c++ - 使用 gdb 检查 boost shared_ptr

标签 c++ boost gdb shared-ptr

以下是我的源代码:

#include <iostream>
#include <boost/shared_ptr.hpp>

class MyClass
{
    public:
        MyClass()
        {
            i=10;
        }
    private:
        int i;
};


int main(int argc, const char *argv[])
{
    boost::shared_ptr <MyClass> obj(new MyClass());
    return 0;
}

我想查看gdb中的obj,查看成员变量i的值。

这是我用普通打印得到的:

29          boost::shared_ptr <MyClass> obj(new MyClass());
(gdb) n
30          return 0;
(gdb) p obj
$1 = {px = 0x602010, pn = {pi_ = 0x602030}}

我尝试了 this link 中提到的提示,但不起作用。

(gdb) call (obj.get())->print()
Cannot evaluate function -- may be inlined

还有其他方法吗? gdb 版本是 7.0.1。

最佳答案

知道了!

(gdb) set print pretty
(gdb) p obj
$5 = {
  px = 0x602010,
  pn = {
    pi_ = 0x602030
  }
}
(gdb) p obj.px
$6 = (MyClass *) 0x602010



(gdb) p *(obj.px)
$7 = {
  i = 10
}

关于c++ - 使用 gdb 检查 boost shared_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17804967/

相关文章:

c++ - 安装 odeint <boost/config.hpp> 时出错

c++ - 从 boost mpl vector 注册类型

c - 我的段错误发生在哪里?

linux - 如何增加 Linux 核心转储匹配符号的概率?

c++ - malloc 或我的错误?

c++ - 是否可以在切换 QTreeWidgetItem 复选框时创建信号?

c++ - 如何提取Boost库中引用段的点

c++ - GCC 调试器堆栈跟踪显示错误的文件名和行号

c# - winform 中的 C++ 非托管代码

java - c++ 或 java 中用于保存 20 位整数的数据类型