c++multithreadingdebuggingwindbglocks

Windbg "!locks" command doesn't work, can I get information anyway?


While debugging dump files, regularly I need to check for locks, for which I use the windbg extension command !locks. When everything goes well, this provides an output like the following:

CritSec +54a8a8 at 0054a8a8
WaiterWoken        No
LockCount          0
RecursionCount     1
OwningThread       13d8
EntryCount         0
ContentionCount    0
*** Locked

CritSec +b73a8d at 00135e8d
WaiterWoken        No
LockCount          0
RecursionCount     1
OwningThread       55f3
EntryCount         0
ContentionCount    0
*** Locked

...

Scanned 662 critical sections

Sometimes, however, I get following error message:

Stopped scanning because of problem reading critical section debug info

Scanned 7 critical sections

Is it possible to have some information anyway? (E.g. where is that critical section debug info, how can I read it without the !locks command, ...)


Solution

  • A better alternative to !locks is to use !cs -s -l -o see !cs this will display all locked critical sections, the owner stack trace and the critical section stack trace, you can omit the -l if you want all critical sections. You may need to enable the user mode stack trace using gflags !gflag +ust remember to remove it when it isn't needed !glag -ust.

    To display critical section info, you can do this if you have the address: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/displaying-a-critical-section

    so !critsec ADDRESS or using display type command dt dt RTL_CRITICAL_SECTION ADDRESS will work if you have the address.