JIT-attach debugging is the phrase used to describe attaching a debugger to an image which throws an uncaught exception. In unmanaged code, it’s what happens when you are prompted with a message box that invites you to:
If you click CANCEL, a debugger is started and attached to the process. Control for this is made via the registry key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Current Version\AeDebug
For any App that includes managed code, the NGWS runtime will offer a similar feature to JIT-attach a debugger. The registry key that controls these options is called:
HKEY_LOCAL_MACHINE\Software\Microsoft\ComPlus\DbgJITDebugLaunchSetting
Alternatively, you can set the environment variable CORDBG_DbgJITDebugLaunchSetting to achieve the same effect.
The Runtime inspects its value, as follows:
The name of the debugger to attach is stored in the registry key:
HKEY_LOCAL_MACHINE\Software\Microsoft\ComPlus\DbgManagedDebugger
Set this key to hold the command-line launch for the required debugger. For example, to use the CorDbg sample debugger that ship with the SDK, set the DbgManagedDebugger key with a value like this:
c:\Program Files\Com20SDK\Bin\CorDbg.exe !a 0x%x or !a %d
The argument will hold the ID of the process to be debugged. It will be filled in automatically by the Runtime dispatch code.