10

When I issued clrstack command, I got the following output. It is the callstack of a blocking thread which owns a deadlock and results in a deadlock. Is that its exact purpose? Does it have any other purposes (without any parameters). Where can I get more information?

!clrstack
OS Thread Id: 0x1b2c (6956)
ESP       EIP     
0012f370 7c90e514 [HelperMethodFrame: 0012f370] System.Threading.Thread.SleepInternal(Int32)
0012f3c4 79299275 System.Threading.Thread.Sleep(Int32)
0012f3c8 00e0030f testlock.LockTest.Test()
0012f420 00e00146 testlock.Program.Main(System.String[])
0012f69c 79e71b4c [GCFrame: 0012f69c] 
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
Maanu
  • 5,093
  • 11
  • 59
  • 82
  • As below answered, this command is simply used to display managed call stack for current thread context. So if you are debugging deadlock issues, you should try to combine it with other commands. – Lex Li Aug 21 '10 at 09:57
  • This doesn't look like a deadlock to me. The stack shows a call to Sleep. For a deadlock you should expect to see a Wait call on the stack. – Brian Rasmussen Aug 25 '10 at 10:12

3 Answers3

23

Use sosex by Steve Johnson. This has a command to detect deadlocks for you.

Download the extension from the link and load it, eg

.load D:\sosex_32\sosex.dll

then issue

!dlk

example output (taken from steve's site)

0:010> !dlk Deadlock detected: CLR thread 4 holds sync block 00000000024c6970 OBJ:000000007fff0f80[System.String] STRVAL=SYNC1 waits sync block 00000000024c6928 OBJ:000000007fff0fa8[System.String] STRVAL=SYNC2 CLR thread 5 holds sync block 00000000024c6928 OBJ:000000007fff0fa8[System.String] STRVAL=SYNC2 waits sync block 00000000024c6970 OBJ:000000007fff0f80[System.String] STRVAL=SYNC1 CLR Thread 4 is waiting at ConsoleTestApp.ConsoleTestApp.MonitorDeadlockThreadProc()+0xa4(IL) [C:\dev\ConsoleTestApp\ConsoleTestApp.cs, line 195] CLR Thread 5 is waiting at ConsoleTestApp.ConsoleTestApp.MonitorDeadlockThreadProc()+0xa4(IL) [C:\dev\ConsoleTestApp\ConsoleTestApp.cs, line 195]

See also this link for a walkthrough

Liam
  • 27,717
  • 28
  • 128
  • 190
wal
  • 17,409
  • 8
  • 74
  • 109
18

How to: Debug Deadlocks Using Windbg?

WinDbg / SOS Cheat Sheet

CLRStack [-a] [-l] [-p] [-n] Provides a stack trace of managed code only.

  • The -p option shows arguments to the managed function.

  • The -l option shows information on local variables in a frame. The SOS Debugging Extension cannot retrieve local names, so the output for local names is in the format = .

  • The -a(all) option is a shortcut for -l and -pcombined.

  • The -n option disables the display of source file names and line numbers. If the debugger has the option SYMOPT_LOAD_LINES specified, SOS will look up the symbols for every managed frame and if successful will display the corresponding source file name and line number. The -n (No line numbers) parameter can be specified to disable this behavior.

The SOS Debugging Extension does not display transition frames on x64 and IA-64-based platforms.

Update: (Thanks to @Liran): To see the call stacks for all the threads in your application, run the following command:

 ~*e!clrstack 

(which basically means, "iterate over all of the threads, and execute the command '!clrstack' on every one of them").

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • 1
    Thanks for the reply.. My application has 2 threads. But the !clrstack command displayed the callstack of only one thread. I have gone through the documents before posting the question.. – Maanu Aug 21 '10 at 06:12
  • 1
    @Maanu, this command is issued per-thread. In order to issue it for all the threads in your application, you will need to use the following command: `~*e!clrstack` (which basically means, "iterate over all of the threads, and execute the command '!clrstack' on every one of them"). – Liran Aug 22 '10 at 05:26
1

Tess has blogged lots of useful information about windbg. Here is one post that might help.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Russel Yang
  • 2,633
  • 3
  • 21
  • 18