Thursday, March 15, 2012

Dumping ground for some useful WinDbg commands

Dumping ground for some useful WinDbg commands and links:
1. Setup symbols path
srv*C:\symbols\web*http://msdl.microsoft.com/download/symbols;C:\symbols\web;C:\symbols\private
2. Load SOS
.loadby sos mscorwks(or "clr" when on .NET 4 tools)
.load sosex
.reload

3. Usefull commands
!threadpool
We can then use the !Threadpool-command to find out exactly what the CPU-usage was at the time the dump was taken. We'll also get some useful information like the number of work requests in the queue, completion port threads and timers.
!runaway
This is a nice command that will list all running threads and their CPU-usage. It's your best friend when troubleshooting a high CPU hang issue.
!threads
To get more information about the running threads we can run the !Threads-command. This will list all managed threads in the application, what application domain the thread is currently executing under, etc.
Switch to thread: ~[number of thread]s ex: ~50s
!clrstack -p
List the stack for the current thread
!pe
Print exception
Display all managed threads call stacks:
~*e !CLRStack (~ = symbol for thread, * = any, e = execute an action. Mean: for each thread, execute !CLRStack command)

###Memory leaks###
!eeheap -gc
!dumpheap -stat

!dumpobject (!do)
!dumpstackobjects (!dso)
!dumparray (!da)

!dumpheap -stat -type TextBox
!dumpheap -mt "address"
!gcroot "address" --see what is keeping alive this object

###Sosex###
!dlk - detect deadlock
!mk
To cancel a long execution in debugger (BUSY word on left bottom), press CTRL + Pause



Link to sosex : http://www.stevestechspot.com/
List of available commands: http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx
Other links:
http://blogs.msdn.com/b/johan/archive/2007/01/11/how-to-install-windbg-and-get-your-first-memory-dump.aspx
http://blogs.msdn.com/b/tess/archive/tags/debugging/
http://blogs.msdn.com/b/tess/archive/2008/02/04/net-debugging-demos-information-and-setup-instructions.aspx