Debugging a Runtime Process
The common language runtime (CLR) debugging API supports debugging in the runtime environment. The following is a step-by-step description of how a runtime process is debugged:
The debugger creates an instance of the ICorDebug interface. The debugger invokes CComPtrBase::CoCreateInstance by using the CLSID CLSID_CorDebug to obtain an instance of ICorDebug.
The debugger initializes the debugging API by calling the ICorDebug::Initialize method.
The debugger registers a managed event handler. The debugger invokes the ICorDebug::SetManagedHandler method to register an instance of the ICorDebugManagedCallback interface as the callback for receiving notification and information about events in managed code.
The debugger optionally registers an unmanaged event handler. If the debugger wants to debug unmanaged code, it invokes the ICorDebug::SetUnmanagedHandler method to register an instance of ICorDebugUnmanagedCallback as the callback for receiving notification and information about events in unmanaged code.
The debugger creates the debuggee process. The debugger calls the ICorDebug::CreateProcess method to create a process.
The debugging API notifies the debugger about the new debuggee process. The debugging API calls ICorDebugManagedCallback methods, starting with ICorDebugManagedCallback::CreateProcess. This may be followed by calls to ICorDebugManagedCallback::LoadModule, ICorDebugManagedCallback::LoadClass, ICorDebugManagedCallback::CreateThread, and so on.
The debugger stops debugging. At some point, the debugger will get an ICorDebugManagedCallback::ExitProcess event, indicating that the debuggee is no longer executing. At some point after that, the debugger releases all references to any interfaces it has, and then calls the ICorDebug::Terminate method.