If I have following stack trace where I see that a thread is waiting on certain lock. How can I get information about the object this thread is waiting for? I was thinking that I should be able to SyncBlk command but seem like it can only give information about the locks and its owner threads.
0:000> !CLRStack
OS Thread Id: 0x25a8 (0)
ESP EIP
001af038 77455e74 [GCFrame: 001af038]
001af108 77455e74 [HelperMethodFrame_1OBJ: 001af108] System.Threading.Monitor.Enter(System.Object)
001af160 00290192 ConsoleApplication1.MyClass.Main(System.String[])
001af3c0 70fc1b4c [GCFrame: 001af3c0]
To find out which object the thread is waiting for, you will have to do some debugging.
First, start with the stack trace that you have:
Find out the frame that is calling Monitor.Enter(). In this case it is MyClass::Main(string [] args)
Now you need to disassemble the caller. Use !sos.u [eip] to do that.
Note the call site. At this point you have the following debug spew:
00d1016c 8b0dfc1e2e02 mov ecx,dword ptr ds:[22E1EFCh] (Object: SyncBlock) 00d10172 e8ae281679 call mscorwks!JIT_MonEnterWorker (79e72a25) >>> 00d10177 90 nop 00d10178 8b0d34202e02 mov ecx,dword ptr ds:[22E2034h] ("Releasing lock") 00d1017e e88538a878 call mscorlib_ni+0x6d3a08 (79793a08) (System.Console.WriteLine(System.String), mdToken: 060007c8) 00d10183 90 nopJust before the call to JitMon::Enter() you see the address of the object being moved into the ECX register. This is the object your thread is waiting on.