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

Nathan,

Please, raise a bug in Bugzilla regarding the "getProcessID" method.

Thanks,
Mikhail
----- Original Message ----- From: "Nathan DeBardeleben" <ndebard@xxxxxxxx>
To: <cdt-debug-dev@xxxxxxxxxxx>
Sent: Thursday, October 07, 2004 1:39 PM
Subject: Re: [cdt-debug-dev] Launching the debugger/perspective on a PID


This was very helpful. I got it working with the following code *BUT* there's one catch:

   ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
   ILaunchConfigurationType type = manager.getLaunchConfigurationType(
     ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
       try {
           IPProcess process = getProcess();
ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "SampleLaunchConfig");

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "mpitest2");

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "mpitest");

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, "org.eclipse.cdt.debug.mi.core.CDebugger");
           System.out.println("PID = "+process.getPid());

wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, process.getPid());
           wc.setAttribute(
             ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
            ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH);
ILaunchConfiguration config = wc.doSave(); config.launch(ILaunchManager.DEBUG_MODE, null);
       } catch (CoreException e) {
           e.printStackTrace();
       }

Notice that I am using ATTR_ATTACH_PROCESS_ID which is stated that, when used in conjunction with DEBUGGER_MODE_ATTACH will let me attach to a process. It also states that if the value is -1 then it throws up the process lister. I have found that regardless of my value of ATTACH_PROCESS_ID it throws up the process lister. Looking at the code I find in LocalCLaunchConfigurationDelegate
   . . .
} else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
           int pid = getProcessID();

The method getProcessID() in there opens the process lister! It's totally ignoring my value I've set.
I changed the code to read as follows:

} else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
           String pidstr =
             config.getAttribute(
               ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID,
               "-1");
             Integer pidI = new Integer(pidstr);
             int pid = pidI.intValue();
             if (pid == -1) {
                 pid = getProcessID();
             }
    . . .

Anyway - the above works perfectly. If I provide the PID as a string in ATTACH_PROCESS_ID it works, otherwise it opens the process lister. Could this have been overlooked? I've searched through the CDT plugins and actually never see the ATTACH_PROCESS_ID field ever used.

Thanks so much for your help.

-- Nathan



Alain Magloire wrote:

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();
}
}
....
}


_______________________________________________
cdt-debug-dev mailing list
cdt-debug-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-debug-dev


_______________________________________________
cdt-debug-dev mailing list
cdt-debug-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-debug-dev




Back to the top