Running IIS7 worker processes under debugger

This blogs explains how to configure debugger such that worker processes launch under debugger in Windows Server 2008.

Step 1: Install Debugging tools for windows from http://www.microsoft.com/whdc/devtools/debugging/default.mspx. This will install ntsd.exe which is what we are going to use. Note the directory to which the debuggers got installed.

Step 2: In this step, we will create an entry in Windows System Registry for the debugger. Simply open Windows registry editor (regedit.exe) and navigate to:

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options".

Step 3: Right click on "Image File Execution Options" node and click on New > Key. Name this key "w3wp.exe".

Step 4: In the right pane of Registry editor, right click and add New > String value. Call this key "Debugger".

Step 5: Double click Debugger and in the "Value data" text field, enter the following string:

<debugger path>\ntsd.exe -server npipe:pipe=w3wp%d -G -g

-g tells the debugger not to breakin on the initial breakpoint when the worker process is starting up.

-G tells the debugger not to breakin on the final breakpoint when the worker process is exiting.

Step 6: Make a request to IIS using internet explorer or your faviourite client so that the worker process starts up. Start a command prompt and CD to the debugger folder. Type "tlist -t" to get a tree view of processes running on the machine. Look for w3wp.exe and it should be running under ntsd.exe like:

    svchost.exe (1628)
      ntsd.exe (1308)
        w3wp.exe (2212)

Step 7: Connect to the debugger via remote.exe using the following command:

<debugger path>\ntsd -remote npipe:server=<machine name>,pipe=w3wp<debugger PID>

where <debugger PID> is the PID of the ntsd.exe process under which the worker process is running. In the above example, it will be 1308. Lot of people confuse this with the PID of the worker process which doesn't work.

Note: It is recommended that you match the bitness of debugger with the bitness of w3wp.exe. I mean that if you are running 32 bit worker process on 64 bit OS (in wow64), you should use 32 bit debuggers. In this case, install 32 bit debuggers on the machine and use the following registry key:

"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"

Note: This behavior for wow64 debugging is going to change for next version of windows (win7). I will blog about the new behavior when win7 releases.

No Comments