mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[240092] some cleanup to GDB parts, of which the most important ones are to fix the JUnit tests and remove get getGDBCommandLine() from IGDBBackend, which was not needed.
This commit is contained in:
parent
8b64c7e941
commit
3fd4ddeddc
4 changed files with 68 additions and 91 deletions
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Ling Wang (Nokia) - initial version. Sep 28, 2008
|
* Nokia - initial version. Sep 28, 2008
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.dd.examples.pda.service;
|
package org.eclipse.dd.examples.pda.service;
|
||||||
|
|
|
@ -81,9 +81,20 @@ public class FinalLaunchSequence extends Sequence {
|
||||||
new Step() { @Override
|
new Step() { @Override
|
||||||
public void execute(RequestMonitor requestMonitor) {
|
public void execute(RequestMonitor requestMonitor) {
|
||||||
fCommandControl = fTracker.getService(IGDBControl.class);
|
fCommandControl = fTracker.getService(IGDBControl.class);
|
||||||
|
if (fCommandControl == null) {
|
||||||
|
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot obtain control service", null)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
requestMonitor.done();
|
||||||
|
}},
|
||||||
|
/*
|
||||||
|
* Fetch the process service for later use
|
||||||
|
*/
|
||||||
|
new Step() { @Override
|
||||||
|
public void execute(RequestMonitor requestMonitor) {
|
||||||
fProcService = fTracker.getService(IMIProcesses.class);
|
fProcService = fTracker.getService(IMIProcesses.class);
|
||||||
if (fCommandControl == null || fProcService == null) {
|
if (fProcService == null) {
|
||||||
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot obtain service", null)); //$NON-NLS-1$
|
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot obtain process service", null)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
requestMonitor.done();
|
requestMonitor.done();
|
||||||
|
@ -168,23 +179,17 @@ public class FinalLaunchSequence extends Sequence {
|
||||||
/*
|
/*
|
||||||
* Specify GDB's working directory
|
* Specify GDB's working directory
|
||||||
*/
|
*/
|
||||||
new Step() {
|
new Step() { @Override
|
||||||
|
|
||||||
private IPath getWorkingDirectory(RequestMonitor requestMonitor) {
|
|
||||||
IPath path = null;
|
|
||||||
try {
|
|
||||||
path = fGDBBackend.getGDBWorkingDirectory();
|
|
||||||
} catch (CoreException e) {
|
|
||||||
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get working directory", e)); //$NON-NLS-1$
|
|
||||||
requestMonitor.done();
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final RequestMonitor requestMonitor) {
|
public void execute(final RequestMonitor requestMonitor) {
|
||||||
IPath dir = getWorkingDirectory(requestMonitor);
|
IPath dir = null;
|
||||||
|
try {
|
||||||
|
dir = fGDBBackend.getGDBWorkingDirectory();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get working directory", e)); //$NON-NLS-1$
|
||||||
|
requestMonitor.done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
fCommandControl.queueCommand(
|
fCommandControl.queueCommand(
|
||||||
new MIEnvironmentCD(fCommandControl.getContext(), dir.toPortableString()),
|
new MIEnvironmentCD(fCommandControl.getContext(), dir.toPortableString()),
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Ling Wang (Nokia) - initial API and implementation with some code moved from GDBControl.
|
* Nokia - initial API and implementation with some code moved from GDBControl.
|
||||||
* Wind River System
|
* Wind River System
|
||||||
* Ericsson
|
* Ericsson
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -68,11 +68,6 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
|
|
||||||
private ILaunchConfiguration fLaunchConfiguration;
|
private ILaunchConfiguration fLaunchConfiguration;
|
||||||
|
|
||||||
/**
|
|
||||||
* Command line to start GDB.
|
|
||||||
*/
|
|
||||||
private List<String> fGDBCommandLine;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parameters for launching GDB.
|
* Parameters for launching GDB.
|
||||||
*/
|
*/
|
||||||
|
@ -102,7 +97,8 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
fLaunchConfiguration = lc;
|
fLaunchConfiguration = lc;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ICProject cproject = LaunchUtils.verifyCProject(lc);
|
// Don't call verifyCProject, because the JUnit tests are not setting a project
|
||||||
|
ICProject cproject = LaunchUtils.getCProject(lc);
|
||||||
fProgramPath = LaunchUtils.verifyProgramPath(lc, cproject);
|
fProgramPath = LaunchUtils.verifyProgramPath(lc, cproject);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fProgramPath = new Path(""); //$NON-NLS-1$
|
fProgramPath = new Path(""); //$NON-NLS-1$
|
||||||
|
@ -148,37 +144,34 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
|
|
||||||
|
|
||||||
private IPath getGDBPath() {
|
private IPath getGDBPath() {
|
||||||
IPath retVal = new Path(IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT);
|
return LaunchUtils.getGDBPath(fLaunchConfiguration);
|
||||||
try {
|
|
||||||
retVal = new Path(fLaunchConfiguration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUG_NAME,
|
|
||||||
IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT));
|
|
||||||
} catch (CoreException e) {
|
|
||||||
}
|
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getGDBCommandLine() {
|
/*
|
||||||
if (fGDBCommandLine == null)
|
* Options for GDB process.
|
||||||
{
|
* Allow subclass to override.
|
||||||
fGDBCommandLine = new ArrayList<String>();
|
*/
|
||||||
|
protected String getGDBCommandLine() {
|
||||||
|
StringBuffer gdbCommandLine = new StringBuffer(getGDBPath().toOSString());
|
||||||
|
|
||||||
// The goal here is to keep options to an absolute minimum.
|
// The goal here is to keep options to an absolute minimum.
|
||||||
// All configuration should be done in the launch sequence
|
// All configuration should be done in the launch sequence
|
||||||
// to allow for easy overriding.
|
// to allow for more flexibility.
|
||||||
fGDBCommandLine.add(getGDBPath().toOSString());
|
gdbCommandLine.append(" --interpreter"); //$NON-NLS-1$
|
||||||
fGDBCommandLine.add("--interpreter"); //$NON-NLS-1$
|
// We currently work with MI version 2. Don't use just 'mi' because it
|
||||||
fGDBCommandLine.add("mi"); //$NON-NLS-1$
|
// points to the latest MI version, while we want mi2 specifically.
|
||||||
// Don't read the gdbinit file here. It is read explicitly in
|
gdbCommandLine.append(" mi2"); //$NON-NLS-1$
|
||||||
// the LaunchSequence to make it easier to customize.
|
// Don't read the gdbinit file here. It is read explicitly in
|
||||||
fGDBCommandLine.add("--nx"); //$NON-NLS-1$
|
// the LaunchSequence to make it easier to customize.
|
||||||
}
|
gdbCommandLine.append(" --nx"); //$NON-NLS-1$
|
||||||
|
|
||||||
return fGDBCommandLine;
|
return gdbCommandLine.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGDBInitFile() throws CoreException {
|
public String getGDBInitFile() throws CoreException {
|
||||||
if (fGDBInitFile == null) {
|
if (fGDBInitFile == null) {
|
||||||
fGDBInitFile = fLaunchConfiguration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_GDB_INIT, ""); //$NON-NLS-1$
|
fGDBInitFile = fLaunchConfiguration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_GDB_INIT,
|
||||||
|
IGDBLaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fGDBInitFile;
|
return fGDBInitFile;
|
||||||
|
@ -187,7 +180,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
public IPath getGDBWorkingDirectory() throws CoreException {
|
public IPath getGDBWorkingDirectory() throws CoreException {
|
||||||
if (fGDBWorkingDirectory == null) {
|
if (fGDBWorkingDirectory == null) {
|
||||||
|
|
||||||
// First try to use the user-sepcified working directory for the debugged program.
|
// First try to use the user-specified working directory for the debugged program.
|
||||||
// This is fine only with local debug.
|
// This is fine only with local debug.
|
||||||
// For remote debug, the working dir of the debugged program will be on remote device
|
// For remote debug, the working dir of the debugged program will be on remote device
|
||||||
// and hence not applicable. In such case we may just use debugged program path on host
|
// and hence not applicable. In such case we may just use debugged program path on host
|
||||||
|
@ -247,8 +240,9 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
|
ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
|
||||||
(String)null);
|
(String)null);
|
||||||
|
|
||||||
if (fProgramArguments != null)
|
if (fProgramArguments != null) {
|
||||||
fProgramArguments = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fProgramArguments);
|
fProgramArguments = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fProgramArguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fProgramArguments;
|
return fProgramArguments;
|
||||||
|
@ -262,7 +256,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
public List<String> getSharedLibraryPaths() throws CoreException {
|
public List<String> getSharedLibraryPaths() throws CoreException {
|
||||||
if (fSharedLibPaths == null) {
|
if (fSharedLibPaths == null) {
|
||||||
fSharedLibPaths = fLaunchConfiguration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH,
|
fSharedLibPaths = fLaunchConfiguration.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH,
|
||||||
new ArrayList<String>(0));
|
new ArrayList<String>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fSharedLibPaths;
|
return fSharedLibPaths;
|
||||||
|
@ -272,15 +266,12 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
* Launch GDB process.
|
* Launch GDB process.
|
||||||
* Allow subclass to override.
|
* Allow subclass to override.
|
||||||
*/
|
*/
|
||||||
protected Process launchGDBProcess() throws CoreException {
|
protected Process launchGDBProcess(String commandLine) throws CoreException {
|
||||||
List<String> gdbCmdLine = getGDBCommandLine();
|
|
||||||
String[] commandLine = gdbCmdLine.toArray(new String[gdbCmdLine.size()]);
|
|
||||||
|
|
||||||
Process proc = null;
|
Process proc = null;
|
||||||
try {
|
try {
|
||||||
proc = ProcessFactory.getFactory().exec(commandLine);
|
proc = ProcessFactory.getFactory().exec(commandLine);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
String message = "Error while launching command " + gdbCmdLine.toString(); //$NON-NLS-1$
|
String message = "Error while launching command " + commandLine; //$NON-NLS-1$
|
||||||
throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, message, e));
|
throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, message, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,17 +302,10 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
if (getState() != State.STARTED)
|
// destroy() should be supported even if it's not spawner.
|
||||||
return;
|
if (getState() == State.STARTED) {
|
||||||
|
fProcess.destroy();
|
||||||
// destroy() should be supported even if it's not spawner.
|
}
|
||||||
fProcess.destroy();
|
|
||||||
/*
|
|
||||||
if (fProcess instanceof Spawner) {
|
|
||||||
Spawner gdbSpawner = (Spawner) fProcess;
|
|
||||||
gdbSpawner.destroy();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public State getState() {
|
public State getState() {
|
||||||
|
@ -370,25 +354,22 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
final Job startGdbJob = new Job("Start GDB Process Job") { //$NON-NLS-1$
|
final Job startGdbJob = new Job("Start GDB Process Job") { //$NON-NLS-1$
|
||||||
@Override
|
@Override
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
List<String> commandList = getGDBCommandLine();
|
String commandLine = getGDBCommandLine();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fProcess = launchGDBProcess();
|
fProcess = launchGDBProcess(commandLine);
|
||||||
} catch(CoreException e) {
|
} catch(CoreException e) {
|
||||||
String message = "Error while launching command " + commandList.toString(); //$NON-NLS-1$
|
gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, e.getMessage(), e));
|
||||||
gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, message, e));
|
|
||||||
gdbLaunchRequestMonitor.done();
|
gdbLaunchRequestMonitor.done();
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream stream = fProcess.getInputStream();
|
Reader r = new InputStreamReader(getMIInputStream());
|
||||||
Reader r = new InputStreamReader(stream);
|
|
||||||
BufferedReader reader = new BufferedReader(r);
|
BufferedReader reader = new BufferedReader(r);
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
//System.out.println("GDB " + line);
|
|
||||||
if (line.endsWith("(gdb)")) { //$NON-NLS-1$
|
if (line.endsWith("(gdb)")) { //$NON-NLS-1$
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +412,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
while (attempts < 10) {
|
while (attempts < 10) {
|
||||||
try {
|
try {
|
||||||
// Don't know if we really need the exit value... but what the hell.
|
// Don't know if we really need the exit value... but what the heck.
|
||||||
fGDBExitValue = fProcess.exitValue(); // throws exception if process not exited
|
fGDBExitValue = fProcess.exitValue(); // throws exception if process not exited
|
||||||
|
|
||||||
requestMonitor.done();
|
requestMonitor.done();
|
||||||
|
@ -490,7 +471,7 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend {
|
||||||
* This event is not consumed by any one at present, instead it's
|
* This event is not consumed by any one at present, instead it's
|
||||||
* the GDBControlInitializedDMEvent that's used to indicate that GDB
|
* the GDBControlInitializedDMEvent that's used to indicate that GDB
|
||||||
* back end is ready for MI commands. But we still fire the event as
|
* back end is ready for MI commands. But we still fire the event as
|
||||||
* it does no harm and may be needed sometime.... 09/29/08
|
* it does no harm and may be needed sometime.... 09/29/2008
|
||||||
*/
|
*/
|
||||||
getSession().dispatchEvent(
|
getSession().dispatchEvent(
|
||||||
new BackendStateChangedEvent(getSession().getId(), getId(), IMIBackend.State.STARTED),
|
new BackendStateChangedEvent(getSession().getId(), getId(), IMIBackend.State.STARTED),
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Ling Wang (Nokia) - initial version. Sep, 2008
|
* Nokia - initial version
|
||||||
|
* Ericsson - Minor cleanup
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.gdb.internal.provisional.service;
|
package org.eclipse.dd.gdb.internal.provisional.service;
|
||||||
|
|
||||||
|
@ -37,16 +38,6 @@ import org.eclipse.dd.mi.service.IMIBackend;
|
||||||
*/
|
*/
|
||||||
public interface IGDBBackend extends IMIBackend {
|
public interface IGDBBackend extends IMIBackend {
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the command line that is used to launch GDB. <br>
|
|
||||||
* Note it's not needed to put debugged binary in the command, as that will
|
|
||||||
* be set by a MI command.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<String> getGDBCommandLine();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path of the debugged program on host.
|
* Get path of the debugged program on host.
|
||||||
*
|
*
|
||||||
|
@ -57,8 +48,8 @@ public interface IGDBBackend extends IMIBackend {
|
||||||
/**
|
/**
|
||||||
* Get init file for GDB.
|
* Get init file for GDB.
|
||||||
*
|
*
|
||||||
* @return file name, may have relative or absolute path, or empty string
|
* @return file name, may have relative or absolute path, or empty string ("")
|
||||||
* ("") indicating an init file is not specified.
|
* indicating an init file is not specified.
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
* - error in getting the option.
|
* - error in getting the option.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue