Mar 31, 2014

WinDbg

For 32bit process running on 64bit use WinDbg (x86)
For 64bit process use WinDbg (x64)

Look into task manager and if process has (*32), it means it's a 32 bit process running on 64 bit.

Dump
Task manager can be used to take dumps (Right click process and then create dump ). For 32 bit process use 32bit task manager which is located in C:\Windows\SysWOW64\taskmgr.exe.
Other tools like Debug Diagnostic Tool and ADPlus can also be used for taking dump.
Symbols
Symbol files with PDB extension allows the debugger to map code or data addresses to symbolic information that makes more sense to you when you debug. Some of the commands which are used around symbol files

.symfix = Set the symbol path to the public microsoft symbol server
.sympath = show/set the symbol path
.sympath + <symbol path> = append symbol path to existing symbol path
.reload = reloada all the symbol

SOS
SOS (Son of Strike) is one of the important extension which you will to use native debugging; you can use following command   to load SOS Debugging Extension.
.loadby sos clr

The above command means load sos.dll from the same location where clr is located.


Debugger commands
You can either attach process to the debugger or work with dump file.
Some of the important commands:

Managed Reference Types are created on Heap, which gets cleaned up by GC.

!DumHeap - Displays every single managed object which it finds.
                    Enumerates all the objects: Address,MethodTable, Size
                    Statistical view by categorizing object view by type: Method Table, count,size, class name; this is sorted by size, so the type which occupy maximum size will be shown in the bottom.

!DumHeap -stat

Analyzing size can give some clue in cased of troubleshooting memory leaks. Also comparing dumpheap stat between dumps taken after some interval can give some clue if any particular object is growing in size.

!DumpHeap -type System.Char[]

!DumpObjet(!do) - Dump singe reference objet
!DumpArray(!da) - Dump an array object
!thread - List all managed code thread running in the process, last exception thrown on any thread. In parenthesis it shows address of exception object so you can run !do on that to get more detail
!PrintException - shows exception information of specified exception
!clrstack -a - Managed code call stack; you can get address of local object and then do !do on those to get more details on that
!GCRoot - Reference chain of object, get address from !clrstack -a
~* e!clrstack - Displays all managed threads and call stack

Reference
http://vimeo.com/9936296