Windbg !cs 临界区死锁
总结:
Win7中,CS初始化时,nLockCout为-1,RecursionCount为0; RecursionCount是own thread每调用一次Enter就递增一次,但只有第一次Enter的时候,LockCount才减1
XP中,cs初始化时,nLockCout为-1,RecursionCount为0;每Enter一次,两个数都加1
总的来说,xp和win7的区别只体现在nLockCount的变化的方向及变化的次数上!
0:000>!cs
-----------------------------------------
DebugInfo = 0x002357b0
Critical section = 0x07a93f30 (+0x7A93F30)
NOT LOCKED
LockSemaphore = 0x0
SpinCount = 0x00000000
-----------------------------------------
DebugInfo = 0x002357d8
Critical section = 0x076fdcf4 (+0x76FDCF4)
NOT LOCKED
LockSemaphore = 0x0
SpinCount = 0x00000000
-----------------------------------------
DebugInfo = 0x00235800
Critical section = 0x076fdd10 (+0x76FDD10)
NOT LOCKED
LockSemaphore = 0x0
SpinCount = 0x00000000
-----------------------------------------
-----------------------------------------
DebugInfo = 0x0018d708
Critical section = 0x01d0be14 (+0x1D0BE14)
LOCKED
LockCount = 0x0
OwningThread = 0x00000744
RecursionCount = 0x1
LockSemaphore = 0x0
SpinCount = 0x00000400
-----------------------------------------
-----------------------------------------
DebugInfo = 0x0020f030
Critical section = 0x02b29750 (+0x2B29750)
LOCKED
LockCount = 0x1
OwningThread = 0x0000053c
RecursionCount = 0x1
LockSemaphore = 0x4B0
SpinCount = 0x00000000
-----------------------------------------
-----------------------------------------
DebugInfo = 0x0020f058
Critical section = 0x02b29770 (+0x2B29770)
LOCKED
LockCount = 0xFFFFFFFE
OwningThread = 0x00000000
RecursionCount = 0xFFFFFFFE
LockSemaphore = 0x4AC
SpinCount = 0x00000000
-----------------------------------------
0:000> dt 0x01d0be14 ntdll!_RTL_CRITICAL_SECTION
+0x000 DebugInfo : 0x0018d708 _RTL_CRITICAL_SECTION_DEBUG
+0x004 LockCount : 0n0
+0x008 RecursionCount : 0n1
+0x00c OwningThread : 0x00000744 Void
+0x010 LockSemaphore : (null)
+0x014 SpinCount : 0x400
0:000> dt 0x02b29750 ntdll!_RTL_CRITICAL_SECTION
+0x000 DebugInfo : 0x0020f030 _RTL_CRITICAL_SECTION_DEBUG
+0x004 LockCount : 0n1
+0x008 RecursionCount : 0n1
+0x00c OwningThread : 0x0000053c Void
+0x010 LockSemaphore : 0x000004b0 Void
+0x014 SpinCount : 0
0:000> dt 0x02b29770 ntdll!_RTL_CRITICAL_SECTION
+0x000 DebugInfo : 0x0020f058 _RTL_CRITICAL_SECTION_DEBUG
+0x004 LockCount : 0n-2
+0x008 RecursionCount : 0n-2
+0x00c OwningThread : (null)
+0x010 LockSemaphore : 0x000004ac Void
+0x014 SpinCount : 0
0:000> ~~[744]
. 0 Id: 404.744 Suspend: 1 Teb: 7ffdf000 Unfrozen
Start: FTNN!wWinMainCRTStartup (0044ea4b)
Priority: 0 Priority class: 32 Affinity: 3
0:000> ~~[53c]
8 Id: 404.53c Suspend: 1 Teb: 7ffd6000 Unfrozen
Start: OMBase!OMThread::CreateThread_Inner (10026530)
Priority: 0 Priority class: 32 Affinity: 3
0:000> dt 0x076fdd10 ntdll!_RTL_CRITICAL_SECTION
+0x000 DebugInfo : 0x00235800 _RTL_CRITICAL_SECTION_DEBUG
+0x004 LockCount : 0n-1
+0x008 RecursionCount : 0n0
+0x00c OwningThread : (null)
+0x010 LockSemaphore : (null)
+0x014 SpinCount : 0
0:000> dt 0x07a93f30 ntdll!_RTL_CRITICAL_SECTION
+0x000 DebugInfo : 0x002357b0 _RTL_CRITICAL_SECTION_DEBUG
+0x004 LockCount : 0n-1
+0x008 RecursionCount : 0n0
+0x00c OwningThread : (null)
+0x010 LockSemaphore : (null)
+0x014 SpinCount : 0
//=======================================================================
//可以用一条命令简单输出
//可以看到下面三个锁住的CS中,前两个分别属于0号及8号线程, 第3个没有拥有线程即永久锁住了,
//再看0号及8号线程堆栈都在等临界区02b29b88,这正是第3个CS区
//=======================================================================
0:019> !cs -s -l
-----------------------------------------
DebugInfo = 0x0018d710
Critical section = 0x01d0be14 (+0x1D0BE14)
LOCKED
LockCount = 0x0
OwningThread = 0x0000093c
RecursionCount = 0x1
LockSemaphore = 0x0
SpinCount = 0x00000400
ntdll!RtlpStackTraceDataBase is NULL. Probably the stack traces are not enabled.
-----------------------------------------
DebugInfo = 0x001a3f68
Critical section = 0x02b29b88 (+0x2B29B88)
LOCKED
LockCount = 0x1
OwningThread = 0x00000864
RecursionCount = 0x1
LockSemaphore = 0x64C
SpinCount = 0x00000000
ntdll!RtlpStackTraceDataBase is NULL. Probably the stack traces are not enabled.
-----------------------------------------
DebugInfo = 0x001a3f90
Critical section = 0x02b29ba8 (+0x2B29BA8)
LOCKED
LockCount = 0xFFFFFFFE
OwningThread = 0x00000000
RecursionCount = 0xFFFFFFFE
LockSemaphore = 0x4B8
SpinCount = 0x00000000
ntdll!RtlpStackTraceDataBase is NULL. Probably the stack traces are not enabled.
0:019> ~~[93c]
0 Id: 598.93c Suspend: 1 Teb: 7ffdf000 Unfrozen
Start: FTNN!wWinMainCRTStartup (0044ea4b)
Priority: 0 Priority class: 32 Affinity: 3
0:019> ~~[864]
8 Id: 598.864 Suspend: 1 Teb: 7ffd6000 Unfrozen
Start: kernel32!BaseThreadStartThunk (7c8106e9)
Priority: 0 Priority class: 32 Affinity: 3
0:019> ~0 kbn
# ChildEBP RetAddr Args to Child
00 0012e45c 7c92df3c 7c93b22b 0000064c 00000000 ntdll!KiFastSystemCallRet
01 0012e460 7c93b22b 0000064c 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
02 0012e4e8 7c921046 00b29b88 006e0e32 02b29b88 ntdll!RtlpWaitForCriticalSection+0x132
03 0012e4f0 006e0e32 02b29b88 19021feb 0012e590 ntdll!RtlEnterCriticalSection+0x46
04 0012e558 006a8f69 0012e590 1910faeb 006a8dfb CtrlCenter!gloox::ConnectionTCPBase::send+0x42 [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\connectiontcpbase.cpp @ 125]
05 0012e564 006a8dfb 19021f9b 02b27b10 02b32538 CtrlCenter!gloox::ClientBase::send+0x59 [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\clientbase.cpp @ 1097]
06 0012e604 006a8bac 02b27b10 02b32538 00000001 CtrlCenter!gloox::ClientBase::send+0x5b [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\clientbase.cpp @ 1060]
07 0012e61c 006a8b44 19021cc3 02b474e4 02b3a3c8 CtrlCenter!gloox::ClientBase::send+0x4c [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\clientbase.cpp @ 1014]
08 0012e668 006b9297 0012e758 01d0b978 00000008 CtrlCenter!gloox::ClientBase::send+0xe4 [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\clientbase.cpp @ 1005]
09 0012e91c 006fe25c 0012e990 190213c7 00000000 CtrlCenter!gloox::RosterManager::GetSimple+0x137 [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\rostermanager.cpp @ 923]
0a 0012ead8 006fa44b 0001adb2 00000000 00000000 CtrlCenter!CC_IM_Roster::GetUserSimpleInfo+0x32c [d:\dailybuild\ftnn_git\ftnn\ctrlcenter\ctrlcenter\cc_im_roster.cpp @ 723]
0b 0012eaec 03f86dcd 0001adb2 00000000 00000000 CtrlCenter!ICC_IM::GetUserSimpleInfo+0x2b [d:\dailybuild\ftnn_git\ftnn\ctrlcenter\ctrlcenter\icc_im.cpp @ 148]
0c 0012eb14 03f86bcd 0001adb2 00000000 4a6a23fa QTUIAssem!CChatUserHeaderData::DoTryRosterSimpleInfoRequest+0x5d [d:\dailybuild\ftnn_git\ftnn\qtuiassem\sns\chatuserheaderdata.cpp @ 162]
0d 0012f394 03f946c9 0418dbdc 0001adb2 00000000 QTUIAssem!CChatUserHeaderData::GetUserHeadImg+0x1ed [d:\dailybuild\ftnn_git\ftnn\qtuiassem\sns\chatuserheaderdata.cpp @ 102]
0:019> ~8 kbn
# ChildEBP RetAddr Args to Child
00 02b0f84c 7c92df3c 7c93b22b 000004b8 00000000 ntdll!KiFastSystemCallRet
01 02b0f850 7c93b22b 000004b8 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
02 02b0f8d8 7c921046 00b29ba8 006cf60e 02b29ba8 ntdll!RtlpWaitForCriticalSection+0x132
03 02b0f8e0 006cf60e 02b29ba8 1ba0021b 00000000 ntdll!RtlEnterCriticalSection+0x46
04 02b0f960 006e0dd4 000f4240 00000010 006a48fa CtrlCenter!gloox::ConnectionTCPClient::recv+0x3e [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\connectiontcpclient.cpp @ 130]
05 02b0f96c 006a48fa 1ba00393 00000000 02b27b10 CtrlCenter!gloox::ConnectionTCPBase::receive+0x24 [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\connectiontcpbase.cpp @ 116]
06 02b0fa78 00707090 02b27b10 1ba00063 77d191c6 CtrlCenter!gloox::ClientBase::connect+0x3aa [d:\dailybuild\ftnn_git\ftnn\glooxlib\gloox-1.0.11\clientbase.cpp @ 227]
07 02b0ff70 007071b4 100264b8 000010ef 00000000 CtrlCenter!CC_IM::Login_Inner+0xb10 [d:\dailybuild\ftnn_git\ftnn\ctrlcenter\ctrlcenter\cc_im.cpp @ 141]
08 02b0ff74 100264b8 000010ef 00000000 00000000 CtrlCenter!CC_IM::PreThreadMsg+0x14 [d:\dailybuild\ftnn_git\ftnn\ctrlcenter\ctrlcenter\cc_im.cpp @ 340]
WARNING: Stack unwind information not available. Following frames may be wrong.
09 02b0ff90 7c93017b 00000000 000010ef 00000000 OMBase!OMThread::Create_Inner+0x68
0a 02b101a8 00380035 00350034 00310030 00350032 ntdll!RtlAllocateHeap+0x1c2
0b 02b101a8 00000000 00350034 00310030 00350032 0x380035
//===============================================
//更简洁的方法
//===============================================
0:019> !cs -o -l
-----------------------------------------
DebugInfo = 0x0018d710
Critical section = 0x01d0be14 (+0x1D0BE14)
LOCKED
LockCount = 0x0
OwningThread = 0x0000093c
RecursionCount = 0x1
LockSemaphore = 0x0
SpinCount = 0x00000400
OwningThread DbgId = ~0s
OwningThread Stack =
ChildEBP RetAddr Args to Child
0012e45c 7c92df3c 7c93b22b 0000064c 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0012e460 7c93b22b 0000064c 00000000 00000000 ntdll!NtWaitForSingleObject+0xc (FPO: [3,0,0])
0012e4e8 7c921046 00b29b88 006e0e32 02b29b88 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
0012e4f0 006e0e32 02b29b88 19021feb 0012e590 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
0012e558 006a8f69 0012e590 1910faeb 006a8dfb CtrlCenter!gloox::ConnectionTCPBase::send+0x42 (FPO: [Uses EBP] [1,19,5]) (CONV: thiscall)
0012e564 006a8dfb 19021f9b 02b27b10 02b32538 CtrlCenter!gloox::ClientBase::send+0x59 (FPO: [0,1,0]) (CONV: thiscall)
0012e604 006a8bac 02b27b10 02b32538 00000001 CtrlCenter!gloox::ClientBase::send+0x5b (CONV: thiscall)
0012e61c 006a8b44 19021cc3 02b474e4 02b3a3c8 CtrlCenter!gloox::ClientBase::send+0x4c (FPO: [0,0,1]) (CONV: thiscall)
0012e668 006b9297 0012e758 01d0b978 00000008 CtrlCenter!gloox::ClientBase::send+0xe4 (FPO: [Uses EBP] [3,13,5]) (CONV: thiscall)
0012e91c 006fe25c 0012e990 190213c7 00000000 CtrlCenter!gloox::RosterManager::GetSimple+0x137 (CONV: thiscall)
0012ead8 006fa44b 0001adb2 00000000 00000000 CtrlCenter!CC_IM_Roster::GetUserSimpleInfo+0x32c (FPO: [Uses EBP] [2,104,5]) (CONV: thiscall)
0012eaec 03f86dcd 0001adb2 00000000 00000000 CtrlCenter!ICC_IM::GetUserSimpleInfo+0x2b (CONV: stdcall)
0012eb14 03f86bcd 0001adb2 00000000 4a6a23fa QTUIAssem!CChatUserHeaderData::DoTryRosterSimpleInfoRequest+0x5d (FPO: [Uses EBP] [2,3,4]) (CONV: thiscall)
0012f394 03f946c9 0418dbdc 0001adb2 00000000 QTUIAssem!CChatUserHeaderData::GetUserHeadImg+0x1ed (FPO: [Uses EBP] [4,536,5]) (CONV: thiscall)
0012f3ac 03fb1533 4a6a3b6a 07500c78 0410ae18 QTUIAssem!CFTRoomDataDelegate::GetRoomMemberHeader+0x29 (FPO: [0,1,0]) (CONV: thiscall)
0012f4b0 0405a13a 07500ec0 0012f66c 0410ae18 QTUIAssem!CFGMemberListGridEx::OnOwnerDrawCell+0xd3 (CONV: thiscall)
0012f4c8 0405a318 07500c78 00000000 0000ff58 QTUIAssem!_AfxDispatchCmdMsg+0x72 (FPO: [Non-Fpo]) (CONV: stdcall)
0012f4f8 04057e34 00000000 0000ff58 0012f518 QTUIAssem!CCmdTarget::OnCmdMsg+0x118 (FPO: [Non-Fpo]) (CONV: thiscall)
0012f520 04055f01 0000004e 00000064 07500ec0 QTUIAssem!CWnd::ReflectChildNotify+0x52 (FPO: [Non-Fpo]) (CONV: thiscall)
0012f538 04056571 0012f66c 4a6a3d66 074fffc8 QTUIAssem!CWnd::SendChildNotifyLastMsg+0x32 (FPO: [1,0,4]) (CONV: thiscall)
-----------------------------------------
DebugInfo = 0x001a3f68
Critical section = 0x02b29b88 (+0x2B29B88)
LOCKED
LockCount = 0x1
OwningThread = 0x00000864
RecursionCount = 0x1
LockSemaphore = 0x64C
SpinCount = 0x00000000
OwningThread DbgId = ~8s
OwningThread Stack =
ChildEBP RetAddr Args to Child
02b0f84c 7c92df3c 7c93b22b 000004b8 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
02b0f850 7c93b22b 000004b8 00000000 00000000 ntdll!NtWaitForSingleObject+0xc (FPO: [3,0,0])
02b0f8d8 7c921046 00b29ba8 006cf60e 02b29ba8 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
02b0f8e0 006cf60e 02b29ba8 1ba0021b 00000000 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
02b0f960 006e0dd4 000f4240 00000010 006a48fa CtrlCenter!gloox::ConnectionTCPClient::recv+0x3e (FPO: [Uses EBP] [1,25,5]) (CONV: thiscall)
02b0f96c 006a48fa 1ba00393 00000000 02b27b10 CtrlCenter!gloox::ConnectionTCPBase::receive+0x24 (FPO: [0,0,0]) (CONV: thiscall)
02b0fa78 00707090 02b27b10 1ba00063 77d191c6 CtrlCenter!gloox::ClientBase::connect+0x3aa (FPO: [Uses EBP] [1,61,5]) (CONV: thiscall)
02b0ff70 007071b4 100264b8 000010ef 00000000 CtrlCenter!CC_IM::Login_Inner+0xb10 (CONV: thiscall)
02b0ff74 100264b8 000010ef 00000000 00000000 CtrlCenter!CC_IM::PreThreadMsg+0x14 (FPO: [3,0,0]) (CONV: thiscall)
WARNING: Stack unwind information not available. Following frames may be wrong.
02b0ff90 7c93017b 00000000 000010ef 00000000 OMBase!OMThread::Create_Inner+0x68
02b101a8 00380035 00350034 00310030 00350032 ntdll!RtlAllocateHeap+0x1c2 (FPO: [Non-Fpo])
02b101a8 00000000 00350034 00310030 00350032 0x380035
-----------------------------------------
DebugInfo = 0x001a3f90
Critical section = 0x02b29ba8 (+0x2B29BA8)
LOCKED
LockCount = 0xFFFFFFFE
OwningThread = 0x00000000
RecursionCount = 0xFFFFFFFE
LockSemaphore = 0x4B8
SpinCount = 0x00000000
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。