Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB doesn't show object's members

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();
}

When I want to inspect base I get:

p base
$1 = (Base *) 0x7fffc408edf0

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

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

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.

like image 995
Michał Walenciak Avatar asked Mar 10 '23 22:03

Michał Walenciak


1 Answers

You want (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.
like image 148
Employed Russian Avatar answered Mar 19 '23 16:03

Employed Russian