Reputation: 323
I want to know the owner of the mutex when debugging with lldb, I check online that gdb can print the thread id like https://en.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Deadlocks
However, when I try this in lldb, the member variable inside mutex is opaque like:
Process 76057 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x00000001000017f5 a.out`main at lol2.cc:65
62 }
63 std::cout << "main thread notify start" << std::endl;
64 std::this_thread::sleep_for(std::chrono::seconds(1));
-> 65 start = true;
66 cv.notify_all();
67 {
68 std::unique_lock<std::mutex> lk(mu1);
(lldb) p mu1
(mutex) $0 = {
__mutex_base = {
_M_mutex = (__sig = 1297437786, __opaque = char [56] @ 0x00007fc614127698)
}
}
(lldb)
Is there any way I can get the content of the opaque part? Thanks.
Upvotes: 1
Views: 1624
Reputation: 2689
I can't say I know how to read the opaque part (may be implementation dependent) but I would suggest using Ami Tavory's answer here to track the owner of a mutex if encapsulating std::mutex
in a new class is allowed.
Upvotes: 1