From c631da77c65e22007d5c3228e8c6c3da58d4a3f9 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 16 Dec 2014 16:56:14 -0500 Subject: [PATCH] Bug 455408 - Show GDB version at startup Change-Id: Ib22d98d31ed2c03c3ef3a0b5a22f8a22c6ee3e50 Signed-off-by: Marc Khouzam Reviewed-on: https://git.eclipse.org/r/38387 Reviewed-by: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants --- .../gdb/launching/FinalLaunchSequence.java | 22 +++++- .../mi/service/command/CommandFactory.java | 8 ++ .../command/commands/MIGDBVersion.java | 36 +++++++++ .../command/output/MIGDBVersionInfo.java | 77 +++++++++++++++++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBVersion.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBVersionInfo.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java index 774aced0098..eefbc6f7dd9 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Ericsson and others. + * Copyright (c) 2008, 2014 Ericsson 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 @@ -15,6 +15,7 @@ * Mathias Kunter - Support for different charsets (bug 370462) * Anton Gorenkov - A preference to use RTTI for variable types determination (Bug 377536) * Xavier Raynaud (Kalray) - Avoid duplicating fields in sub-classes (add protected accessors) + * Marc Khouzam (Ericsson) - Output the version of GDB at startup (Bug 455408) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.launching; @@ -45,6 +46,7 @@ import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; import org.eclipse.cdt.dsf.mi.service.CSourceLookup; import org.eclipse.cdt.dsf.mi.service.IMIProcesses; import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; @@ -100,6 +102,7 @@ public class FinalLaunchSequence extends ReflectionSequence { return new String[] { "stepInitializeFinalLaunchSequence", //$NON-NLS-1$ // Global GDB settings + "stepGDBVersion", //$NON-NLS-1$ "stepSetEnvironmentDirectory", //$NON-NLS-1$ "stepSetBreakpointPending", //$NON-NLS-1$ "stepEnablePrettyPrinting", //$NON-NLS-1$ @@ -176,6 +179,23 @@ public class FinalLaunchSequence extends ReflectionSequence { requestMonitor.done(); } + /** + * Print the version of GDB. + * @since 4.6 + */ + @Execute + public void stepGDBVersion(final RequestMonitor requestMonitor) { + fCommandControl.queueCommand( + fCommandFactory.createMIGDBVersion(fCommandControl.getContext()), + new DataRequestMonitor(getExecutor(), requestMonitor) { + @Override + protected void handleCompleted() { + // Accept failures + requestMonitor.done(); + } + }); + } + /** * Specify GDB's working directory. * @since 4.0 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 8aa9548116f..474b2c92fc4 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 @@ -25,6 +25,7 @@ * Dmitry Kozlov (Mentor Graphics) - New trace-related methods (Bug 390827) * Alvaro Sanchez-Leon (Ericsson AB) - [Memory] Support 16 bit addressable size (Bug 426730) * Marc Khouzam (Ericsson) - Support for dynamic printf (Bug 400638) + * Marc Khouzam (Ericsson) - Support for -gdb-version (Bug 455408) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -137,6 +138,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTraceNotes; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTraceUser; 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.MIGDBVersion; 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; @@ -205,6 +207,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIDataWriteMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowExitCodeInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowLanguageInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo; 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; @@ -823,6 +826,11 @@ public class CommandFactory { return new MIGDBShowLanguage(ctx); } + /** @since 4.6 */ + public ICommand createMIGDBVersion(ICommandControlDMContext ctx) { + return new MIGDBVersion(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/MIGDBVersion.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBVersion.java new file mode 100644 index 00000000000..757f6fa5c99 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBVersion.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; + +/** + * + * -gdb-version + * + * @since 4.6 + * + */ +public class MIGDBVersion extends MICommand { + private static final String COMMAND = "-gdb-version"; //$NON-NLS-1$ + + public MIGDBVersion(ICommandControlDMContext ctx) { + super(ctx, COMMAND); + } + + @Override + public MIInfo getResult(MIOutput out) { + return new MIGDBVersionInfo(out); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBVersionInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBVersionInfo.java new file mode 100644 index 00000000000..e856e08a79c --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBVersionInfo.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.mi.service.command.output; + +import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils; +import org.eclipse.cdt.dsf.mi.service.command.output.MIConsoleStreamOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIStreamRecord; + +/** + * '-gdb-version' Show version information for gdb. + * + * sample output: + * + * -gdb-version + * ~"GNU gdb (Ubuntu 7.7-0ubuntu3.1) 7.7\n" + * ~"Copyright (C) 2014 Free Software Foundation, Inc.\n" + * ~"License GPLv3+: GNU GPL version 3 or later \nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type \"show copying\"\nand \"show warranty\" for details.\n" + * ~"This GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details." + * ~"\nFor bug reporting instructions, please see:\n" + * ~".\n" + * ~"Find the GDB manual and other documentation resources online at:\n.\n" + * ~"For help, type \"help\".\n" + * ~"Type \"apropos word\" to search for commands related to \"word\".\n" + * ^done + * + * @since 4.6 + */ +public class MIGDBVersionInfo extends MIInfo { + + private String fVersion; + private String fFullOutput; + + public MIGDBVersionInfo(MIOutput record) { + super(record); + parse(); + } + + protected void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIOOBRecord[] records = out.getMIOOBRecords(); + StringBuilder builder = new StringBuilder(); + for(MIOOBRecord rec : records) { + if (rec instanceof MIConsoleStreamOutput) { + MIStreamRecord o = (MIStreamRecord)rec; + builder.append(o.getString()); + } + } + fFullOutput = builder.toString(); + fVersion = parseVersion(fFullOutput); + } + } + + protected String parseVersion(String output) { + return LaunchUtils.getGDBVersionFromText(output); + } + + public String getFullOutput() { + return fFullOutput; + } + + public String getVersion() { + return fVersion; + } +}