Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain !SyncBlk the windbg command

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?

like image 431
bsobaid Avatar asked Jun 08 '12 15:06

bsobaid


1 Answers

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.

like image 198
Brian Rasmussen Avatar answered Nov 15 '22 00:11

Brian Rasmussen