From 5e9fc0024228992f9f434c503ef14f8ad89c84ee Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Sun, 18 Apr 2021 21:24:53 +0100 Subject: [PATCH] Bug 572944: Set GDB process attributes Change-Id: I98350d5307c23f91207d55372cc85319ebe716c4 --- .../guide/deprecated_API_removals.html | 26 ++++++++ .../.settings/.api_filters | 11 ++++ .../META-INF/MANIFEST.MF | 2 +- .../cdt/dsf/gdb/launching/GdbLaunch.java | 62 +++++++------------ .../cdt/dsf/gdb/service/GDBBackend.java | 17 +++-- .../cdt/dsf/gdb/service/GDBBackend_7_12.java | 5 +- .../cdt/dsf/gdb/service/IGDBBackend.java | 13 +++- 7 files changed, 87 insertions(+), 49 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/.settings/.api_filters diff --git a/doc/org.eclipse.cdt.doc.isv/guide/deprecated_API_removals.html b/doc/org.eclipse.cdt.doc.isv/guide/deprecated_API_removals.html index 25317cb3d35..9f9eddf3944 100644 --- a/doc/org.eclipse.cdt.doc.isv/guide/deprecated_API_removals.html +++ b/doc/org.eclipse.cdt.doc.isv/guide/deprecated_API_removals.html @@ -56,6 +56,12 @@
  • 32-bit Binary parsers with 64-bit replacements
  • BaudRate enum in org.eclipse.cdt.serial
  • +

    + Planned Removals after June 2023 +

    +
      +
    1. Rework of API to determine GDB command line in org.eclipse.cdt.dsf.gdb
    2. +

    @@ -394,6 +400,26 @@

    See Bug 563108.

    + +

    API Removals after June 2023

    + +

    1. Rework of API to determine GDB command line in org.eclipse.cdt.dsf.gdb

    +

    + To support presentation of the GDB command line within the process property page, a public method + getDebuggerCommandLineArray() has been added to the org.eclipse.cdt.dsf.gdb.service.IGDBBackend interface + and the following redundant protected methods will be removed: +

    + +

    + Extenders that override the above protected methods should override + org.eclipse.cdt.dsf.gdb.service.IGDBBackend.getDebuggerCommandLineArray() instead. +

    +

    + See Bug 572944. +

    diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/.settings/.api_filters b/dsf-gdb/org.eclipse.cdt.dsf.gdb/.settings/.api_filters new file mode 100644 index 00000000000..678c0084daa --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/.settings/.api_filters @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF index 4e421bc64c9..4b353fc32b7 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb;singleton:=true -Bundle-Version: 6.3.0.qualifier +Bundle-Version: 6.4.0.qualifier Bundle-Activator: org.eclipse.cdt.dsf.gdb.internal.GdbPlugin Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime, 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 2d07991d859..2ff36fd4ee6 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2018 Wind River Systems and others. + * Copyright (c) 2006, 2021 Wind River Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,20 +14,17 @@ * Marc Khouzam (Ericsson) - Create the gdb process through the process factory (Bug 210366) * Alvaro Sanchez-Leon (Ericsson AB) - Each memory context needs a different MemoryRetrieval (Bug 250323) * John Dallaway - Resolve variables using launch context (Bug 399460) + * John Dallaway - Set GDB process attributes (Bug 572944) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.launching; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -40,6 +37,7 @@ import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.parser.util.StringUtil; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; @@ -66,6 +64,7 @@ import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants; import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.internal.memory.GdbMemoryBlockRetrievalManager; +import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfServicesTracker; @@ -92,6 +91,7 @@ import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.commands.IDebugCommandRequest; import org.eclipse.debug.core.commands.IDisconnectHandler; import org.eclipse.debug.core.commands.ITerminateHandler; +import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.ISourceLocator; import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.launch.ITargetedLaunch; @@ -210,11 +210,25 @@ public class GdbLaunch extends DsfLaunch implements ITracedLaunch, ITargetedLaun } }).get(); + IGDBBackend gdbBackend = getDsfExecutor().submit(new Callable() { + @Override + public IGDBBackend call() throws CoreException { + return fTracker.getService(IGDBBackend.class); + } + }).get(); + + // Set process attributes for presentation in process properties page + Map attributes = new HashMap<>(); + attributes.put(IProcess.ATTR_CMDLINE, StringUtil.join(gdbBackend.getDebuggerCommandLineArray(), "\n")); //$NON-NLS-1$ + attributes.put(DebugPlugin.ATTR_ENVIRONMENT, StringUtil.join(getLaunchEnvironment(), "\n")); //$NON-NLS-1$ + attributes.put(DebugPlugin.ATTR_LAUNCH_TIMESTAMP, Long.toString(System.currentTimeMillis())); + Optional.ofNullable(gdbBackend.getGDBWorkingDirectory()).map(IPath::toOSString) + .ifPresent(dir -> attributes.put(DebugPlugin.ATTR_WORKING_DIRECTORY, dir)); + // Need to go through DebugPlugin.newProcess so that we can use // the overrideable process factory to allow others to override. // First set attribute to specify we want to create the gdb process. // Bug 210366 - Map attributes = new HashMap<>(); attributes.put(IGdbDebugConstants.PROCESS_TYPE_CREATION_ATTR, IGdbDebugConstants.GDB_PROCESS_CREATION_VALUE); DebugPlugin.newProcess(this, gdbProc, label, attributes); @@ -514,40 +528,6 @@ public class GdbLaunch extends DsfLaunch implements ITracedLaunch, ITargetedLaun } - /** - * Read from the specified stream and return what was read. - * - * @param stream - * The input stream to be used to read the data. This method will - * close the stream. - * @return The data read from the stream - * @throws IOException - * If an IOException happens when reading the stream - */ - private static String readStream(InputStream stream) throws IOException { - StringBuilder cmdOutput = new StringBuilder(200); - try { - Reader r = new InputStreamReader(stream); - BufferedReader reader = new BufferedReader(r); - - String line; - while ((line = reader.readLine()) != null) { - cmdOutput.append(line); - cmdOutput.append('\n'); - } - return cmdOutput.toString(); - } finally { - // Cleanup to avoid leaking pipes - // Bug 345164 - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - } - } - } - } - /** * Gets the CDT environment from the CDT project's configuration referenced * by the launch. This environment is used as the environment to run GDB in diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java index ad8b76ce30a..2cbd4b38842 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 Wind River Systems, Nokia and others. + * Copyright (c) 2006, 2021 Wind River Systems, Nokia and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ * Marc Khouzam (Ericsson) - Use the new IMIBackend2 interface (Bug 350837) * Mark Bozeman (Mentor Graphics) - Report GDB start failures (Bug 376203) * Iulia Vasii (Freescale Semiconductor) - Separate GDB command from its arguments (Bug 445360) + * John Dallaway - Implement getDebuggerCommandLineArray() method (Bug 572944) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -176,9 +177,9 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa * array. Allow subclass to override. * * @since 4.6 - * @deprecated Replaced by getDebuggerCommandLine() + * @deprecated Override {@link #getDebuggerCommandLineArray()} instead */ - @Deprecated + @Deprecated(since = "5.2", forRemoval = true) protected String[] getGDBCommandLineArray() { // The goal here is to keep options to an absolute minimum. // All configuration should be done in the final launch sequence @@ -196,10 +197,17 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa return CommandLineUtil.argumentsToArray(cmd); } + @Override + public String[] getDebuggerCommandLineArray() { + // Call the deprecated method which might be overridden + return getDebuggerCommandLine(); + } + /** * Returns the GDB command and its arguments as an array. * Allow subclass to override. * @since 5.2 + * @deprecated Override {@link #getDebuggerCommandLineArray()} instead */ // This method replaces getGDBCommandLineArray() because we need // to override it for GDB 7.12 even if an extender has overridden @@ -224,6 +232,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa // Note that we didn't name this method getGDBCommandLine() because // this name had been used in CDT 8.8 and could still be part of // extenders' code. + @Deprecated(since = "6.4", forRemoval = true) protected String[] getDebuggerCommandLine() { // Call the old method in case it was overridden return getGDBCommandLineArray(); @@ -294,7 +303,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa // not starting the full GDB console properly. protected Process launchGDBProcess() throws CoreException { // Call the old method in case it was overridden - return launchGDBProcess(getDebuggerCommandLine()); + return launchGDBProcess(getDebuggerCommandLineArray()); } /** diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java index 5c2b57162c5..2c2b1286009 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java @@ -123,13 +123,14 @@ public class GDBBackend_7_12 extends GDBBackend { return fDummyErrorStream; } + /** @deprecated Override {@link #getDebuggerCommandLineArray()} instead */ @Override + @Deprecated(since = "6.4", forRemoval = true) protected String[] getDebuggerCommandLine() { // Start from the original command line method which // could have been overridden by extenders, and add what we need // to convert it to a command that will launch in CLI mode. // Then trigger the MI console - @SuppressWarnings("deprecation") String[] originalCommandLine = getGDBCommandLineArray(); if (!isFullGdbConsoleSupported()) { @@ -195,7 +196,7 @@ public class GDBBackend_7_12 extends GDBBackend { // If we are launching the full console, we need to use a PTY in TERMINAL mode // for the GDB CLI to properly display in its view Process proc = null; - String[] commandLine = getDebuggerCommandLine(); + String[] commandLine = getDebuggerCommandLineArray(); try { fCLIPty = new PTY(Mode.TERMINAL); IPath path = getGDBWorkingDirectory(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java index 96d39dfd0d9..f58b992c791 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Nokia Corporation. + * Copyright (c) 2008, 2021 Nokia Corporation. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * Nokia - initial version * Ericsson - Minor cleanup + * John Dallaway - Add getDebuggerCommandLineArray() method (Bug 572944) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -85,6 +86,16 @@ public interface IGDBBackend extends IMIBackend { */ public IPath getGDBWorkingDirectory() throws CoreException; + /** + * Get the command line used to invoke GDB. + * + * @return String[] - the GDB command and its arguments as an array + * @since 6.4 + */ + default String[] getDebuggerCommandLineArray() { + return new String[0]; + } + /** * @throws CoreException * - error in getting the option.