Determining type of an object at debug time.
Mike Stump
mrs@windriver.com
Mon Mar 13 18:30:00 GMT 2000
> Date: Mon, 13 Mar 2000 09:45:42 -0800 (PST)
> From: Daniel Berlin <dan@cgsoftware.com>
> To: gcc@gcc.gnu.org
> one of the things i'm working on is determining the type of an
> object at debug time
> Is this even possible with g++ compiled objects?
Yes.
> I could call the __tf functions, but that would require knowing the
> type in the first place.
No. See type_info::name() and see how the compiler generates code for
it:
#include <stdio.h>
#include <typeinfo>
struct A {
virtual void foo() { }
} *a;
main() {
printf("", typeid(*a).name());
}
Doing a call at debug time to get the name is a bit unfortunate (what
if it dumps or changes the program state?)... Another way, would be
to see what name the __tf function name has, as it does have the name
of the type in it! For example if the slot has a pointer to __tf1A,
then the dynamic type is in fact 1A, or demangled, A. We know that
from the name of the __tf function alone without the actual need to
call it.
Hope this helps.
More information about the Gcc
mailing list