WinDBG cheat sheet
Prereqs
Install
debugging Tools for Windows. To debug managed code, install SOS.dll. It is automatically installed with Visual Studio
and with Windows SDK.
Set symbol path (Make sure you have a ton of space on drive to download symbols)
srv*c:\websymbols*http://msdl.microsoft.com/download/symbols
Examining the unmanaged environment
- .load sos mscorwks (This command load the sos debugger extension)
- .loadby sos mscorwks
- .dump /mA (filepath) (This command generates a full memory dump)
- ~*k (This command lists all call stacks from all threads)
- ~* e !clrstack (This command dumps all clr stack. This is to show how to execute
a command against all threads.))
- dqs (Addr) + 120 (This command shows word and symbols. Use dds (Addr) + 120 for
32bit)
- dc (Addr)
- .chain (Show you all the extensions in the order. Only to check debug extensions
are loaded correctly)
- ~20s (This command switches to thread 20.)
- lmf (lists all loaded modules with the full path)
- lmt (lists all loaded modules with the last modified timestamp)
- ~ list (lists unmanaged threads)
- ~thread s (select a thread s for executing thread specific commands)
- !token -n (view the thread permissions)
- k (view unmanaged call stack)
- !runaway (view CPU consumption for the thread)
- bp (set a breakpoint)
- .dump path (dump the small memory image)
- .dump /ma path (dump the complete memory image)
- !heap (list the heaps with index and the heap address)
Managed commands (assumes SOS is available)
- !dae (This command lists all exceptions)
- !waitlist (This command shows waitlist. May be useful to look at hangs or long waits)
- !handle (This command shows handle. May be useful to looking at handle leaks)
- !htrace (Trace handle leak. http://channel9.msdn.com/Blogs/jeff_dailey/Understanding-handle-leaks-and-how-to-use-htrace-to-find-them
)
- !dso (see what objects the thread owns. Useful in finding where memory is allocated.)
- !do (dump object array)
- !cce (Check current exception)
- !analyze –v (This command does analysis and tells you what it thinks is wrong.
Generate a lot of files. But this is usually useless in user mode debugger.)
Debug managed memory leak
- !dumpdomain (This command list the assemblies. Look for unknown domains for dynamically
loaded assemblies)
- !EEHeap (This command gets a summary of CLR memory)
- !DumpHeap –stat
- !gcroot <object address>
References
Nirav Home
Suggestions/Comments/corrections are welcome. Contact me at
the address shown in the home page.
Copyright 2005-2011, Nirav Jasapara