From 1ba8833d4965be1d8fcdd0360a2777566beaa37e Mon Sep 17 00:00:00 2001 From: Philippe Gil Date: Thu, 14 Nov 2013 11:11:52 +0100 Subject: [PATCH] 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 Reviewed-on: https://git.eclipse.org/r/18371 IP-Clean: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants Tested-by: Hudson CI Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam Reviewed-by: Mikhail Khodjaiants --- .../cdt/dsf/gdb/service/GDBMemory.java | 136 +++++++++++++----- .../mi/service/command/CommandFactory.java | 16 ++- .../command/commands/MIGDBSetLanguage.java | 27 ++++ .../service/command/commands/MIGDBShow.java | 28 ++++ .../command/commands/MIGDBShowLanguage.java | 34 +++++ .../command/output/MIGDBShowLanguageInfo.java | 93 ++++++++++++ 6 files changed, 294 insertions(+), 40 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetLanguage.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShow.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowLanguage.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowLanguageInfo.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java index 9795f8553d7..f459c756af4 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java @@ -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 String originalLanguage = MIGDBShowLanguageInfo.AUTO; + + // Need a global here as getSteps() can be called more than once. + private Step[] steps = null; - 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(ImmediateExecutor.getInstance(), requestMonitor) { + private void determineSteps() + { + ArrayList stepsList = new ArrayList(); + + 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(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(requestMonitor)); + } + }); + + stepsList.add( + new Step() { + // read address size + @Override + public void execute(final RequestMonitor requestMonitor) { + readAddressSize( + memContext, + new ImmediateDataRequestMonitor(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(requestMonitor)); } }); + } - }, + + if (fIsBigEndian == null) { + stepsList.add( + new Step() { + // read endianness + @Override + public void execute(final RequestMonitor requestMonitor) { + readEndianness( + memContext, + new ImmediateDataRequestMonitor(requestMonitor) { + @Override + @ConfinedToDsfExecutor("fExecutor") + protected void handleSuccess() { + fIsBigEndian = getData(); + requestMonitor.done(); + } + }); + } + }); + } - new Step() { - @Override - public void execute(final RequestMonitor requestMonitor) { - if ( fIsBigEndian != null) { - requestMonitor.done(); - return; - } - readEndianness( - memContext, - new DataRequestMonitor(ImmediateExecutor.getInstance(), 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; } }); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java index c58ef521201..b5852cea9dc 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java @@ -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 createMIGDBSetLanguage(IDMContext ctx, String language) { + return new MIGDBSetLanguage(ctx, language); + } + public ICommand 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 createMIGDBShowLanguage(IDMContext ctx) { + return new MIGDBShowLanguage(ctx); + } + /** @since 4.0 */ public ICommand createMIInferiorTTYSet(IMIContainerDMContext dmc, String tty) { return new MIInferiorTTYSet(dmc, tty); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetLanguage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetLanguage.java new file mode 100644 index 00000000000..e39e4bbf816 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetLanguage.java @@ -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$ + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShow.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShow.java new file mode 100644 index 00000000000..06bba0b795b --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShow.java @@ -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 extends MICommand +{ + public MIGDBShow(IDMContext ctx, String[] params) { + super(ctx, "-gdb-show", null, params); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowLanguage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowLanguage.java new file mode 100644 index 00000000000..6ead09c13ff --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowLanguage.java @@ -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 +{ + public MIGDBShowLanguage(IDMContext ctx) { + super(ctx, new String[] {"language"}); //$NON-NLS-1$ + } + + @Override + public MIGDBShowLanguageInfo getResult(MIOutput miResult) { + return new MIGDBShowLanguageInfo(miResult); + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowLanguageInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowLanguageInfo.java new file mode 100644 index 00000000000..beb2762200f --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowLanguageInfo.java @@ -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; + } +}