This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Surprises with "set print object"


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


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