Common methods for deadlock detection of WinDbg. NET programs (personal backup notes)

Source: Internet
Author: User
Tags wrappers

Deadlock detection

. Load Sosex.dll 0:004>! Dlk 0:>!mk-a

The MK command displays a call stack of the currently selected thread (including both managed and unmanaged frames).
The command has now been extended to support the-a switch which outputs both the local variables as well as parameters
(Combination of-l and-p switches):

0:003>!finq

  

The FINQ command (finalization queue) lists all the objects that is on the finalization queue. An example is shown below:

0:003>!frq-stat

  


The Frq command (f-reachable queue) on the other hand, lists all objects that is on the f-reachable queue as shown below:


200B220 is waiting on behalf of the thread, possibly a lock, or Sleep (), which should be checked further.

0:046>!threadsthreadcount:54unstartedthread:0backgroundthread:22pendingthread:0deadthread:9hosted       Runtime:no Preemptive Lock   ID OSID Threadobj State GC GC Alloc Context Domain Count APT Exception   9 1 1644 0000000001412de0 8220 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 Ukn 17 2   528 000000000141f5d0 b220 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 MTA (Finalizer) 19 4 181c 00000000039853e0 100a220 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 MTA (Threadpool Worker   ) 5 221c 0000000003998d00 1220 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 Ukn 21 6 16d8 00000000044484c0 200b220 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA 7 1e54 000 0000004460680 200b220Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA 8 1308 000000000445fd20 200b220 enabled 0 000000000000000:0000000000000000 00000000039980a0 0 mtaxxxx 9 00000000044b0510 1019820 Enabled 00000000000 00000:0000000000000000 0000000000311a20 0 MTA (Threadpool Worker) 1e50 00000000044e0e80 200b020 Enabled 0 000000000000000:0000000000000000 00000000039980a0 0 MTA 204c 000000000450b110 200b220 Enabled 00000000000 00000:0000000000000000 00000000039980a0 0 MTA

  

0:000>! ThreadState 3009220    Legal to Join    Background    CLR owns in    Multi threaded Apartment    Thread Pool Worker Thread    interruptible0:000>! ThreadState 200b220    Legal to Join    Background    CLR owns    coinitialized in    Multi threaded apartment< C11/>interruptible0:000>! ThreadState 8009220     Legal to Join    Background    CLR owns in    Multi threaded Apartment    completion Port Thread

  

ThreadState Details: http://www.parallelfun.com/2012_11_01_archive.html



0:050>!syncblkindex         syncblock monitorheld recursion owning Thread Info          syncblock Owner   57 000000000456f9e8            1         1 0000000004567c30 1c98   00000001800b6e90 system.objectwaiting Threads:  141 00000000045702a8            1         1 0000000004567c30 1c98   00000001800b6f70 ProtoBufV2.Meta.BasicListWaiting Threads:-----------------------------Total           152CCW             3RCW             2ComClassFactory 0Free            64

  



Number 46th managed threads have a monitor, Monitorheld calculation method: (MonitorHeld-1)/2 threads waiting for line Line 46.
For example: Thread 91 of Monitorheld is 39, then: (39-1)/2=19 means 19 threads waiting for thread 91
Here's Monitorheld as explained by MSDN, the thread holding the lock is 1, the thread of the lock is 2, the value of Monitorheld is even, and it means that no thread has held the lock.

/*
Sync Block Information:
The!SYNCBLK index value can show the sync block information, mainly the following information
Index:sync the index value in the Block table
The address of Sync Block:sync Block
Monitorheld:numbers of Monitor held
Recursion: The number of times the thread gets the sync block
Owning thread Info: A total of three values, the first value is the thread's data structure address, the second is the thread's system thread ID, and the third value is the thread's managed thread ID
SyncBlock owner: The address of the memory that points to the object that owns the SyncBlock
If there is a second value that refers to the type of the second held of the Synblock
Statistical information:
Total (number of sync Lock for sync block table)
CCW 3 (the number of sync blocks owned by a CCW (COM callable Wrappers) object)
RCW 2 (RCW (Runtime callable Wrappers) object has the number of sync blocks)
Comclassfactory 0
Free Sync block table number of empty indexes remaining

*/


/*

Http://blogs.msdn.com/b/oldnewthing/archive/2006/12/12/1266392.aspx

!syncblock detailed explanation and!critsec use
Http://blogs.msdn.com/b/tess/archive/2006/01/09/a-hang-scenario-locks-and-critical-sections.aspx
*/

0:044>!syncblkindex         syncblock monitorheld recursion owning Thread Info          syncblock Owner 2193 000000000598fe18            5         1 000000000a4650e0 3038   00000001bff69770 system.objectwaiting threads:90 121 2616 000000000577db08          133         0 0000000000000000     none    000000011fc6aa30 system.runtimetype+ Runtimetypecache+memberinfocache ' 1[[system.reflection.runtimemethodinfo, mscorlib]]waiting threads:39 40 42 48 49 52 53 58 60 63 65 67 69 73 75 76 77 79 81 82 83 85 86 87 88 93 94 95 97 99 100 104 105 107 108 109 110 111 112 114 115 117 12 0 122 123 124 129, 133 134 135 136 2910 000000000577bae8            3         1 000000000a5821b0 134bc   000000019 fc88170 system.objectwaiting threads:64-----------------------------Total           3256CCW             3RCW             2ComClassFactory 1Free            2992

  

If you know the address of the critical section, you can use the command, if you do not know the address, you can use!locks

0:044>!critsec 000000011fc6aa30debuginfo for critsec @ 000000011fc6aa30 does not point back to the critical Sectionno T an initialized critical section. Critsec +1fc6aa30 at 000000011fc6aa30waiterwoken        yeslockcount          -1recursioncount     0OwningThread       0EntryCount         fef56b35contentioncount    2000007*** Locked

  


Output of the!locks
http://msdn.microsoft.com/en-us/library/windows/hardware/ff541979 (v=vs.85). aspx

0:105>!lockscritsec +1192340 at 0000000001192340WaiterWoken        nolockcount          0RecursionCount     1OwningThread       bad0entrycount         0ContentionCount    46a*** Locked

  

Switch directly to the process:

0:014> ~~[bad0]s

  

or use ~ to list all the threads and then cut through
Reference: Http://blogs.msdn.com/b/tess/archive/2006/01/09/a-hang-scenario-locks-and-critical-sections.aspx

0:105> ~#  0  Id:d9e0.a700 suspend:0 teb:000007ff ' fffde000 unfrozen   1  id:d9e0.18bac suspend:0 teb:0 00007ff ' fffdc000 unfrozen   2  Id:d9e0.bfa0 suspend:0 teb:000007ff ' fffd7000 unfrozen   3  Id:d9e0.bad0 suspend:0 teb:000007ff ' fffd3000 unfrozen   4  id:d9e0.16364 suspend:0 teb:000007ff ' fff9e000 unfrozen0:014> ~ 3s  

  






//

 0:046>. Shell-i--ci "~*e!clrstack" find/i "Monitor.Enter" 0000000002f7d428 0000000076f6171a [helpermethodframe:0 000000002F7D428] System.Threading.Monitor.Enter (System.Object) 00000000049ad3e8 0000000076f6171a [ Helpermethodframe:00000000049ad3e8] System.Threading.Monitor.Enter (System.Object) 0000000016a6d898 000007FEF76500B9 [helpermethodframe:0000000016a6d898] System.Threading.Monitor.Enter (System.Object) 0000000016b6e8b8 000007fef76500b7 [Helpermethodframe:0000000016b6e8b8] System.Threading.Monitor.Enter ( System.Object). Shell:process exited0:046>. Shell-i--ci "~*e!clrstack" find/i "Monitor.TryEnter". Shell:process E xited0:046>. Shell-i--ci "~*e!clrstack" find/i "Monitor" 000000000433eae8 0000000076f6186a [helpermethodframe_1obj : 000000000433eae8] System.Threading.Monitor.ObjWait (Boolean, Int32, System.Object) 000000000504e3b8 0000000076f6186a [Helpermethodframe_1obj:000000000504e3b8] System.Threading.Monitor.ObjWait (Boolean, Int32, System.Object) 000000000504E4e0 000007fef663d2ae System.Threading.Monitor.Wait (System.Object) 0000000002f7d428 0000000076f6171a [ HELPERMETHODFRAME:0000000002F7D428] System.Threading.Monitor.Enter (System.Object) 00000000049ad3e8 0000000076f6171a [Helpermethodframe:00000000049ad3e8] System.Threading.Monitor.Enter (System.Object) 0000000016a6d898 000007fef76500b9 [helpermethodframe:0000000016a6d898] System.Threading.Monitor.Enter ( System.Object) 0000000016b6e8b8 000007fef76500b7 [HELPERMETHODFRAME:0000000016B6E8B8]  System.Threading.Monitor.Enter (System.Object). Shell:process exited

  




Sometimes you will find no lock sync fast or deadlock, you can also use!mlocks to see

0:164>!dlkexamining syncblocks ... Scanning for ReaderWriterLock instances ... Scanning for holders of ReaderWriterLock locks ... Scanning for ReaderWriterLockSlim instances ... Scanning for holders of ReaderWriterLockSlim locks ... Examining Criticalsections ... Scanning for threads waiting on syncblocks ... Scanning for threads waiting on ReaderWriterLock locks ... Scanning for threads waiting on Readerwriterlocksslim locks ... Scanning for threads waiting on criticalsections ... No deadlocks detected.0:164>!mlocksexamining syncblocks ... Scanning for ReaderWriterLock instances ... Scanning for holders of ReaderWriterLock locks ... Scanning for ReaderWriterLockSlim instances ... Scanning for holders of ReaderWriterLockSlim locks ... Examining Criticalsections ... Clrthread dbgthread osthread LockType Lock locklevel-------------------------------------------------      -----------------------------0x67 0x1e8 thinlock 000000014036a2b0 (recursion:0) 0xAB 182  0x268 thinlock 00000001c0724188 (recursion:0) 0xa4 177 0x14cc Rwlockslim 000000013ff0a358 Writer 0:164>!rwlock 000000013ff0a358writelockownerthread:0xa4upgradablereadlockownerthread : Nonereadercount:0readerthreadids:nonewaitingreadercount:204wai Tingreaderthreadids:0x9,0xa,0x11,0x12,0x13,0x14,0x15,0x16,0x17waitingwritercount:204waitingwrite Rthreadids:0x8,0xf,0x1d,0x21,0x24,0x2b,0x2f,0x30,waitingupgradablereadercount:0waitingupgradablereaderthre Adids:nonewaitingwriterupgradecount:0waitingwriterupgradethreadids:none clrthread DbgThread OsThread Lo       Cktype Lock locklevel------------------------------------------------------------------------------0x15 0x15e8 thinlock 00000000010b6130 (recursion:0) 0x16c 226 0x1a1c syncblock 000000  0000c735a8

  


Shell command:

. Shell-ci "!mlocks-d" Find "Writer"

  


















Reference:
Http://weblogs.thinktecture.com/ingo/2006/08/who-is-blocking-that-mutex---fun-with-windbg-cdb-and-kd.html

Http://blogs.msdn.com/b/tess/archive/2006/01/09/a-hang-scenario-locks-and-critical-sections.aspx

Http://hi.baidu.com/ju_feng/item/e22f06974dafe530326eeb64

Http://stackoverflow.com/questions/22037581/determining-which-method-is-holding-a-readerwriterlockslim-writelock

Common methods for deadlock detection of WinDbg. NET programs (personal backup notes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.