windbg .net 程序的死锁检测 常用方法(个人备份笔记)
//死锁检测
.load sosex.dll :> !dlk :> !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 are 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 are on the f-reachable queue as shown below:
// 200b220 代表线程等待,可能是锁,或者 Sleep(), 这个要进一步检查。
0:046> !threads
ThreadCount: 54
UnstartedThread: 0
BackgroundThread: 22
PendingThread: 0
DeadThread: 9
Hosted 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)
20 5 221c 0000000003998d00 1220 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 Ukn
21 6 16d8 00000000044484c0 200b220 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA
22 7 1e54 0000000004460680 200b220 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA
23 8 1308 000000000445fd20 200b220 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA
XXXX 9 00000000044b0510 1019820 Enabled 0000000000000000:0000000000000000 0000000000311a20 0 MTA (Threadpool Worker)
25 a 1e50 00000000044e0e80 200b020 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA
26 b 204c 000000000450b110 200b220 Enabled 0000000000000000:0000000000000000 00000000039980a0 0 MTA
0:000> !ThreadState 3009220
Legal to Join
Background
CLR Owns
In Multi Threaded Apartment
Thread Pool Worker Thread
Interruptible
0:000> !ThreadState 200b220
Legal to Join
Background
CLR Owns
CoInitialized
In Multi Threaded Apartment
Interruptible
0:000> !ThreadState 8009220
Legal to Join
Background
CLR Owns
In Multi Threaded Apartment
Completion Port Thread
// threadstate详细: http://www.parallelfun.com/2012_11_01_archive.html
0:050> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner
57 000000000456f9e8 1 1 0000000004567c30 1c98 46 00000001800b6e90 System.Object
Waiting threads:
141 00000000045702a8 1 1 0000000004567c30 1c98 46 00000001800b6f70 ProtoBufV2.Meta.BasicList
Waiting threads:
-----------------------------
Total 152
CCW 3
RCW 2
ComClassFactory 0
Free 64
// 46号托管线程拥有一个Monitor, MonitorHeld 的计算方法:(MonitorHeld-1)/2 个线程等待 46号线程。
// 例如: 线程91 的 MonitorHeld 是39,则:(39-1)/2=19 表示有19个线程等待线程91
// 这里的MonitorHeld按msdn的解释,拿锁的线程为1,等锁的线程为2; Monitorheld的值是偶数,也说明已经没有线程拿住锁了。
/*
Sync Block 的信息:
通过!syncblk 索引值 可以显示Sync Block的信息,主要有如下信息
Index: Sync Block Table中的Index值
Sync Block: Sync Block的地址
MonitorHeld: numbers of monitor held
Recursion: 该线程获取该sync block的次数
Owning thread info : 总共有三个值,第一个值是线程的数据结构地址,第二个是线程的系统线程ID,第三个值为线程的托管线程ID
SyncBlock Owner:指向拥有该SyncBlock的对象的内存地址,也就是Object的地址
如果有第二个值指这个synblock第二个Held的类型
统计信息:
Total 152 (sync block table的总的sync Lock数量)
CCW 3 (CCW(COM Callable Wrappers)对象拥有的sync block 数量)
RCW 2 (RCW(Runtime Callable Wrappers )对象拥有的sync block 数量)
ComClassFactory 0
Free 64 Sync block table 剩余的空索引的数量
*/
/*
http://blogs.msdn.com/b/oldnewthing/archive/2006/12/12/1266392.aspx
!syncblock 详细解释和 !critsec 使用
http://blogs.msdn.com/b/tess/archive/2006/01/09/a-hang-scenario-locks-and-critical-sections.aspx
*/
0:044> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner
2193 000000000598fe18 5 1 000000000a4650e0 3038 110 00000001bff69770 System.Object
Waiting 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 120 122 123 124 128 129 132 133 134 135 136
2910 000000000577bae8 3 1 000000000a5821b0 134bc 78 000000019fc88170 System.Object
Waiting threads: 64
-----------------------------
Total 3256
CCW 3
RCW 2
ComClassFactory 1
Free 2992
//如果知道临界区的地址,可以用一下命令,如果不知道地址,可以用!locks
0:044> !critsec 000000011fc6aa30 DebugInfo for CritSec at 000000011fc6aa30 does not point back to the critical section
NOT an initialized critical section. CritSec +1fc6aa30 at 000000011fc6aa30
WaiterWoken Yes
LockCount -1
RecursionCount 0
OwningThread 0
EntryCount fef56b35
ContentionCount 2000007
*** Locked
// !locks 的输出
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff541979(v=vs.85).aspx
0:105> !locks CritSec +1192340 at 0000000001192340
WaiterWoken No
LockCount 0
RecursionCount 1
OwningThread bad0
EntryCount 0
ContentionCount 46a
*** Locked
//直接切换到进程上去:
0:014> ~~[bad0]s
//或者用 ~ 列出所有线程,然后切过去
//参考: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: 000007ff`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 Unfrozen
0:014> ~3s
//
0:046> .shell -i - -ci "~*e !clrstack" FIND /i "Monitor.Enter"
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
0:046> .shell -i - -ci "~*e !clrstack" FIND /i "Monitor.TryEnter"
.shell: Process exited
0: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
// 有时候会发现无锁定同步快或死锁,还可以用!mlocks 看看
0:164> !dlk
Examining 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> !mlocks
Examining 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 116 0x1e8 thinlock 000000014036a2b0 (recursion:0)
0xab 182 0x268 thinlock 00000001c0724188 (recursion:0)
0xa4 177 0x14cc RWLockSlim 000000013ff0a358 Writer 0:164> !rwlock 000000013ff0a358
WriteLockOwnerThread: 0xa4
UpgradableReadLockOwnerThread: None
ReaderCount: 0
ReaderThreadIds: None
WaitingReaderCount: 204
WaitingReaderThreadIds: 0x9,0xa,0x11,0x12,0x13,0x14,0x15,0x16,0x17
WaitingWriterCount: 204
WaitingWriterThreadIds: 0x8,0xf,0x1d,0x21,0x24,0x2b,0x2f,0x30,
WaitingUpgradableReaderCount: 0
WaitingUpgradableReaderThreadIds: None
WaitingWriterUpgradeCount: 0
WaitingWriterUpgradeThreadIds: None ClrThread DbgThread OsThread LockType Lock LockLevel
------------------------------------------------------------------------------
0x15 19 0x15e8 thinlock 00000000010b6130 (recursion:0)
0x16c 226 0x1a1c SyncBlock 0000000000c735a8
// shell 命令:
.shell -ci "!mlocks -d" find "Writer"
参考:
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
windbg .net 程序的死锁检测 常用方法(个人备份笔记)的更多相关文章
- linux死锁检测的一种思路【转】
转自:http://www.cnblogs.com/mumuxinfei/p/4365697.html 前言: 上一篇博文讲述了pstack的使用和原理. 和jstack一样, pstack能获取进 ...
- linux死锁检测的一种思路
前言: 上一篇博文讲述了pstack的使用和原理. 和jstack一样, pstack能获取进程的线程堆栈快照, 方便检验和性能评估. 但jstack功能更加的强大, 它能对潜在的死锁予以提示, 而p ...
- UNIX环境高级编程——记录上锁(fcntl函数)以及死锁检测
一.记录锁 record locking 功能:当一个进程正在读或修改文件的某个部分时,它可以阻止其它进程修改同一文件区. 字节范围锁 byte-range locking 二.历史 flock函数, ...
- LiteOS:SpinLock自旋锁及LockDep死锁检测
摘要:除了多核的自旋锁机制,本文会介绍下LiteOS 5.0引入的LockDep死锁检测特性. 2020年12月发布的LiteOS 5.0推出了全新的内核,支持SMP多核调度功能.想学习SMP多核调度 ...
- halcon——缺陷检测常用方法总结(测量拟合)
引言 机器视觉中缺陷检测分为一下几种: blob分析+特征 模板匹配(定位)+差分:halcon--缺陷检测常用方法总结(模板匹配(定位)+差分) - 唯有自己强大 - 博客园 (cnblogs.co ...
- matlab练习程序(SUSAN检测)
matlab练习程序(SUSAN检测) SUSAN算子既可以检测角点也可以检测边缘,不过角点似乎比不过harris,边缘似乎比不过Canny.不过思想还是有点意思的. 主要思想就是:首先做一个和原图像 ...
- 为什么MySQL死锁检测会严重降低TPS
在大量的客户端,更新数据表的同一行时,会造成数据库的吞吐量大幅降低. 很多数据库的前辈和同行分别通过实验和源码的方法,定位到了罪魁祸首----MySQL死锁检测 实验方式:http://blog.cs ...
- 14.3.5.2 Deadlock Detection and Rollback 死锁检测和回滚:
14.3.5.2 Deadlock Detection and Rollback 死锁检测和回滚: InnoDB 自动检查四艘,回滚一个事务或者事务来打破死锁. InnoDB 试图选择小的事务来回滚, ...
- Linux死锁检测-Lockdep
关键词:LockDep.spinlock.mutex. lockdep是内核提供协助发现死锁问题的功能. 本文首先介绍何为lockdep,然后如何在内核使能lockdep,并简单分析内核lockdep ...
随机推荐
- html中文字溢出处理(text-overflow)
文字溢出处理有两种方式: 一.css overflow:hidden; white-space: nowrap; text-overflow: ellips ...
- SQLServer 的存储过程与java交互
一. 存储过程简介 Sql Server的存储过程是一个被命名的存储在服务器上的Transacation-Sql语句集合,是封装重复性工作的一种方法,它支持用户声明的变量.条件执行和其他强大的编程 ...
- 如何在Cordova Android 7.0.0 以下版本集成最新插件 极光插件为例
前提 Cordova Android 7.0.0开始改变了项目安卓平台的架构.新建一个空项目分别添加Android 6.4.0 和 Android 7.0.0平台: cordova platform ...
- 微信小程序ofo小黄车+thinkphp5.0打造全栈应用
原文地址:https://www.imooc.com/article/20310 ofo至今还没有微信小程序(很费解),每次用ofo都得去支付宝,很不方便,我用微信用的比较多,无意间在简书上面看到某人 ...
- 通过UIColor转换为UIImage
+ (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); ...
- 使用go写一个简单的exe文件
工作需要一个小工具给分析师用,原先打算写一个脚本的,但是呢我又不会用python,要写的话只能用java来实现(打包成可执行jar,使用java -jar 的命令来执行,当然得安装jdk).这种命令行 ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- C. Edgy Trees Codeforces Round #548 (Div. 2) 【连通块】
一.题面 here 二.分析 这题刚开始没读懂题意,后来明白了,原来就是一个数连通块里点数的问题.首先在建图的时候,只考虑红色路径上的点.为什么呢,因为为了不走红色的快,那么我们可以反着想只走红色的路 ...
- stark - 4 ⇲ 视图函数
✘ list_view 处理表格(默认是显示表结构的所有字段) 1 list_display = self.get_list_display() # 4.1处理表头 header_list = [] ...
- service worker --- offline APP
相关介绍: https://developer.mozilla.org/zh-CN/docs/Web/API/Service_Worker_API/Using_Service_Workers