Just-In-Time (JIT) Debugging

Just-In-Time (JIT) Debugging

JIT debugging attaches a registered debugger to an application when an unhandled exception is raised or otherwise crashes. The JIT debugger for these events can be set in the registry. You can inspect the registry using the Regedit tool. In this text, HKLM is shorthand for HKEY_LOCAL_MACHINE.

For managed code, the following key manages JIT debugging:

  • HKLM\Software\Microsoft\.NETFramework

The DbgJITDebugLaunchSetting value at this key sets the behavior of the just-in-time dialog box. There are three possible values. A value of zero requests that the Microsoft Error Reporting dialog box is displayed for JIT debugging. In the Microsoft Error Reporting dialog box, click the Don't Send button to launch the JIT debugging dialog box. Both the Microsoft Error Reporting and the JIT debugging dialog boxes are shown in Figures 13-1 and 13-2. A value of 1 causes the Microsoft Error Reporting dialog box to be suppressed. A value of 2 forces the JIT debugging dialog box to be displayed when JIT debugging occurs. However, the Microsoft Error Reporting dialog box is not shown. The default value for DbgJITDebugLaunchSetting is zero. In addition to the DbgJITDebugLaunchSetting value, you can name the managed JIT debugger in the DbgManagedDebugger value. Figure 13-3 has the managed debugging key and values.

Image from book
Figure 13-1: Microsoft Error Report dialog box
Image from book
Figure 13-2: Just-in-Time Debugging dialog box
Image from book
Figure 13-3: View of the .NETFramework key and DbgManagedDebugger value

For unmanaged code, you configure JIT debugging at the following registry key:

  • HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug

The Auto value of this key controls the Just-in-Time Debugging dialog box. Zero causes the Microsoft Error Reporting dialog box to be displayed. If the Debug button is clicked on the Microsoft Error Reporting dialog box, the Just-in-Time Debugging dialog box is displayed next. A value of 1 displays the Just-in-Time Debugging dialog box directly. The Debugger value of the AeDebug registry key holds the name of the JIT unmanaged debugger.

Visual Studio .NET is named as the default managed and unmanaged debugger when the product is installed. If that changes, you can reappoint Visual Studio .NET as the default debugger from the Tools menu and the Options dialog box. Choose the Just-In-Time section in the Debugging pane. From that window, choose the types of code for which Visual Studio .NET should be the JIT debugger.

Figure 13-4 shows the JIT debugging selections.

Image from book
Figure 13-4: Just-In-Time pane

You can install other debuggers as the default JIT debugger. The I startup option of the WinDbg or Dr. Watson tools installs either as the default unmanaged debugger. You can also manually change the registry to make these tools the default managed or unmanaged JIT debuggers:

  • WinDbg -I

  • Drwtsn32 -I