Attaching and detaching to a program

Applies to: yesVisual Studio noVisual 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

  1. 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:

    1. Calls GetEngineInfo to get the engine information of the DE.

    2. Co-creates the DE.

    3. Calls Attach.

  2. The DE sends an IDebugEngineCreateEvent2 to the SDM with an EVENT_SYNC attribute.

  3. The DE sends an IDebugProgramCreateEvent2 to the SDM with an EVENT_SYNC attribute.

  4. 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:

  5. The SDM calls Detach.

  6. The DE sends an IDebugProgramDestroyEvent2.

See also