无法访问GDB中的pthread_mutex_t成员
Unable access to pthread_mutex_t members in GDB
我无法将pthread_mutex_t的struct成员置于gdb中,以检测僵局
(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_iostreams.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_filesystem.a -Wl,-rpath,/usr/local/lib
OS 9.0释放freebsd 9.0释放#1:AMD64
请帮忙!谢谢!
来自该行
boost::mutex::lock (this=0x7fffffffd980) at mutex.hpp:116
我们可以推断地址0x7fffffffd980
处的对象类型是boost::mutex
。
然后看来将boost::mutex
铸造为pthread_mutex_t
,这是一个坏主意。(另外,可能是gdb
知道位于boost::mutex
类型内部偏移0
的实际类型的sub-object类型。仍然,该字段是私有的)。
即使您找到了boost::mutex
类型的CC_8的正确私人成员,那么您仍然不应依靠其中的实现值。它没有证明是有原因的(实现可能有所不同,可能会更改等)
我建议使用线程测试(-fsanitize=thread
,DRD或Helgrind),如果您需要/需要调试僵局。
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 将函数类成员映射到类本身内部
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- std::mutex作为一个成员变量对多个线程来说是安全的吗
- std::mutex 和 condition_variable 无法访问类内的私有成员
- 以std::mutex作为参数对成员函数进行线程处理
- 与 std::d eque 一起使用时,不能将 Boost::mutex 作为私有类成员吗?
- std:mutex'es 作为将进入容器的对象的成员?
- 使用boost::mutex作为类的私有成员