Please explain !SyncBlk the windbg command
Asked Answered
P

1

5

Firstly, is there a command for getting help and parameters for each sos command in windbg?

Secondly, I'd like to understand !syncblk output

Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
  201 05b9493c          979         1 05bc1040   bcc  45   022f3490 System.Collections.ArrayList
 2875 05b4c914            1         1 17b99e10  1af8 290   024862d8 MyClass
 2945 05b4b66c            1         1 17d1a290  12c0 752   02482940 MyClass

MonitorHeld shows # of monitor held by the synblk. 1 for write and 2 for read, but what does the rest of column means?

Say I have a C# code

MyClass MyObj;
MyObj = new MyClass();

Now if I do

lock (MyObj)
{
}

Will the syncblk owner column show "MyClass" ? Similarly when I run this !SyncBlk command, what exactly is it showing me? Is it showing me the number of lock() and Monitor.Enter and Mutex() and other locking mechanisms?

Persia answered 8/6, 2012 at 15:22 Comment(0)
S
7

To get help for the SOS commands type !help or !sos.help. To get help on specific commands type !help <command>. The help texts for SOS are also available online. The online version gives you an overview of the command. For additional details use !help syncblk.

The output of !syncblk shows you the thread id (header #1 in the output below), the object and the type of the object used to lock (header #2).

                                      +-------#1-------+  +-----#2------+
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
  201 05b9493c          979         1 05bc1040   bcc  45   022f3490 System.Collections.ArrayList
 2875 05b4c914            1         1 17b99e10  1af8 290   024862d8 MyClass
 2945 05b4b66c            1         1 17d1a290  12c0 752   02482940 MyClass

1) First value is thread object, second is native thread id and last is WinDbg thread id.

2) First value is object used to lock on and second value is the type of this object.

!syncblk only covers the internal .NET locks, so Mutex (which is a kernel object) is not covered here.

In your example the thread id of the code running the lock statement will show up along with the address MyObj points to and the type MyClass.

Scevor answered 8/6, 2012 at 15:59 Comment(5)
Can you please tell which column shows which value? there are 2 syncblock columns.Persia
I've updated my answer to clarify. Please let me know if it's still not clear.Scevor
Thanks, and what do columns 1,2, and 4 mean? WinDbgId is used to drill down a thread? something like ~45e!clrstack? Is there a way to know the line of code where a given syncblock line is holding/waiting for a thread?Persia
A blocking thread will usually have Monitor.Enter on top of the call stack. Use !dso to dump references on the stack. Correlate this with the output of !syncblk.Scevor
thanks Brian, I have a related thread going on, if you get a chance take a look #10939785Persia

© 2022 - 2024 — McMap. All rights reserved.