1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Bug 421541 - Support all languages for memory context's address size

add MIGDBShow MIGDBShowLanguage MIGDBSetLanguage
When retrieving memory context's address size do
Store initial language
Set language to c
Read address size
Restore initial language

Change-Id: I6b504526a1cde8d509299d57cf3e1d70d73c4f5b
Signed-off-by: Philippe Gil <gil@adacore.com>
Reviewed-on: https://git.eclipse.org/r/18371
IP-Clean: Mikhail Khodjaiants <mikhailkhod@googlemail.com>
Tested-by: Mikhail Khodjaiants <mikhailkhod@googlemail.com>
Tested-by: Hudson CI
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
Reviewed-by: Mikhail Khodjaiants <mikhailkhod@googlemail.com>
This commit is contained in:
Philippe Gil 2013-11-14 11:11:52 +01:00 committed by Mikhail Khodjaiants
parent 4f485bfd58
commit 1ba8833d49
6 changed files with 294 additions and 40 deletions

View file

@ -8,9 +8,11 @@
* Contributors:
* Mentor Graphics - Initial API and implementation
* John Dallaway - Add methods to get the endianness and address size (Bug 225609)
* Philippe Gil (AdaCore) - Switch to c language when getting sizeof(void *) when required (Bug 421541)
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@ -18,6 +20,7 @@ import java.util.Map;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
@ -35,6 +38,8 @@ import org.eclipse.cdt.dsf.mi.service.MIMemory;
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
import org.eclipse.cdt.dsf.mi.service.command.output.CLIShowEndianInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIDataEvaluateExpressionInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowLanguageInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.core.runtime.IStatus;
@ -123,55 +128,108 @@ public class GDBMemory extends MIMemory implements IGDBMemory {
@Override
public void initializeMemoryData(final IMemoryDMContext memContext, RequestMonitor rm) {
ImmediateExecutor.getInstance().execute(new Sequence(getExecutor(), rm) {
private Step[] fSteps = new Step[] {
new Step() {
@Override
public void execute(final RequestMonitor requestMonitor) {
Integer addrSize = fAddressSizes.get(memContext);
if (addrSize != null) {
requestMonitor.done();
return;
}
readAddressSize(
memContext,
new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), requestMonitor) {
private String originalLanguage = MIGDBShowLanguageInfo.AUTO;
// Need a global here as getSteps() can be called more than once.
private Step[] steps = null;
private void determineSteps()
{
ArrayList<Step> stepsList = new ArrayList<Step>();
if (fAddressSizes.get(memContext) == null) {
stepsList.add(
new Step() {
// store original language
@Override
public void execute(final RequestMonitor requestMonitor) {
fCommandControl.queueCommand(
fCommandControl.getCommandFactory().createMIGDBShowLanguage(memContext),
new ImmediateDataRequestMonitor<MIGDBShowLanguageInfo>(requestMonitor) {
@Override
@ConfinedToDsfExecutor("fExecutor")
protected void handleSuccess() {
originalLanguage = getData().getLanguage();
requestMonitor.done();
}
});
}
});
stepsList.add(
new Step() {
// switch to c language
@Override
public void execute(final RequestMonitor requestMonitor) {
fCommandControl.queueCommand(
fCommandControl.getCommandFactory().createMIGDBSetLanguage(memContext, MIGDBShowLanguageInfo.C),
new ImmediateDataRequestMonitor<MIInfo>(requestMonitor));
}
});
stepsList.add(
new Step() {
// read address size
@Override
public void execute(final RequestMonitor requestMonitor) {
readAddressSize(
memContext,
new ImmediateDataRequestMonitor<Integer>(requestMonitor) {
@Override
@ConfinedToDsfExecutor("fExecutor")
protected void handleSuccess() {
fAddressSizes.put(memContext, getData());
requestMonitor.done();
}
});
}
});
stepsList.add(
new Step() {
// restore original language
@Override
@ConfinedToDsfExecutor("fExecutor")
protected void handleSuccess() {
fAddressSizes.put(memContext, getData());
requestMonitor.done();
public void execute(final RequestMonitor requestMonitor) {
fCommandControl.queueCommand(
fCommandControl.getCommandFactory().createMIGDBSetLanguage(memContext, originalLanguage),
new ImmediateDataRequestMonitor<MIInfo>(requestMonitor));
}
});
}
},
new Step() {
@Override
public void execute(final RequestMonitor requestMonitor) {
if ( fIsBigEndian != null) {
requestMonitor.done();
return;
}
readEndianness(
memContext,
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), requestMonitor) {
@Override
@ConfinedToDsfExecutor("fExecutor")
protected void handleSuccess() {
fIsBigEndian = getData();
requestMonitor.done();
}
});
}
},
};
if (fIsBigEndian == null) {
stepsList.add(
new Step() {
// read endianness
@Override
public void execute(final RequestMonitor requestMonitor) {
readEndianness(
memContext,
new ImmediateDataRequestMonitor<Boolean>(requestMonitor) {
@Override
@ConfinedToDsfExecutor("fExecutor")
protected void handleSuccess() {
fIsBigEndian = getData();
requestMonitor.done();
}
});
}
});
}
steps = stepsList.toArray(new Step[stepsList.size()]);
}
@Override
public Step[] getSteps() {
return fSteps;
if (steps == null) {
determineSteps();
}
return steps;
}
});
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2012 QNX Software Systems and others.
* Copyright (c) 2000, 2013 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,6 +21,7 @@
* Vladimir Prus (Mentor Graphics) - Support for -info-os (Bug 360314)
* John Dallaway - Support for -data-write-memory-bytes (Bug 387793)
* Alvaro Sanchez-Leon (Ericsson) - Make Registers View specific to a frame (Bug (323552)
* Philippe Gil (AdaCore) - Add show/set language CLI commands (Bug 421541)
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command;
@ -112,6 +113,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetCharset;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetDetachOnFork;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetEnv;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetHostCharset;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetLanguage;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetNonStop;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPagination;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPrintObject;
@ -124,6 +126,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetAsync;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetCharset;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetWideCharset;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowExitCode;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowLanguage;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIInferiorTTYSet;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIInfoOs;
import org.eclipse.cdt.dsf.mi.service.command.commands.MIInterpreterExec;
@ -194,6 +197,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfoOsInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIListFeaturesInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIListThreadGroupsInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowLanguageInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIStackInfoDepthInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIStackListArgumentsInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIStackListFramesInfo;
@ -698,6 +702,11 @@ public class CommandFactory {
return new MIGDBSetHostCharset(ctx, hostCharset);
}
/** @since 4.3 */
public ICommand<MIInfo> createMIGDBSetLanguage(IDMContext ctx, String language) {
return new MIGDBSetLanguage(ctx, language);
}
public ICommand<MIInfo> createMIGDBSetNonStop(ICommandControlDMContext ctx, boolean isSet) {
return new MIGDBSetNonStop(ctx, isSet);
}
@ -752,6 +761,11 @@ public class CommandFactory {
return new MIGDBShowExitCode(ctx);
}
/** @since 4.3 */
public ICommand<MIGDBShowLanguageInfo> createMIGDBShowLanguage(IDMContext ctx) {
return new MIGDBShowLanguage(ctx);
}
/** @since 4.0 */
public ICommand<MIInfo> createMIInferiorTTYSet(IMIContainerDMContext dmc, String tty) {
return new MIInferiorTTYSet(dmc, tty);

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2013 AdaCore and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philippe Gil (AdaCore) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.commands;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
/**
*
* -gdb-set language
*
* @since 4.3
*/
public class MIGDBSetLanguage extends MIGDBSet {
public MIGDBSetLanguage(IDMContext ctx, String language) {
super(ctx, new String[] {"language", language}); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2013 AdaCore and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philippe Gil (AdaCore) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.commands;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
/**
*
* -gdb-show
*
* @since 4.3
*
*/
public class MIGDBShow<V extends MIInfo> extends MICommand<V>
{
public MIGDBShow(IDMContext ctx, String[] params) {
super(ctx, "-gdb-show", null, params); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2013 AdaCore and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philippe Gil (AdaCore) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.commands;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowLanguageInfo;
/**
*
* -gdb-show language
*
* @since 4.3
*
*/
public class MIGDBShowLanguage extends MIGDBShow<MIGDBShowLanguageInfo>
{
public MIGDBShowLanguage(IDMContext ctx) {
super(ctx, new String[] {"language"}); //$NON-NLS-1$
}
@Override
public MIGDBShowLanguageInfo getResult(MIOutput miResult) {
return new MIGDBShowLanguageInfo(miResult);
}
}

View file

@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2013 AdaCore and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philippe Gil (AdaCore) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
/**
* '-gdb-show language' returns the current source language.
*
* sample output:
*
* -gdb-show language
* ^done,value="auto"
*
* the different returned values are:
*
* (gdb) help set language
* Set the current source language.
* The currently understood settings are:
*
* local or auto Automatic setting based on source file
* ada Use the Ada language
* c Use the C language
* c++ Use the C++ language
* asm Use the Asm language
* minimal Use the Minimal language
* d Use the D language
* fortran Use the Fortran language
* objective-c Use the Objective-c language
* go Use the Go language
* java Use the Java language
* modula-2 Use the Modula-2 language
* opencl Use the Opencl language
* pascal Use the Pascal language
*
* @since 4.3
*/
public class MIGDBShowLanguageInfo extends MIInfo {
public static final String LOCAL = "local"; //$NON-NLS-1$
public static final String AUTO = "auto"; //$NON-NLS-1$
public static final String ADA = "ada"; //$NON-NLS-1$
public static final String C = "c"; //$NON-NLS-1$
public static final String C_PLUS_PLUS = "c++"; //$NON-NLS-1$
public static final String ASM = "asm"; //$NON-NLS-1$
public static final String MINIMAL = "minimal"; //$NON-NLS-1$
public static final String D = "d"; //$NON-NLS-1$
public static final String FORTRAN = "fortran"; //$NON-NLS-1$
public static final String OBJECTIVE_C = "objective-c"; //$NON-NLS-1$
public static final String GO = "go"; //$NON-NLS-1$
public static final String JAVA = "java"; //$NON-NLS-1$
public static final String MODULA_2 = "modula-2"; //$NON-NLS-1$
public static final String OPENCL = "opencl"; //$NON-NLS-1$
public static final String PASCAL = "pascal"; //$NON-NLS-1$
private String fLanguage = AUTO;
public MIGDBShowLanguageInfo(MIOutput record) {
super(record);
parse();
}
protected void parse() {
if (isDone()) {
MIOutput out = getMIOutput();
MIResultRecord outr = out.getMIResultRecord();
if (outr != null) {
MIResult[] results = outr.getMIResults();
for (int i = 0; i < results.length; i++) {
String var = results[i].getVariable();
if (var.equals("value")) { //$NON-NLS-1$
MIValue value = results[i].getMIValue();
if (value instanceof MIConst) {
fLanguage = ((MIConst)value).getString();
}
}
}
}
}
}
public String getLanguage() {
return fLanguage;
}
}