This is the mail archive of the
mailing list for the Archer project.
Re: How to cast a pointer to a base class with multiple inheritance
I have a patch I've been meaning to submit for a while, it adds
gdb.Value.rtti_type which returns the run time type of an object (as a
gdb.Type) using similar code to `set print object on'. The object can
then be cast using gdb.Value.cast.
I'm not at the right pc just now, but I'll try and mail it to this
list later today.
Just in case it helps in the mean time, it is possible to look at the
first 4 (8 on 64-bit) bytes of an object which has a vtable (which
should be a pointer to the vtable), and run `addr2line -Cfe
name-of-executable 0xBLAHBLAH' which should then say something like
`0xBLAHBLAH: vtable for class FOO'. I think you can also find the
vtable this way using nm or objdump, there may be a similar way to do
this within gdb, but I wouldn't know how. Sorry if these instructions
are rough/wrong, I'm at a non gnu/linux machine at the moment.
2009/8/3 Tom Tromey <firstname.lastname@example.org>:
>>>>>> "Matthieu" == Matthieu VIAL <email@example.com> writes:
> Matthieu> Sorry Value.cast seems to work but my problem is actually a bit more
> Matthieu> complex.
> Matthieu> I need to compare pointers to the interface with pointers to
> Matthieu> the base class. But these classes are not directly related so
> Matthieu> Value.cast is useless. The solution is to up cast the base
> Matthieu> class pointer to the final class and then down cast to the
> Matthieu> interface. But i need run time type information for that. The
> Matthieu> typeid operator doesn't seem to be available in archer.
> Nope. ?The Python API just exposes things that already exist in gdb.
> typeid is not implemented yet, there's a bug for it:
> However, gdb does have "set print object on"... if this prints the right
> thing for you, I think we could hook up the internal code to find the
> "real object" as a Value method.