GDB 不显示对象的成员

GDB doesn't show object's members

我有一个 class Impl 继承自 Base.

我正在尝试调试的一个简单代码片段:

{
    Base* base = getObject();     // getObject() returns instance of Impl
    base->something();
}

当我想检查时 base 我得到:

p base
 = (Base *) 0x7fffc408edf0

p *base
 = {_vptr.Base = 0x7ffff74be100 <vtable for Impl+16>}

我正在用 gcc 编译我的程序,我使用 -O0 -g。我也试过 -ggdb3 而不是 -g 没有用。

这里可能很重要:我的项目分为 3 个模块:可执行文件和两个静态库。我正在调试的代码位于其中一个静态库中,ImplBase 的定义在第二个中。

你想要(gdb) set print object on.

Documentation:

set print object on
  When displaying a pointer to an object, identify the actual (derived) type
  of the object rather than the declared type, using the virtual function table.

gdb 不知道你的 *base 指向一个 Impl,所以你必须告诉它:

p (Impl)*base