Determining type of an object at debug time.
Daniel Berlin
dan@cgsoftware.com
Mon Mar 13 09:45:00 GMT 2000
As the new C++ support maintainer for GDB, one of the things i'm working
on is determining the type of an object at debug time, so we can print out
the type properly without the user having to cast it, and so we can call
the right functions if the user wanted to.
For those who don't udnerstand what i mean, consider the following:
class foo1
{
public:
virtual int ab(){};
int a;
};
class foo2:public foo1
{
public:
virtual int ab(){};
int b;
};
foo1 *dan=new foo2();
if you print dan in GDB, it'll think it's a foo1 *, and if you want to see
the foo2 members, you have to print (foo2 *)dan.
If you called ab, it would call the wrong function, because it has no idea
it's really not a foo1.
Their is already support for doing this with HP aCC compiled objects. The
code works by reading the type name out of the vtable.
Obviously, this is very compiler specific, but it's always going to be, so
i have no problem with having to hard code offsets or something.
I'm just trying to figure out how to get the same info, at debug time, on
g++ compiled objects.
Is this even possible with g++ compiled objects?
I could call the __tf functions, but that would require knowing the type
in the first place.
--Dan
More information about the Gcc
mailing list