You can use ptype
.
Suppose I add these lines to your example:
A alpha;
B beta;
Now in gdb I can ask for a description of a class type (or an instance of one):
(gdb) ptype alpha
type = class A {
public:
virtual void foo();
}
(gdb) ptype A
type = class A {
public:
virtual void foo();
}
(gdb) ptype beta
type = class B : public A {
public:
virtual void foo();
}
(gdb) ptype B
type = class B : public A {
public:
virtual void foo();
}
If I try that with a pointer, I get the declared type:
(gdb) ptype b
type = class A {
public:
virtual void foo();
} *
If I want the real type, I must set the `print object’ variable:
(gdb) set print object on
(gdb) ptype b
type = /* real type = B * */
class A {
public:
virtual void foo();
} *
and then call ptype
again to see what B
has (I don’t know how to do it in one step).