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've tried to implement this and am running into tons and tons of brick 
> walls.  The code you sent me to look at utilizes a large number of 
> protected and private methods - the only public interfaces to it don't 
> let me send in a PID. 
> I implemented the following code but it doesn't work and brings me to 
> wonder if I'm approaching this the wrong way.  My plugin is separate 
> from CDT - if that's true, can I call methods in the CDT plugin - even 
> if they are static?
> 
> It seems like a simple request:
> I have a plugin, it starts a job running, I grab the PID of that job, I 
> provide a UI Button which reads 'debug process' which, upon clicked, I 
> want the debug perspective to start and start debugging my running job.
> Obviously all of that is simple up until the very end.
> I've read the articles after your suggestion on the Eclipse site having 
> to do with launch configurations and the like.
> 
> Any chance any more assistance can be provided that can point me in the 
> right direction?
> Am I totally taking the wrong approach? :)
> 

Well ... the class that I pointed you at was to be use as an example on
__how__ to create a launcher, not to be extended.
You'll have to read the docs on Eclipse Launch framework and look
at the source of the CDT.  I can not write the code for you.
If you, however, have specific problems or requests send an email
or make a PR for bugs.

To help you kick start here is a some template code, taken from
the CApplicationShortcut class, isolating the important bits.
This will create a launch debugging session, for the executable
foobar.exe and stops at main().

public class SampleAction implements IWorkbenchWindowActionDelegate {
	private IWorkbenchWindow window;
	/**
	 * The constructor.
	 */
	public SampleAction() {
	}

	/**
	 * The action has been activated. The argument of the
	 * method represents the 'real' action sitting
	 * in the workbench UI.
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
		ILaunchConfigurationType type = manager.getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
		try {
			ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "SampleLaunchConfig");
			wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "foobar");
			wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "foobar.exe");
			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, "org.eclipse.cdt.debug.mi.core.CDebugger");
			wc.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT);

			ILaunchConfiguration config = wc.doSave();	
			config.launch(ILaunchManager.DEBUG_MODE, null);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
....
}




Back to the top