Skip to content

Instantly share code, notes, and snippets.

@vivainio
Last active August 19, 2021 12:29
Show Gist options
  • Save vivainio/25462dc101ef3fa576f872c3dd1082f3 to your computer and use it in GitHub Desktop.
Save vivainio/25462dc101ef3fa576f872c3dd1082f3 to your computer and use it in GitHub Desktop.

Debugging c# dump with windbg

Applies to .NET 4.7 applications.

Right click on dmp, "open with" -> windbg.

Run command:

.cordll -ve -u -l

(that automatically loads SOS extension)

To get list of threads, with nice stack traces (that you can copy paste to your friends):

~*e!clrstack 

(I'm not kidding, that's the command).

A blocking/deadlocked thread may look like this:

OS Thread Id: 0x33ec (359)
        Child SP               IP Call Site
000000c7eb17da20 00007ffd11b267c4 [GCFrame: 000000c7eb17da20] 
000000c7eb17db48 00007ffd11b267c4 [HelperMethodFrame_1OBJ: 000000c7eb17db48] System.Threading.Monitor.ObjWait(Boolean, Int32, System.Object)
000000c7eb17dc60 00007ffc9397ce48 System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken)
000000c7eb17dcf0 00007ffc97210e9b System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken)
000000c7eb17dd60 00007ffc97210d01 System.Threading.Tasks.Task.InternalWait(Int32, System.Threading.CancellationToken)
000000c7eb17de30 00007ffc972dea6f System.Threading.Tasks.Task.Wait(Int32, System.Threading.CancellationToken)
...

You can switch to thread 359 by typing:

~359s

Now that the thread is active, you can run commands like:

  • "!clrstack" to print the stack again
  • "!clrstack -a" for the same, but with some param variables (probably broken though)
  • "!dso" to 'dump stack objects', i.e. see objects that have been pushed to stack. You can click on addresses to drill deeper into objects etc.

Other commands:

  • "!DumpHeap -stat" for heap statistics (sorted by size used)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment