【问题标题】:Unable access to pthread_mutex_t members in GDB无法访问 GDB 中的 pthread_mutex_t 成员
【发布时间】:2017-09-07 04:37:59
【问题描述】:

我无法在 gdb 中转储 pthread_mutex_t 的结构成员值以检测死锁

(gdb) where
#0  boost::mutex::lock (this=0x7fffffffd980) at mutex.hpp:116
#1  0x000000000043454b in boost::unique_lock<boost::mutex>::lock (this=0x7fffffffd970) at lock_types.hpp:346
#2  0x0000000000434591 in unique_lock (this=0x7fffffffd970, m_=@0x7fffffffd980) at lock_types.hpp:124

(gdb) print m
$21 = 0x802418880
(gdb) print &m
$22 = (pthread_mutex_t *) 0x7fffffffd980


GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd".

testapp.cpp 的来源

boost::mutex cn_mutex;
    boost::mutex::scoped_lock lock(cn_mutex);
    mystruct st;
    st.id = 888;
    while(true)
    {
        usleep(1000 * 2000);
    }
    std::cout << "done \n";
    return 0;

编译参数:

   /usr/bin/c++ -g -Wno-unknown-pragmas -Wno-sign-compare -g -pg CMakeFiles/testinterproc.dir/testapp.cpp.o -o testinterproc /usr/local/lib/libssl.so /usr/local/lib/libcrypto.so /usr/local/lib/libexecinfo.so /usr/local/lib/liblog4cplus.so -lpthread /home/xgps_app/thirdparty/boostlib1_64_0/lib/libboost_iostre‌​ams.a /home/xgps_app/thirdparty/boostlib1_64_0/lib/libboost_system‌​.a /home/xgps_app/thirdparty/boostlib1_64_0lib/lib/boost_thread‌​.a /home/xgps_app/thirdparty/boostlib1_64_0 /home/xgps_app/thirdparty/boostlib1_64_0/lib/libboost_filesy‌​stem.a -Wl,-rpath,/usr/local/lib

OS 9.0-RELEASE FreeBSD 9.0-RELEASE #1: amd64
请帮忙! 谢谢!

【问题讨论】:

  • 你是如何编译你的代码的?
  • 编辑您的问题以包含使用的命令。
  • 还要注意 pthread 类型是opaque types。你不应该知道他们的成员,或者访问他们。
  • @Nikola 请自行在问题中为您的问题提供更多详细信息。您可以点击问题底部的“编辑”按钮,添加您在评论中输入的详细信息,然后删除评论。
  • 代码中仍然没有m

标签: c++ boost gdb mutex freebsd


【解决方案1】:

从线

boost::mutex::lock (this=0x7fffffffd980) at mutex.hpp:116

我们可以推断出地址0x7fffffffd980的对象的类型是boost::mutex

然后似乎将boost::mutex 转换为pthread_mutex_t,这是一个坏主意。 (或者,gdb 可能知道位于boost::mutex 类型内偏移量0 的子对象的实际类型。不过,该字段是私有的)。

即使您发现boost::mutex正确 私有成员是pthread_mutex_t 类型,那么您仍然不应该依赖其中特定于实现的值。它没有记录是有原因的(实现可能不同,可能会改变等)

如果您想要/需要调试死锁,我建议您使用线程测试(-fsanitize=thread、DRD 或 Helgrind)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多