About the Author
Arno Huetter
Arno wrote his first lines of code on a Sinclair ZX80 in
1984.
Over the years, he has been programming in C/C++,
Java and C#, and also did quite some database
development.
Today he is Development Lead at Dynatrace (APM
vendor).
WinDbg Core Features
WinDbg 1.0 released in 2000 (rewrite of previous WinDBG)
Usermode Debugging
Kernel/Remote Debugging
Post-mortem Debugging
Huge set of commands (some quite cryptical)
UI (oh well...)
Debugging Extensions (.NET: SOS, SOSEX, Psscor2|4, etc)
Script Engine
32bit vs. 64bit Version: Use the WinDbg executable matching your process bitness
What about Visual Studio Debugger?
Visual Studio Debugger?
Easier to use
Sufficient for many debugging problems
Also supports remote, kernel and post-mortem debugging
WinDbg helps on the really tough cases (and most interesting ones)
For example, one might just have a function offset from an eventlog entry (no symbols), or some
bytes from the stack, or a dump from an old binary without symbols, or...
Problem might be not reproducible and only happening in production in border case scenario, or at
Windows startup, in a driver, etc. WinDbg is well suited for post-mortem, can also connect over
RS232, USB. Lightweight installation, WinDbg even runs from USB stick.
WinDbg Extensions and Scripts provide powerful means, e.g. to analyze heap corruption, etc.
WinDbg Download
Part of Windows SDK/WDK, choose Debugging Tools within SDK Download
Installer
https://msdn.microsoft.com/en-
us/library/windows/hardware/ff551063%28v=vs.85%29.aspx
Demo 4: Analyzing a .NET Deadlock
Enter: SOS (Son Of Strike) .NET Debugging Extension
Load SOS (part of every CLR)
0:008> .loadby sos clr
0:008> .cordll -ve -u -l
Automatically loaded SOS Extension
CLRDLL: Loaded DLL C:WindowsMicrosoft.NETFrameworkv4.0.30319mscordacwks.dll
CLR DLL status: Loaded DLL
C:WindowsMicrosoft.NETFrameworkv4.0.30319mscordacwks.dll
Memdumps: Always use sos.dll / mscordacwks.dll from identical CLR (version /
bitness). Latest WinDbg releases can load matching sos.dll from Microsoft symbol
server.
Some WinDbg commands
Go
g
Set breakpoint at address
bp [Addr]
Set breakpoint at symbol (pattern)
bm SymPattern
Set breakpoint on access
ba [r|w|e] [Size] Addr
More WinDbg commands
Display callstack for selected thread
k
Display local variables and parameters
dv [/i /t /V /a /n /z] [Pattern]
Display type
dt [-n|y] [mod!]Name [-n|y] [Field] [Addr] -abcehioprsv
0:000> dt 0x0100297c MYTYPE1
+0x000 a : 22
+0x004 b : 43 '+'
+0x006 c : 0x0
+0x008 d : 0x0
+0x00c gn : [6] 0x0
More WinDbg commands
Display callstacks for all threads
~* k
Dump all registers
r
Show process environment block
!peb
Display time consumption per thread
!runaway
Search memory for pattern
s -[Flags][b|w|d|q|a|u] Range Pattern
Selected SOS commands
Display managed callstack
!CLRStack [-a] [-l] [-p] [-n]
Display managed / unmanaged callstack for all threads (see: !DumpStack)
!EEStack [-short] [-EE]
Display IL associated with managed method
!DumpIL <Managed DynamicMethod object> | <MethodDesc pointer>
Heap object statistics
!DumpHeap –stat
Display object at specified address
!DumpObj [-nofields] <object address>
Selected SOSEX commands
Display deadlocks between SyncBlocks and/or ReaderWriterLocks
!dlk [-d]
Display GC roots for the specified object
!mroot <ObjectAddr> [-all]
Print a stack trace of managed and unmanaged frames
!mk
Search the managed heap for strings
strings [ModuleAddress] [Options]
Selected PSSCOR commands
Displays all objects on stack
!DumpStackObjects
Shows detailed info about running HttpRuntime (ASP.NET)
!DumpHttpRuntime
Save all .NET assemblies to local disk
!SaveAllModules folderName
Dump all exceptions found in heap (incl. callstacks)
!dae
Find managed MethodDesc and JITted code address
!Name2EE mscorlib.dll System.String.ToString
For your Toolbox
MS DebugDiag
http://blogs.msdn.com/b/debugdiag/
Process-specific rules for crashes,
perfcounters, memory usage, exceptions
Creates full dumps, mini dumps, stack traces
Built-in auto-analysis
For your Toolbox
SysInternals ProcDump
https://technet.microsoft.com/en-us/sysinternals/dd996900.aspx
Commandline tool for dump creation
Can be event-triggered, e.g. CPU usage
MS AppVerifier
https://msdn.microsoft.com/en-us/library/ms220948(v=vs.90).aspx
Runtime verification for native code, e.g. memory corruption
For your Toolbox
VerySleepy
http://www.codersnotes.com/sleepy/
CPU profiler
Samples native callstacks, aggregates results over time
Online Resources
Common WinDbg Commands (Thematically Grouped)
http://windbg.info/doc/1-common-cmds.html
SOS.dll (SOS Debugging Extension)
https://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx
"If broken it is, fix it you should" - Tess Ferrandez Blog
https://blogs.msdn.microsoft.com/tess/
Software Diagnostics Institute
http://www.dumpanalysis.org/