My StackHash Debugging Script

I’ve been beta testing StackHash, a “thick client” for Microsoft’s Windows Error Reporting website. It does a great job of ameliorating the pain of using Winqual by downloading and caching all the event data locally, then adds helpful features such as being able to debug CABs with a couple of clicks.

By default, it’s configured to launch WinDbg (from the Debugging Tools for Windows package), but I’ve found this to be insufficient.

Firstly, we use the Microsoft Symbol Server and also have a local symbol server that stores the PDBs for the release versions of our software. Secondly, Microsoft apparently doesn’t put the binaries for .NET Framework security patches on the symbol server, so you need to collect those manually and add them to the symbol path. (To do this, install the latest Windows Updates, then copy the C:\Windows\Microsoft.NET\Framework\v2.0.50727 folder to a shared location. Repeat for XP, Vista, and Windows 7.) Finally, I want to automatically start crash analysis when the dump is opened.

Some of this can be worked around by setting global environment variables, but this will also affect Visual Studio’s debugger, which may be unwanted. I created the following batch file to set up the environment for debugging, then set it as the debugger in StackHash’s Tools > Client Options > Debuggers > 32-bit Debugger setting. A similar script could be created for 64-bit debugging.

(Note: lines are broken for readability; they need to be joined together. _\\server\Symbols_ is our local symbol server, _\\server\Framework_ is a shared folder where we place specific versions of the .NET Framework that aren’t yet on the Microsoft symbol server. This batch file assumes WinDbg is installed in the standard location.)

@echo off
PATH %PATH%;C:\Program Files (x86)\Debugging Tools for Windows (x86)
set _NT_EXECUTABLE_IMAGE_PATH=\\server\Framework\v2.0.50727.4952;\\server\Framework\v2.0.50727.4206;\\server\Framework\v2.0.50727.3615;\\server\Framework\v2.0.50727.4927;\\server\Framework\v2.0.50727.4200
set _NT_SYMBOL_PATH=%_NT_EXECUTABLE_IMAGE_PATH%;SRV*C:\Symbols*\\server\Symbols*http://msdl.microsoft.com/download/symbols
"C:\Program Files (x86)\Debugging Tools for Windows (x86)\windbg.exe" -QY -c ".loadby sos mscorwks;!analyze -v" %*

UPDATE: Scott points out that this can be simplified by using the -y command-line argument to WinDbg to set the symbol path. (I didn’t use -i to set the executable path, because it turned out to be unnecessary.) This reduces the batch file to one (long) line:

@"C:\Program Files (x86)\Debugging Tools for Windows (x86)\windbg.exe" -y\\server\Framework\v2.0.50727.4952;\\server\Framework\v2.0.50727.4206;\\server\Framework\v2.0.50727.3615;\\server\Framework\v2.0.50727.4927SRV*C:\Symbols*\\server\Symbols*http://msdl.microsoft.com/download/symbols -QY -c ".loadby sos mscorwks;!analyze -v" %*

Posted by Bradley Grainger on September 01, 2010