Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-debug-dev] Launching the debugger/perspective on a PID

> 
> I am trying to, within code, switch to the debug perspective and debug a 
> process which is already executing - I have its PID.
> I see in the CDT code places where this is possible though there are all 
> sorts of configuration and related classes floating around that I feel 
> leery around jumping in and calling these methods - many are protected 
> anyway.
> 
> Can anyone explain to me how to do this?  In pseudo-code I'm thinking 
> something like:
> 
> int pid = pid_of_currently_executing_process;
> launchDebuggerAndPerspectiveOnPID(pid);
> 
> Surely it's not this simple, but I assume CDT was built in such a way as 
> the above is remotely possible.
> 

It is possible but not simple 8-).  It involves an understanding in
how Eclipse launch framework works.
So for more info on this take a look at the doc (Help contents).
The node of the Debug launch.

The good news:
For what you want to do the code is already in CApplicationLaunchShortcut.
This class tries to discover an already launch extension for the an executable
in none was found it creates a new one, an excerpt from the
createConfiguration()  method.

 ILaunchConfigurationWorkingCopy wc =
	 configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(bin.getElementName()));
 wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectName);
 wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, bin.getCProject().getElementName());
 wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
 wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
		ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, debugConfig.getID());

config = wc.doSave();

config.launch(ILaunchManager.RUN_MODE, null);

In this case you probably want to set
 ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID


The bad news:
We are currently changing some of the attributes:
 ICDTLaunchConfigurationConstants.ATTR_XXXX
and some of the launch interface in the head to remedy inconsistencies.





Back to the top