From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27612 invoked by alias); 29 Feb 2008 21:49:01 -0000 Received: (qmail 27601 invoked by uid 22791); 29 Feb 2008 21:49:00 -0000 X-Spam-Check-By: sourceware.org Received: from aussmtpmrkpc120.us.dell.com (HELO aussmtpmrkpc120.us.dell.com) (143.166.82.159) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Feb 2008 21:48:40 +0000 X-IronPort-AV: E=Sophos;i="4.25,429,1199685600"; d="scan'208";a="330245938" Received: from unknown (HELO M31.equallogic.com) ([12.110.134.31]) by aussmtpmrkpc120.us.dell.com with SMTP; 29 Feb 2008 15:48:38 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18376.32181.325683.100560@gargle.gargle.HOWL> Date: Fri, 29 Feb 2008 22:06:00 -0000 From: Paul Koning To: gdb@sourceware.org Subject: Surprises with "set print object" X-Mailer: VM 7.17 under 21.4 (patch 19) "Constant Variable" XEmacs Lucid X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00270.txt.bz2 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]) { = {_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]) { = {_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