【问题标题】:lldb how to check the owner of the mutex?lldb如何检查互斥锁的所有者?
【发布时间】:2018-01-10 09:54:19
【问题描述】:

用lldb调试的时候想知道mutex的所有者,我上网查了一下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)

有什么办法可以得到不透明部分的内容吗?谢谢。

【问题讨论】:

    标签: c++ multithreading gdb mutex lldb


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 2018-04-16
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多