How can I debug mutex issues on Mac OS X?

2019-06-23 17:28发布

问题:

I am trying to get a gdb/lldb stub to work for a program I'm making, and right now it seems to deadlock the debugger, so I am (ironically) debugging lldb on my machine to try to figure out where things go wrong.

lldb is trying to lock a mutex and seems to deadlock on that.

On Windows, I know that you can use WinDBG magic in kernel debugging mode to figure out who acquired the mutex first, and on Linux I know that pthread_mutex_t isn't opaque and you can use it to figure out which thread is holding it very simply.

What about Mac OS X? What can I do if I want to know which thread owns a mutex?

For the record, I've tried searching opensource.apple.com for the actual definition of the mutex structure, without much luck, but it doesn't mean it's not there.