Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Koning <Paul_Koning@dell.com>
To: gdb@sourceware.org
Subject: Surprises with "set print object"
Date: Fri, 29 Feb 2008 22:06:00 -0000	[thread overview]
Message-ID: <18376.32181.325683.100560@gargle.gargle.HOWL> (raw)

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


                 reply	other threads:[~2008-02-29 21:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18376.32181.325683.100560@gargle.gargle.HOWL \
    --to=paul_koning@dell.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox