* Surprises with "set print object"
@ 2008-02-29 22:06 Paul Koning
0 siblings, 0 replies; only message in thread
From: Paul Koning @ 2008-02-29 22:06 UTC (permalink / raw)
To: gdb
We're debugging some code with "set print object" in effect, so GDB
will look at the vtable when interpreting a pointer to class, and show
the actual class rather than the pointer's class.
This is great but it only works about half the time.
Given the following:
class foo
{
public:
int x;
virtual void t(void) const;
virtual void u(void) const;
};
class bar: public foo
{
public:
int y;
virtual void t(void) const;
};
foo *fp;
foo f;
bar b;
void foo::t(void) const
{
printf("foo::t\n");
}
void bar::t(void) const
{
printf("bar::t\n");
}
void foo::u(void) const
{
printf ("foo::u\n");
}
int main(int, char **)
{
fp = &b;
fp->u();
return 0;
}
In the call to foo::u, the object pointed to is an instance of class
bar.
Here's what I get with GDB 6.7.1:
Breakpoint 1, foo::u (this=0x8049a5c) at /lhome/pkoning/vt.cc:34
34 printf ("foo::u\n");
(gdb) set print object
(gdb) p this
$3 = (bar *) 0x8049a5c
(gdb) p *this
$4 = (bar [incomplete object]) {<foo> = {_vptr.foo = 0x8048740, x = 0}, y = 0}
(gdb) p x
$5 = 0
(gdb) p y
No symbol "y" in current context.
(gdb) p this->y
$6 = 0
(gdb) p this[0]
$7 = (bar [incomplete object]) {<foo> = {_vptr.foo = 0x8048740, x = 0}, y = 0}
(gdb) p this[0].y
There is no member or method named y.
So references to this, or *this, or this->member, or this[0] all are
interpreted correctly. But references to "member" or "this[0].member"
do not work right (they only work if "member" is a member of class
foo).
Known bug? If not, where might it live? I could attempt a fix (if it
doesn't require great gdb type magic, which often goes over my
head...).
Thanks,
paul
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-02-29 21:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-29 22:06 Surprises with "set print object" Paul Koning
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox