public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Determining type of an object at debug time.
@ 2000-03-13  9:45 Daniel Berlin
  2000-03-13 16:35 ` Martin v. Loewis
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Berlin @ 2000-03-13  9:45 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Determining type of an object at debug time.
@ 2000-03-13 18:30 Mike Stump
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 2000-03-13 18:30 UTC (permalink / raw)
  To: dan, gcc

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-03-13 18:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-13  9:45 Determining type of an object at debug time Daniel Berlin
2000-03-13 16:35 ` Martin v. Loewis
2000-03-13 17:02   ` Daniel Berlin
2000-03-13 17:14     ` Martin v. Loewis
2000-03-13 17:49       ` Daniel Berlin
2000-03-13 18:30 Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).