gpt4 book ai didi

c++ - GDB 不显示对象的成员

转载 作者:行者123 更新时间:2023-11-30 01:41:04 25 4
gpt4 key购买 nike

我有一个 Impl 类,它继承自 Base

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

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

当我想检查 base 时,我得到:

p base
$1 = (Base *) 0x7fffc408edf0

p *base
$2 = {_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.

关于c++ - GDB 不显示对象的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42076577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com