Skip to content

Instantly share code, notes, and snippets.

@jennings
Last active June 1, 2023 05:12
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jennings/265fc3ddd33350f0f6ed0c837c7a1619 to your computer and use it in GitHub Desktop.
Save jennings/265fc3ddd33350f0f6ed0c837c7a1619 to your computer and use it in GitHub Desktop.
Debugging .NET with WinDbg feels like wizardry, so naturally I want to get better at it.

Load PSSCOR4:

.loadby sos clr
.load C:\Debug\Psscor4\amd64\psscor4.dll

or:

.loadby sos clr
.load C:\Debug\Psscor4\x86\psscor4.dll

or (.NET Core):

# Pick the right runtime version below. How do you know which? I have no idea.
.load C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.2.4\sos.dll
.loadby sos clr

Set symbol path:

srv*C:\Debug\Symbols*https://msdl.microsoft.com/download/symbols

Dump all CLR stacks

~*e!clrstack

# somtimes that doesn't seem to work.
!eestack -ee

Dump locals and arguments

!clrstack -l      # locals
!clrstack -p      # parameters
!clrstack -a      # both

Dump objects

!do 015f3b14                       # Dump an object
!do -nofields 015f3b14             # Dump an object without its fields (useful for strings I guess)
!da 015f3b14                       # Dump an array and the item addresses
!da -details 015f3b14              # Dump an array and the objects inside
!da -details -length 10 015f3b14   # Dump the first 10 items in an array

!dso                               # Dump objects on the current stack

!objsize <address>                 # Show total size of an object and its members

Tasks

https://github.com/Microsoft/vs-threading/blob/master/doc/dumpasync.md

.load C:\debug\vs-threading\x86\AsyncDebugTools.dll

.load C:\debug\vs-threading\x64\AsyncDebugTools.dll

!dumpasync

Finding objects

!name2ee mscorlib.dll System.Threading.Tasks.Task   # Find the method table for a type
!sos.dumpmt <mt>                                    # Display ...something? Not a method table

The heap

!dumpheap -stat                    # Show the heap grouped by object type, ordered by size
!dumpheap [-mt <>] [-type <>] [-strings] [-min] [-max]   # Dump the heap by mt or type

Help

.help
!psscor4.help

Links:

@jasoncable
Copy link

"# somtimes that doesn't seem to work.
!eestack -ee"

I've found this as well. Usually, I've forgotten to have WinDbg run through the dump file. Make sure you do a !verifyheap or !analyze -v before any ! queries.

my cheat sheet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment