.NET code.

WinDBG Tips

I had previously blogged about finding some good tutorials on how to get started. I’ve been using the WinDBG debugger a little bit more lately and I’ve put together a “cheat sheet” that I use for the most common commands and I thought I would share them. Almost all of these commands are specific to the SOS extension to debug .NET code.

If you are a seasoned WinDBG user, you’ll know all of these command by heart, but if you are just getting started this might help. The first thing to do is run, don’t walk to setup your “Symbol Search Path” setting. Enter CTRL+S from inside WinDBG, mine looks like this:

You can find out more about it in this Microsoft support article.

The WinDBG command line has TAB completion, so when you type the first few characters of a command, hit TAB to cycle through the possible completions.

I have picked up the majority of these tips by reading some of the great blogs on MSDN. If you are interested in learning a lot more about WinDBG and how to debug some very difficult problems you need to subscribe to Tess’s blog right away!

If you know of any other tips or helpful WinDBG command, please post them in the comments and I’ll add them to the list.

Command Description
.loadby sos mscorwks Loads the correct version of the SOS(.NET) extension dll based on the version of mscorwks currently loaded
.chain View the currently loaded extensions
.hh command Opens the help file for the specified command. For example: .hh ~
!help Displays help for extensions, including for SOS a list of commands
!help command Displays help for the specified extension command. For example: !help clrstack
.cls Clears the sceen
~ List all threads
!threads List managed threads
~# s Set current thread, where # is a thread number, for example: ~3 s
!clrstack Display the CLR stack
!clrstack Display the CLR stack with parameters
kb Display the stack frame for the native thread
!dso Dump objects on the stack
!do Dump managed object
dc Display the contents of memory as DWORDS and ASCII chars
!dumpheap Dumps the contents of the managed heap
!dumpheap -stat Display stat summary of managed heap
!dumpmt address Dumps the MethodTable of the specified address
!dumpmt -md address Dumps the MethodTable of the specified address and displays a list of all the methods on the object
!dumpclass address Displays the EEClass for the specified address
!dumpobj address Display the details of the object at the specified address
!eestack Runs !DumpStack on all threads
!dumpruntimetypes Displays all System.RuntimeType object from the managed heap
!runaway Displays thread time statistics
.time Displays System Uptime, Process Uptime, Kernel Time and User Time
!syncblk Displays synchronization lock info
!dumpheap -thinlock Displays objects locked with thinlocks instead of syncblk’s
!dumpheap -type System.String -stat Displays count and total size of the specified type (in this case System.String) on the heap
!address Display virtual memory stats, load addresses and reserve/commit info
!address -summary Display just the summary virtual memory info
!eeheap -gc Display garbage collector generation info
!pe Print exception details
~*kb Display callstacks for all threads
!finalizequeue Display stats and contents of the finalizer queue

ScottGu’s ASP.NET 2.0 Tips/Tricks TechEd Talk Posted

If you develop with ASP.NET you need to subscribe to Scott Guthrie’s blog.

His blog is full of detailed and well written articles that provide invaluable insight to any ASP.NET programmer.

He just posted the PowerPoint presentation and the sample code from his TechEd talk. I would highly recommend you download and review the sample project. I know every time I download samples that Scott has posted I learn something new.

Some of the features shown:

  • app_offline.htm
  • cross page postbacks
  • maintaining scrollback position
  • default button
  • custom databinding expressions

ScottGu’s ASP.NET 2.0 Tips/Tricks TechEd Talk Posted

If you develop with ASP.NET you need to subscribe to Scott Guthrie’s blog.

His blog is full of detailed and well written articles that provide invaluable insight to any ASP.NET programmer.

He just posted the PowerPoint presentation and the sample code from his TechEd talk. I would highly recommend you download and review the sample project. I know every time I download samples that Scott has posted I learn something new.

Some of the features shown:

  • app_offline.htm
  • cross page postbacks
  • maintaining scrollback position
  • default button
  • custom databinding expressions

Really Powerful Debugging With WinDBG & SOS.dll

If you have never used WinDBG or the SOS extensions before, read the following blog posts by Mike Taulty:

  • A word for WinDBG – Part 1
  • A word for WinDBG – Part 2

Mike walks you through a sample debugging session with WinDBG. Then in the second part, he focuses on the SOS extensions for .NET debugging. With the SOS extension you can do some seriously cool stuff:

  • View thread/threadpool info
  • View the finalizequeue
  • See what’s allocated on the managed heap
  • Determine what is keeping your managed object from being finalized by viewing it’s “roots”

If you have Visual C++ installed you can actually use SOS calls from the Visual Studio debugger! Read Mike’s post, that walks you through the setup and use of SOS from inside Visual Studio. As Mike points out, make sure you go to the project properties, choose Debug, and then check “Enabled unmanaged code debugging”. Be prepared the very first time you do this, it might be slow because the symbols have to be downloaded/loaded.