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

Bug 202343

Launch for for Attaching to a running
This commit is contained in:
Marc Khouzam 2008-04-15 16:38:17 +00:00
parent 178f065901
commit 2c82390e87
7 changed files with 201 additions and 31 deletions

View file

@ -7,7 +7,7 @@
delegate="org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunchDelegate" delegate="org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunchDelegate"
public="true" public="true"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer" sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"
name="Local C/C++ Application (Experimental - DSF)" name="C/C++ Local Application (Experimental - DSF)"
id="org.eclipse.dd.gdb.launch.localCLaunch" id="org.eclipse.dd.gdb.launch.localCLaunch"
modes="debug"> modes="debug">
</launchConfigurationType> </launchConfigurationType>
@ -15,7 +15,16 @@
delegate="org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunchDelegate" delegate="org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunchDelegate"
id="org.eclipse.dd.gdb.launch.remoteCLaunch" id="org.eclipse.dd.gdb.launch.remoteCLaunch"
modes="debug" modes="debug"
name="Remote C/C++ Application (Experimental - DSF)" name="C/C++ Remote Application (Experimental - DSF)"
public="true"
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
</launchConfigurationType>
<launchConfigurationType
delegate="org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunchDelegate"
id="org.eclipse.dd.gdb.launch.attachCLaunch"
modes="debug"
name="C/C++ Attach to Local Application (Experimental - DSF)"
public="true" public="true"
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator" sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"> sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
@ -33,6 +42,11 @@
id="org.eclipse.dd.gdb.launch.remoteRunLaunchTabGroup" id="org.eclipse.dd.gdb.launch.remoteRunLaunchTabGroup"
type="org.eclipse.dd.gdb.launch.remoteCLaunch"> type="org.eclipse.dd.gdb.launch.remoteCLaunch">
</launchConfigurationTabGroup> </launchConfigurationTabGroup>
<launchConfigurationTabGroup
class="org.eclipse.dd.gdb.internal.ui.launching.GdbAttachLaunchConfigurationTabGroup"
id="org.eclipse.dd.gdb.launch.localAttachLaunchTabGroup"
type="org.eclipse.dd.gdb.launch.attachCLaunch">
</launchConfigurationTabGroup>
</extension> </extension>
<extension <extension
point="org.eclipse.debug.ui.launchConfigurationTypeImages"> point="org.eclipse.debug.ui.launchConfigurationTypeImages">
@ -46,5 +60,10 @@
icon="icons/full/obj16/c_app.gif" icon="icons/full/obj16/c_app.gif"
id="org.eclipse.dd.gdb.launch.remoteRunLaunchImage"> id="org.eclipse.dd.gdb.launch.remoteRunLaunchImage">
</launchConfigurationTypeImage> </launchConfigurationTypeImage>
<launchConfigurationTypeImage
configTypeID="org.eclipse.dd.gdb.launch.attachCLaunch"
icon="icons/full/obj16/c_app.gif"
id="org.eclipse.dd.gdb.launch.attachRunLaunchImage">
</launchConfigurationTypeImage>
</extension> </extension>
</plugin> </plugin>

View file

@ -217,7 +217,7 @@ public class CDebuggerTab extends AbstractCDebuggerTab {
(mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN) (mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)
&& debugConfigs[i].getName().equals("gdb/mi") && debugConfigs[i].supportsMode(mode)) || //$NON-NLS-1$ && debugConfigs[i].getName().equals("gdb/mi") && debugConfigs[i].supportsMode(mode)) || //$NON-NLS-1$
(mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH) (mode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)
&& debugConfigs[i].getName().equals("gdb Debugger") && debugConfigs[i].supportsMode(mode))) { //$NON-NLS-1$ && debugConfigs[i].getName().equals("gdb/mi") && debugConfigs[i].supportsMode(mode))) { //$NON-NLS-1$
String debuggerPlatform = debugConfigs[i].getPlatform(); String debuggerPlatform = debugConfigs[i].getPlatform();
if (validatePlatform(config, debugConfigs[i])) { if (validatePlatform(config, debugConfigs[i])) {
list.add(debugConfigs[i]); list.add(debugConfigs[i]);

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2008 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:
* Ericsson - Initial API and implementation
*******************************************************************************/
package org.eclipse.dd.gdb.internal.ui.launching;
import org.eclipse.cdt.launch.ui.CMainTab;
import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl.SessionType;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.sourcelookup.SourceLookupTab;
public class GdbAttachLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog, java.lang.String)
*/
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
new CMainTab(true),
new CDebuggerTab(SessionType.ATTACH),
new SourceLookupTab(),
new CommonTab()
};
setTabs(tabs);
}
}

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants; import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
@ -37,11 +38,11 @@ import org.eclipse.dd.mi.service.command.commands.MIBreakInsert;
import org.eclipse.dd.mi.service.command.commands.MICommand; import org.eclipse.dd.mi.service.command.commands.MICommand;
import org.eclipse.dd.mi.service.command.commands.MIExecContinue; import org.eclipse.dd.mi.service.command.commands.MIExecContinue;
import org.eclipse.dd.mi.service.command.commands.MIExecRun; import org.eclipse.dd.mi.service.command.commands.MIExecRun;
import org.eclipse.dd.mi.service.command.commands.MIFileExecFile; import org.eclipse.dd.mi.service.command.commands.MIFileExecAndSymbols;
import org.eclipse.dd.mi.service.command.commands.MIFileSymbolFile;
import org.eclipse.dd.mi.service.command.commands.MIGDBSetAutoSolib; import org.eclipse.dd.mi.service.command.commands.MIGDBSetAutoSolib;
import org.eclipse.dd.mi.service.command.commands.MIGDBSetSolibSearchPath; import org.eclipse.dd.mi.service.command.commands.MIGDBSetSolibSearchPath;
import org.eclipse.dd.mi.service.command.commands.MIInferiorTTYSet; import org.eclipse.dd.mi.service.command.commands.MIInferiorTTYSet;
import org.eclipse.dd.mi.service.command.commands.CLIAttach;
import org.eclipse.dd.mi.service.command.commands.MITargetSelect; import org.eclipse.dd.mi.service.command.commands.MITargetSelect;
import org.eclipse.dd.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.dd.mi.service.command.output.MIBreakInsertInfo;
import org.eclipse.dd.mi.service.command.output.MIInfo; import org.eclipse.dd.mi.service.command.output.MIInfo;
@ -66,6 +67,11 @@ public class FinalLaunchSequence extends Sequence {
*/ */
new Step() { @Override new Step() { @Override
public void execute(RequestMonitor requestMonitor) { public void execute(RequestMonitor requestMonitor) {
if (fSessionType == SessionType.ATTACH) {
requestMonitor.done();
return;
}
try { try {
boolean useTerminal = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true); boolean useTerminal = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true);
@ -114,24 +120,19 @@ public class FinalLaunchSequence extends Sequence {
} }
}}, }},
/* /*
* Specify the executable file to be debugged. * Specify the executable file to be debugged and read the symbol table.
*/ */
new Step() { @Override new Step() { @Override
public void execute(RequestMonitor requestMonitor) { public void execute(final RequestMonitor requestMonitor) {
fCommandControl.queueCommand( final IPath execPath = fCommandControl.getExecutablePath();
new MIFileExecFile(fCommandControl.getControlDMContext(), if (execPath != null && !execPath.isEmpty()) {
fCommandControl.getExecutablePath().toOSString()), fCommandControl.queueCommand(
new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor)); new MIFileExecAndSymbols(fCommandControl.getControlDMContext(),
}}, execPath.toOSString()),
/* new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor));
* Read symbol table. } else {
*/ requestMonitor.done();
new Step() { @Override }
public void execute(RequestMonitor requestMonitor) {
fCommandControl.queueCommand(
new MIFileSymbolFile(fCommandControl.getControlDMContext(),
fCommandControl.getExecutablePath().toOSString()),
new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor));
}}, }},
/* /*
* Tell GDB to automatically load or not the shared library symbols * Tell GDB to automatically load or not the shared library symbols
@ -185,7 +186,8 @@ public class FinalLaunchSequence extends Sequence {
locator.getSourceContainers(), requestMonitor); locator.getSourceContainers(), requestMonitor);
}}, }},
/* /*
* If remote debugging, connect to target * If remote debugging, connect to target.
* If attach session, perform the attach.
*/ */
new Step() { new Step() {
private boolean fTcpConnection; private boolean fTcpConnection;
@ -241,7 +243,7 @@ public class FinalLaunchSequence extends Sequence {
} }
return true; return true;
} }
@Override @Override
public void execute(final RequestMonitor requestMonitor) { public void execute(final RequestMonitor requestMonitor) {
if (fSessionType == SessionType.REMOTE) { if (fSessionType == SessionType.REMOTE) {
@ -263,6 +265,10 @@ public class FinalLaunchSequence extends Sequence {
fSerialDevice), fSerialDevice),
new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor)); new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor));
} }
} else if (fSessionType == SessionType.ATTACH) {
fCommandControl.queueCommand(
new CLIAttach(fCommandControl.getControlDMContext(), fPid),
new DataRequestMonitor<MIInfo>(getExecutor(), requestMonitor));
} else { } else {
requestMonitor.done(); requestMonitor.done();
} }
@ -314,6 +320,11 @@ public class FinalLaunchSequence extends Sequence {
@Override @Override
public void execute(final RequestMonitor requestMonitor) { public void execute(final RequestMonitor requestMonitor) {
if (fSessionType == SessionType.ATTACH) {
requestMonitor.done();
return;
}
final MICommand<MIInfo> execCommand; final MICommand<MIInfo> execCommand;
if (fSessionType == SessionType.REMOTE) { if (fSessionType == SessionType.REMOTE) {
// When doing remote debugging, we use -exec-continue instead of -exec-run // When doing remote debugging, we use -exec-continue instead of -exec-run
@ -349,13 +360,20 @@ public class FinalLaunchSequence extends Sequence {
GdbLaunch fLaunch; GdbLaunch fLaunch;
SessionType fSessionType; SessionType fSessionType;
int fPid;
GDBControl fCommandControl; GDBControl fCommandControl;
public FinalLaunchSequence(DsfExecutor executor, GdbLaunch launch, SessionType type) { public FinalLaunchSequence(DsfExecutor executor, GdbLaunch launch, SessionType type) {
super(executor); super(executor);
fLaunch = launch; fLaunch = launch;
fSessionType = type; fSessionType = type;
}
// If a pid is specified, it is for an ATTACH type
public FinalLaunchSequence(DsfExecutor executor, GdbLaunch launch, int attachToPid) {
this(executor, launch, SessionType.ATTACH);
fPid = attachToPid;
} }

View file

@ -61,7 +61,7 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate
{ {
public final static String GDB_DEBUG_MODEL_ID = "org.eclipse.dd.gdb"; //$NON-NLS-1$ public final static String GDB_DEBUG_MODEL_ID = "org.eclipse.dd.gdb"; //$NON-NLS-1$
private SessionType fSessionType; private SessionType fSessionType;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
*/ */
@ -107,23 +107,42 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate
} }
final GdbLaunch launch = (GdbLaunch)l; final GdbLaunch launch = (GdbLaunch)l;
if (fSessionType == SessionType.REMOTE) { if (fSessionType == SessionType.REMOTE) {
monitor.subTask( "Debugging remote C/C++ application" ); //$NON-NLS-1$ monitor.subTask( "Debugging remote C/C++ application" ); //$NON-NLS-1$
} else { } else {
monitor.subTask( "Debugging local C/C++ application" ); //$NON-NLS-1$ monitor.subTask( "Debugging local C/C++ application" ); //$NON-NLS-1$
} }
IPath exePath = verifyProgramPath( config ); IPath exePath = verifyProgramPath( config );
ICProject project = verifyCProject( config ); ICProject project = verifyCProject( config );
if ( exePath != null ) { if ( exePath != null ) {
verifyBinary( project, exePath ); verifyBinary( project, exePath );
} }
setDefaultSourceLocator(launch, config);
monitor.worked( 1 ); monitor.worked( 1 );
// If we are attaching, get the process id now, so as to avoid starting the launch
// and canceling it if the user does not put the pid properly.
int pid = -1;
if (fSessionType == SessionType.ATTACH) {
try {
// have we already been given the pid (maybe from a JUnit test launch or something)
pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1);
} catch (CoreException e) {
// do nothing and fall to below
}
if (pid == -1) {
pid = promptForProcessID(config);
}
if (pid == -1) {
throw new DebugException(new Status(IStatus.CANCEL, GdbPlugin.PLUGIN_ID,
LaunchMessages.getString("LocalAttachLaunchDelegate.No_Process_ID_selected"))); //$NON-NLS-1$
}
}
setDefaultSourceLocator(launch, config);
// Create and invoke the launch sequence to create the debug control and services // Create and invoke the launch sequence to create the debug control and services
final ServicesLaunchSequence servicesLaunchSequence = final ServicesLaunchSequence servicesLaunchSequence =
new ServicesLaunchSequence(launch.getSession(), launch, exePath); new ServicesLaunchSequence(launch.getSession(), launch, exePath);
@ -165,8 +184,12 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate
} }
// Create and invoke the final launch sequence to setup GDB // Create and invoke the final launch sequence to setup GDB
final FinalLaunchSequence finalLaunchSequence = final FinalLaunchSequence finalLaunchSequence;
new FinalLaunchSequence(launch.getSession().getExecutor(), launch, fSessionType); if (fSessionType == SessionType.ATTACH) {
finalLaunchSequence = new FinalLaunchSequence(launch.getSession().getExecutor(), launch, pid);
} else {
finalLaunchSequence = new FinalLaunchSequence(launch.getSession().getExecutor(), launch, fSessionType);
}
launch.getSession().getExecutor().execute(finalLaunchSequence); launch.getSession().getExecutor().execute(finalLaunchSequence);
try { try {
finalLaunchSequence.get(); finalLaunchSequence.get();
@ -200,6 +223,21 @@ public class GdbLaunchDelegate extends AbstractCLaunchDelegate
} }
} }
// Copied from the CDT
protected int promptForProcessID(ILaunchConfiguration config) throws CoreException {
IStatus fPromptStatus = new Status(IStatus.INFO, "org.eclipse.debug.ui", 200, "", null); //$NON-NLS-1$//$NON-NLS-2$
IStatus processPrompt = new Status(IStatus.INFO, "org.eclipse.cdt.launch", 100, "", null); //$NON-NLS-1$//$NON-NLS-2$
// consult a status handler
IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(fPromptStatus);
if (prompter != null) {
Object result = prompter.handleStatus(processPrompt, config);
if (result instanceof Integer) {
return ((Integer)result).intValue();
}
}
return -1;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#getPluginID() * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#getPluginID()

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2008 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:
* Ericsson - Initial API and implementation
*******************************************************************************/
package org.eclipse.dd.mi.service.command.commands;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.mi.service.command.output.MIInfo;
/**
* This command connects to a remote target.
*/
public class CLIAttach extends CLICommand<MIInfo> {
public CLIAttach(IDMContext ctx, int pid) {
super(ctx, "attach " + Integer.toString(pid)); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2008 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:
* Ericsson - Initial API and implementation
*******************************************************************************/
package org.eclipse.dd.mi.service.command.commands;
import org.eclipse.dd.mi.service.command.MIControlDMContext;
import org.eclipse.dd.mi.service.command.output.MIInfo;
/**
* -file-exec-and-symbols [FILE]
*
* Specify the executable file to be debugged. Unlike `-file-exec-and-symbols',
* the symbol table is not read from this file. If used without argument, GDB
* clears the information about the executable file. No output is produced,
* except a completion notification.
*/
public class MIFileExecAndSymbols extends MICommand<MIInfo>
{
public MIFileExecAndSymbols(MIControlDMContext dmc, String file) {
super(dmc, "-file-exec-and-symbols", null, new String[] {file}); //$NON-NLS-1$
}
public MIFileExecAndSymbols(MIControlDMContext dmc) {
super(dmc, "-file-exec-and-symbols"); //$NON-NLS-1$
}
}