5

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!

3
  • Does print typeid(*this->obj._M_ptr) work? Oct 17, 2012 at 14:28
  • try this Q/A: stackoverflow.com/questions/9568201/…
    – PiotrNycz
    Oct 17, 2012 at 14:30
  • typeid(...) just outputs 'No symbol "typeid" in current context.', which could mean that my cross-compiled GDB might be too old. In this case this would be bad luck. But thanks for the hint.
    – Martin C.
    Oct 17, 2012 at 14:48

1 Answer 1

6

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.

3
  • Using set print object on was my first approach, but it only outputs the IFoo* interface. I begin to fear that there is no RTTI available. This is a core-dump from a stripped ARM binary, where I have the dbg files available as well. Would working with dynamic_cast imply that RTTI needs to be enabled or not?
    – Martin C.
    Oct 17, 2012 at 14:44
  • 1
    @MartinC. Re: dynamic cast with no RTTI: stackoverflow.com/questions/7687041/… Oct 18, 2012 at 14:03
  • @shroudednight Thanks, good hint. I know for sure that there are no explicit disable flags in the compile process, but I will continue investigating in this direction.
    – Martin C.
    Oct 19, 2012 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.