From fbe98078775898ecae0e1d74b3549384fa833dbb Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 1 Aug 2016 14:07:27 -0400 Subject: [PATCH] Allow GdbLaunch#getGDBVersion() to be called more than once. Originally, we used LaunchUtils.getGDBVersion() to fetch the GDB version. Because that method was used for any debug session, we didn't cache the result of it. Now that we moved the version handling to the GdbLaunch class, and that this class is unique per session, we can cache the result of the getGDBVersion(), allowing it to be called more than once. Change-Id: I1a396134ca5c609224f8abb7b70d1e0866810497 --- .../org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java index 113ce91ee30..6abe37d0eef 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java @@ -114,6 +114,8 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr private IMemoryBlockRetrievalManager fMemRetrievalManager; private IDsfDebugServicesFactory fServiceFactory; private ILaunchTarget fLaunchTarget; + + private String fGdbVersion; public GdbLaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator) { super(launchConfiguration, mode, locator); @@ -500,14 +502,17 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr /** * This method actually launches 'gdb --version' to determine the version of - * the GDB that is being used. This method should ideally be called only - * once per session and the resulting version string stored for future uses. + * the GDB that is being used. The result is then cached for any future requests. * * A timeout is scheduled which will kill the process if it takes too long. * * @since 5.0 */ public String getGDBVersion() throws CoreException { + if (fGdbVersion != null) { + return fGdbVersion; + } + String cmd = getGDBPath().toOSString() + " --version"; //$NON-NLS-1$ // Parse cmd to properly handle spaces and such things (bug 458499) @@ -559,7 +564,8 @@ public class GdbLaunch extends DsfLaunch implements ITerminate, IDisconnect, ITr "Could not determine GDB version using command: " + StringUtil.join(args, " "), //$NON-NLS-1$ //$NON-NLS-2$ detailedException)); } - return gdbVersion; + fGdbVersion = gdbVersion; + return fGdbVersion; } catch (IOException e) { throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Error with command: " + StringUtil.join(args, " "), e));//$NON-NLS-1$ //$NON-NLS-2$