GDB 不显示对象的成员 [英] GDB doesn't show object's members

查看:47
本文介绍了GDB 不显示对象的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个继承自 Base 的类 Impl.

I've a class Impl which inherites from Base.

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

A simple code snippet I'm trying to debug:

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

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

When I want to inspect base I get:

p base
$1 = (Base *) 0x7fffc408edf0

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

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

I'm compiling my program with gcc and I use -O0 -g. I've also tried -ggdb3 instead of -g with no use.

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

What may be important here: my project is divided into 3 modules: executable and two static libraries. Code I'm debugging lies in one of those static libraries, and definitions of Impl and Base are in second one.

推荐答案

你想要 (gdb) set print object on.

文档:

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 不显示对象的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆