This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Determining type of an object at debug time.


> 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?

If all you have is a void*, then no, it is not possible in the general
case. Consider

struct timespec
  {
    long int tv_sec;		/* Seconds.  */
    long int tv_nsec;		/* Nanoseconds.  */
  };

I very much doubt that given a void* to a struct timespec, HP aCC will
find out that this is a struct timespec*; that sounds just not
possible.

If you know the base type already, and you know that the base type has
a virtual function table, then you can use the virtual table to find
out the dynamic type. Rather than calling the type info function, I'd
recommend to find out the external symbol name, and use that to infer
the type (perhaps doing a consistency check whether it is really
derived from the base type).

In the new C++ ABI, the vtable will always be at offset 0, so you get
the dynamic type as long as you know you have a polymorphic pointer -
but that is not implemented, yet.

So if you only have a void*, you could do some guess-work to find out
what the dynamic type is. You could scan the fields of the object to
find something that looks like a vtable pointer. On most systems, you
can tell whether it is a vtable pointer if it has an external symbol.
In case they are stripped, it should live in the text segment, and so
on.

I feel that it would pay-off to try to be smart, as long as nothings
breaks in case you guess wrong.

I think this would be a very important feature, so let me know if you
have further questions.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]