使用WinDbg分析死鎖

2022-03-03 23:07:32 字數 4318 閱讀 4447

using system;

using system.threading;

private void test1()

).start();

console.readkey();

console.writeline("exit test1");}}

private void test2()}}

}

0:000> ~*e!clrstack

os thread id: 0x26d4 (0)

child sp ip call site

000000000045ea38 000007ffe9ab2c5a [inlinedcallframe: 000000000045ea38] microsoft.win32.win32native.readconsoleinput(intptr, inputrecord byref, int32, int32 byref)

000000000045ea38 000007ffd1e3f64e [inlinedcallframe: 000000000045ea38] microsoft.win32.win32native.readconsoleinput(intptr, inputrecord byref, int32, int32 byref)

000000000045e9f0 000007ffd1e3f64e domainneutralilstubclass.il_stub_pinvoke(intptr, inputrecord byref, int32, int32 byref)

000000000045eb30 000007ffd1ea9961 system.console.readkey(boolean)

000000000045efd0 000007ffdac338f3 [gcframe: 000000000045efd0]

os thread id: 0x2b74 (1)

unable to walk the managed stack. the current thread is likely not a

managed thread. you can run !threads to get a list of managed threads in

the process

failed to start stack walk: 80070057

os thread id: 0x2a60 (2)

child sp ip call site

000000001af8f8c8 000007ffe9ab319b [debuggeru2mcatchhandlerframe: 000000001af8f8c8]

os thread id: 0x1978 (3)

unable to walk the managed stack. the current thread is likely not a

managed thread. you can run !threads to get a list of managed threads in

the process

failed to start stack walk: 80070057

os thread id: 0x242c (4)

child sp ip call site

000000001ba6e9d8 000007ffe9ab319b [gcframe: 000000001ba6e9d8]

000000001ba6eb18 000007ffe9ab319b [gcframe: 000000001ba6eb18]

000000001ba6eb58 000007ffe9ab319b [helpermethodframe_1obj: 000000001ba6eb58] system.threading.monitor.enter(system.object)

000000001ba6ecb0 000007ffd16afb65 system.threading.executioncontext.runinternal(system.threading.executioncontext, system.threading.contextcallback, system.object, boolean)

000000001ba6ee10 000007ffd16af8c9 system.threading.executioncontext.run(system.threading.executioncontext, system.threading.contextcallback, system.object, boolean)

000000001ba6ee40 000007ffd16af887 system.threading.executioncontext.run(system.threading.executioncontext, system.threading.contextcallback, system.object)

000000001ba6ee90 000007ffd16c2fe1 system.threading.threadhelper.threadstart()

000000001ba6f1a8 000007ffdac338f3 [gcframe: 000000001ba6f1a8]

000000001ba6f4d8 000007ffdac338f3 [debuggeru2mcatchhandlerframe: 000000001ba6f4d8]

0:000> !runaway

user mode time

thread time

4:242c 0 days 0:00:00.000

3:1978 0 days 0:00:00.000

2:2a60 0 days 0:00:00.000

1:2b74 0 days 0:00:00.000

0:26d4 0 days 0:00:00.000

0:000> .time

debug session time: mon may 20 17:22:13.000 2013 (utc + 8:00)

system uptime: 0 days 7:14:13.190

process uptime: 0 days 0:00:11.000

kernel time: 0 days 0:00:00.000

user time: 0 days 0:00:00.000

0:000> !threads

threadcount: 3

unstartedthread: 0

backgroundthread: 1

pendingthread: 0

deadthread: 0

hosted runtime: no

lock

id osid threadobj state gc mode gc alloc context domain count apt exception

0 1 26d4 00000000004fe850 2a020 preemptive 0000000002826698:0000000002827fd0 00000000004d2ab0 2 mta

2 2 2a60 00000000005056a0 2b220 preemptive 0000000000000000:0000000000000000 00000000004d2ab0 0 mta (finalizer)

4 3 242c 000000000052aca0 202b020 preemptive 0000000002828010:0000000002829fd0 00000000004d2ab0 0 mta

可看到執行緒0有兩個鎖

0:000> !syncblk

index syncblock monitorheld recursion owning thread info syncblock owner

-----------------------------

total 2

ccw 0

rcw 0

comclassfactory 0

free 0

可看到執行緒「00000000004fe850 」拿到了鎖,再通過!threads命令得到其執行緒邏輯號為0,即可切換至該執行緒,並通過!clrstack列印出其執行堆疊。

windbg分析死鎖問題

如下 include include include using namespace std critical section cs db1 critical section cs db2 dword winapi threadproc lpvoid lpparam void main delete...

WinDbg 除錯互斥體 Mutex 死鎖

include include include handle hmutexa null handle hmutexb null unsigned stdcall threadproc1 void parg unsigned stdcall threadproc2 void parg int main...

Windbg除錯互斥體 Mutex 死鎖

include include include handle hmutexa null handle hmutexb null unsigned stdcall threadproc1 void parg unsigned stdcall threadproc2 void parg int main...