Attaching and Detaching to a Program
Attaching the debugger requires sending the correct sequence of methods and events with the proper attributes.
Sequence of Methods and Events
The session debug manager (SDM) calls the IDebugProgramNodeAttach2::OnAttach method.
Based on the debug engine (DE) process model, the IDebugProgramNodeAttach2::OnAttach method returns one of the following methods, which determines what happens next.
If S_FALSE is returned, the debug engine has successfully been attached to the program. Otherwise, the IDebugEngine2::Attach method is called to complete the attach process.
If S_OK is returned, the DE is to be loaded in the same process as the SDM. The SDM performs the following tasks:
Calls IDebugProgramNode2::GetEngineInfo to get the engine information of the DE.
Co-creates the DE.
Calls IDebugEngine2::Attach.
The DE sends an IDebugEngineCreateEvent2 to the SDM with an EVENT_SYNC attribute.
The DE sends an IDebugProgramCreateEvent2 to the SDM with an EVENT_SYNC attribute.
The DE sends an IDebugLoadCompleteEvent2 to the SDM with an EVENT_SYNC_STOP attribute.
Detaching from a program is a simple, two-step process, as follows:
The SDM calls IDebugProgram2::Detach.
The DE sends an IDebugProgramDestroyEvent2.