WinDbg / SOS Cheat Sheet

Here are the WinDbg / SOS commands I talked about at Code Camp NY.  These are the basic commands to get you going with WinDbg / SOS.

 

Starting, Attaching, Executing and Exiting

 

Start -> All Programs -> Debugging Tools for Windows -> WinDbg

F6

attach to process

Ctrl-Break

interrupt debugee

.detach

detach from a process

g

continue debugee execution

q

exit WinDbg

 

Getting Help

?

help on commands that affect the debugee

.help

help on commands that affect the debugger

.hh command

view the on line help file

!help

help on the extension dll at the top of the chain (e. g., SOS)

 

Issuing Commands

up arrow, down arrow, enter

scroll through command history

Right mouse button

paste into command window

 

Examining the Unmanaged Environment

lmf

list loaded modules with full path

lmt

list loaded modules with last modified timestamp

~

list unmanaged threads

~thread s

select a thread for thread specific commands

!token -n

view thread permissions

k

view the unmanaged call stack

!runaway

view thread CPU consumption

bp

set a breakpoint

.dump path

dump small memory image

.dump /ma path

dump complete memory image

 

Working with Extension DLLs (e. g., SOS)

.chain

list extensions dlls

.load clr10\sos

load SOS for debugging framework 1.0 / 1.1

.unload clr10\sos

unload SOS

.loadby sos mscorwks

load SOS for debugging framework 2.0

 

SOS Commands

!threads

view managed threads

!clrstack

view the managed call stack

!dumpstack

view combined unmanaged & managed call stack

!clrstack -p

view function call arguments

!clrstack –l

view stack (local) variables

!name2ee module class

view addresses associated with a class or method

!dumpmt –md address

view the method table & methods for a class

!dumpmd address

view detailed information about a method

!do address

view information about an object

!dumpheap –stat

view memory consumption by type

!dumpheap –min size

view memory consumption by object when at least size

!dumpheap –type type

view memory consumption for all objects of type type

!gcroot address

view which object are holding a reference to address

!syncblk

view information about managed locks

 

SOS 2.0 Commands

!bpmd module method

set breakpoint

!DumpArray address

view contents of an array

!PrintException

view information about most recent exception

 

Print | posted @ Tuesday, March 14, 2006 4:55 AM

Comments on this entry:

Gravatar # re: WinDbg / SOS Cheat Sheet
by nikolay aristov at 7/19/2007 12:34 PM

when I do .loadby sos mscorwks I get error Unable to find module 'mscorwks". What does that mean?
Gravatar # re: WinDbg / SOS Cheat Sheet
by David Douglass at 7/19/2007 8:48 PM

.loadby locates a DLL by looking in the same directory as where another DLL was loaded from. So, ".loadby sos mscorwks" tells WinDbg to look up which directory mscorwks.dll was loaded from and load sos.dll from there. If you're running an unmanaged application (i. e., a non .NET application) then mscorwks.dll won't be loaded and you get the message "Unable to find module 'mscorwks'". You also get this message if you break into a managed application very early, before the .NET CLR is loaded.
Gravatar # re: WinDbg / SOS Cheat Sheet
by Thomas Pettersen at 12/11/2007 1:41 PM

Thanks a lot! :) Just what I needed.
Gravatar # re: WinDbg / SOS Cheat Sheet
by Shan McArthur at 4/23/2008 6:54 PM

When I try .loadby sos mscorwks.dll, I get Unable to find module 'mscorwks.dll'. I am opening an IIS crash dump. Are you saying that in this crash dump (of an asp.net site) that .net runtime is not loaded yet (and therefore is not in the minidump file), or is it a problem with multiple .net versions and symbols on my workstation that I am trying to examine it with Windbg?
Gravatar # re: WinDbg / SOS Cheat Sheet
by Shan McArthur at 4/23/2008 7:02 PM

followup to previous message... I did a LM to list the loaded modules, and mscorwks is not listed as a loaded module. There are many other mscor* modules, and this is an asp.net website with other .net modules loaded. It doesn't seem like SOS can function without the mscorwks module in the crash dump file. This is a second chance exception. I want to see the exception - is there another way to force SOS to show me this if the mscorwks module is not loaded in the crash dump?
Gravatar # re: WinDbg / SOS Cheat Sheet
by David Douglass at 4/23/2008 8:28 PM

.loadby is just a convenience. .loadby sos mscorwks says to load sos.dll from whatever directory mscorwks.dll was loaded from. Is sos.dll in the same directory as mscorwks.dll? If not, use .load followed by the complete path to sos.dll.

You say that when you do an lm you don’t see mscorwks. Note that if you’re using a server operating system you should use mscorsvr instead of mscorwks for framework 1.0 and 1.1.
Gravatar # re: WinDbg / SOS Cheat Sheet
by Blah at 8/5/2008 2:58 PM

Try this:

sxe ld:mscorlib
g
(... breaks again ...)
.loadby sos mscorwks

The 'sxe ld:..' stops on module load.

Gravatar # re: WinDbg / SOS Cheat Sheet
by rüya tabiri at 8/29/2008 10:57 AM

Thank You
Gravatar # re: WinDbg / SOS Cheat Sheet
by rüya tabirleri at 8/29/2008 10:59 AM

thanks you
Gravatar # re: WinDbg / SOS Cheat Sheet
by parke at 8/29/2008 11:00 AM

thank Youuu...
Gravatar # re: WinDbg / SOS Cheat Sheet
by Maha at 9/12/2008 3:56 AM

Hi
I need a info regarding on how to load sos dll for unmanaged application (like vc++ windows app).
I need to check the memory usage with this windbg. Could I get help here...
Gravatar # re: WinDbg / SOS Cheat Sheet
by Gregory Chernis at 3/15/2009 2:30 PM

I guess you could use this piece of info:

Please see
http://support.microsoft.com/kb/892277

Quoting:
If you are running on a multi-processor system (or a hyper-threaded system), you will see function calls in mscorsvr instead of mscorwks.


Gravatar # re: WinDbg / SOS Cheat Sheet
by Zaki Shaheen at 9/29/2009 7:30 AM

Thanks a lot. It had let me solve very naughty issues in a release build in a mixed environment application twice.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: