1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 572944: Set GDB process attributes

Change-Id: I98350d5307c23f91207d55372cc85319ebe716c4
This commit is contained in:
John Dallaway 2021-04-18 21:24:53 +01:00
parent 3c58527d53
commit 5e9fc00242
7 changed files with 87 additions and 49 deletions

View file

@ -56,6 +56,12 @@
<li><a href="#binaryparsers">32-bit Binary parsers with 64-bit replacements</a></li>
<li><a href="#baudrate">BaudRate enum in org.eclipse.cdt.serial</a></li>
</ol>
<p>
Planned Removals after June 2023
</p>
<ol>
<li><a href="#gdbBackendDebuggerCommandLine">Rework of API to determine GDB command line in org.eclipse.cdt.dsf.gdb</a></li>
</ol>
<hr>
@ -394,6 +400,26 @@
<p>
See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=563108" target="_blank">Bug 563108</a>.
</p>
<h3>API Removals after June 2023</h3>
<h3>1. <a name="gdbBackendDebuggerCommandLine">Rework of API to determine GDB command line in org.eclipse.cdt.dsf.gdb</a></h3>
<p>
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:
</p>
<ul>
<li>org.eclipse.cdt.dsf.gdb.service.GDBBackend.getDebuggerCommandLine()</li>
<li>org.eclipse.cdt.dsf.gdb.service.GDBBackend.getGDBCommandLineArray()</li>
</ul>
<p>
Extenders that override the above protected methods should override
org.eclipse.cdt.dsf.gdb.service.IGDBBackend.getDebuggerCommandLineArray() instead.
</p>
<p>
See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=572944" target="_blank">Bug 572944</a>.
</p>
</body>
</html>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.dsf.gdb" version="2">
<resource path="src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java" type="org.eclipse.cdt.dsf.gdb.service.IGDBBackend">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.dsf.gdb.service.IGDBBackend"/>
<message_argument value="getDebuggerCommandLineArray()"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -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,

View file

@ -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<IGDBBackend>() {
@Override
public IGDBBackend call() throws CoreException {
return fTracker.getService(IGDBBackend.class);
}
}).get();
// Set process attributes for presentation in process properties page
Map<String, String> 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<String, String> 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

View file

@ -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());
}
/**

View file

@ -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();

View file

@ -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.