LLDB 如何检查互斥锁的所有者?

lldb how to check the owner of the mutex?

本文关键字:所有者 何检查 检查 LLDB      更新时间:2023-10-16

我想知道使用 lldb 调试时互斥锁的所有者,我在线检查 gdb 是否可以像 https://en.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Deadlocks 一样打印线程 ID

但是,当我在 lldb 中尝试此操作时,互斥锁中的成员变量是不透明的,例如:

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)

有什么方法可以获取不透明部分的内容吗?谢谢。

我不能说我知道如何阅读不透明部分(可能取决于实现(,但我建议在这里使用 Ami Tavory 的答案来跟踪互斥锁的所有者,如果允许将std::mutex封装在新类中。