Geeks With Blogs
David Douglass .NET on My Mind

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

 

Posted on Tuesday, March 14, 2006 4:55 AM | Back to top


Comments on this post: WinDbg / SOS Cheat Sheet

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
when I do .loadby sos mscorwks I get error Unable to find module 'mscorwks". What does that mean?
Left by nikolay aristov on Jul 19, 2007 12:34 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
.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.
Left by David Douglass on Jul 19, 2007 8:48 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Thanks a lot! :) Just what I needed.
Left by Thomas Pettersen on Dec 11, 2007 1:41 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
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?
Left by Shan McArthur on Apr 23, 2008 6:54 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
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?
Left by Shan McArthur on Apr 23, 2008 7:02 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
.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.
Left by David Douglass on Apr 23, 2008 8:28 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Try this:

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

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

Left by Blah on Aug 05, 2008 2:58 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Thank You
Left by rüya tabiri on Aug 29, 2008 10:57 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
thank Youuu...
Left by parke on Aug 29, 2008 11:00 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
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...
Left by Maha on Sep 12, 2008 3:56 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
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.


Left by Gregory Chernis on Mar 15, 2009 2:30 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Thanks a lot. It had let me solve very naughty issues in a release build in a mixed environment application twice.
Left by Zaki Shaheen on Sep 29, 2009 7:30 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Cheat sheet is not only awesome but saves a lot of headaches when debugging. Very handy, thank you for allowing us who are in the debugging field to use what you have put together. Very nice
Left by americancritic on Jul 01, 2011 7:05 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
I can't get ".load clr10\sos" to work. Do I have to do something specific first?
Left by Proteinpulver on Jul 13, 2011 6:35 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
use !loadby sos clr for debugging .net 4.
Left by Bryan on Aug 09, 2011 6:28 PM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Than you very much.... very useful post :-)
Left by sardo007 on Jan 30, 2012 11:50 AM

# re: WinDbg / SOS Cheat Sheet
Requesting Gravatar...
Thanks for your post, very helpful.
Left by Dennis Gao on Mar 12, 2013 11:25 PM

Your comment:
 (will show your gravatar)


Copyright © David Douglass | Powered by: GeeksWithBlogs.net | Join free