I have an auto_ptr<IFoo>
, where IFoo
is an interface with just pure-virtual methods.
I now also have a core-file after a segmentation fault, where I'd really like to know what the concrete sub-class was behind this auto_ptr. As dynamic_cast
works in the project, I think that RTTI must be available somehow, but I am unaware as how I would access this information via gdb
?
The output I get is as follows:
(gdb) print this->obj._M_ptr
$22 = (class martin::IFoo *) 0x7418
What I'd really like to know, if the pointer belongs to an IBar
or an IBaz
.
Thanks for any help!
What I'd really like to know, if the pointer belongs to an IBaror an IBaz
GDB should be able to tell you that. Use (gdb) set print object on
. Documentation here.
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. Note that the virtual function table is required—this feature can only work for objects that have run-time type identification; a single virtual method in the object's declared type is sufficient.
Update:
it only outputs the IFoo* interface
That likely means that the pointer really is pointing to IFoo
(e.g. the object that was of type IBar
or IBaz
has already been destructed).
Would working with dynamic_cast imply
Yes, dynamic_cast
can't work without RTTI; if you are using dynamic_cast
, print object on
should just work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With