Attaching and detaching to a program
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. 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
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 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 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 GetEngineInfo to get the engine information of the DE.
Co-creates the DE.
Calls 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 Detach.
The DE sends an IDebugProgramDestroyEvent2.