Attaching to the Program
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
After you have registered your programs with the appropriate port, you must attach the debugger to the program you want to debug.
Choosing How to Attach
There are three ways in which the session debug manager (SDM) attempts to attach to the program being debugged.
For programs that are launched by the debug engine through the LaunchSuspended method (typical of interpreted languages, for example), the SDM obtains the IDebugProgramNodeAttach2 interface from the IDebugProgramNode2 object associated with the program being attached to. If the SDM can obtain the
IDebugProgramNodeAttach2
interface, the SDM then calls the OnAttach method. TheIDebugProgramNodeAttach2::OnAttach
method returnsS_OK
to indicate that it did not attach to the program and that other attempts can be made to attach to the program.If the SDM can obtain the IDebugProgramEx2 interface from the program being attached to, the SDM calls the Attach method. This approach is typical for programs that were launched remotely by the port supplier.
If the program cannot be attached through the
IDebugProgramNodeAttach2::OnAttach
orIDebugProgramEx2::Attach
methods, the SDM loads the debug engine (if not already loaded) by calling theCoCreateInstance
function and then calls the Attach method. This approach is typical for programs launched locally by a port supplier.It is also possible for a custom port supplier to call the
IDebugEngine2::Attach
method in the custom port supplier's implementation of theIDebugProgramEx2::Attach
method. Typically in this case, the custom port supplier launches the debug engine on the remote machine.Attachment is achieved when the session debug manager (SDM) calls the Attach method.
If you run your DE in the same process as the application to be debugged, then you must implement the following methods of IDebugProgramNode2:
-
After the
IDebugEngine2::Attach
method is called, follow these steps in your implementation of theIDebugEngine2::Attach
method:
Send an IDebugEngineCreateEvent2 event object to the SDM. For more information, see Sending Events.
Call the GetProgramId method on the IDebugProgram2 object that was passed to the
IDebugEngine2::Attach
method.This returns a
GUID
that is used to identify the program. TheGUID
must be stored in the object that represents the local program to the DE, and it must be returned when theIDebugProgram2::GetProgramId
method is called on theIDebugProgram2
interface.Note
If you implement the
IDebugProgramNodeAttach2
interface, the program'sGUID
is passed to theIDebugProgramNodeAttach2::OnAttach
method. ThisGUID
is used for the program'sGUID
returned by theIDebugProgram2::GetProgramId
method.Send an IDebugProgramCreateEvent2 event object to notify the SDM that the local
IDebugProgram2
object was created to represent the program to the DE. For details, see Sending Events.Note
This is not the same
IDebugProgram2
object that was passed into theIDebugEngine2::Attach
method. The previously passedIDebugProgram2
object is recognized by the port only and is a separate object.
See Also
Launch-based Attachment
Sending Events
LaunchSuspended
IDebugProgram2
IDebugProgramCreateEvent2
IDebugProgramNodeAttach2
OnAttach
IDebugProgramNode2
GetProgramId
IDebugProgramEx2
Attach
Attach