Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify concrete type of object behind auto_ptr from core dump

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 IBaror an IBaz.

Thanks for any help!

like image 674
Martin C. Avatar asked Oct 17 '12 14:10

Martin C.


1 Answers

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.

like image 157
Employed Russian Avatar answered Oct 11 '22 02:10

Employed Russian