From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23107 invoked by alias); 27 Sep 2009 18:26:15 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 23092 invoked by uid 22791); 27 Sep 2009 18:26:14 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Date: Sun, 27 Sep 2009 18:26:00 -0000 From: Jan Kratochvil To: Keith Seitz Cc: archer@sourceware.org Subject: Re: set print objct pros/cons [Re: [Keith Seitz] Re: [tools-team] Status 2008-09-01] Message-ID: <20090927182601.GA10613@host0.dyn.jankratochvil.net> References: <6d1764b50909230708l60a4be26ocf3bf6aef198710@mail.gmail.com> <6d1764b50909251238i6471fcacreea5cfbab57cdd2d@mail.gmail.com> <20090927122147.GA15789@host0.dyn.jankratochvil.net> <4ABF9D6E.8020606@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="uAKRQypu60I7Lcqm" Content-Disposition: inline In-Reply-To: <4ABF9D6E.8020606@redhat.com> User-Agent: Mutt/1.5.20 (2009-08-17) X-SW-Source: 2009-q3/txt/msg00259.txt.bz2 --uAKRQypu60I7Lcqm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1383 On Sun, 27 Sep 2009 19:14:22 +0200, Keith Seitz wrote: > On 09/27/2009 05:21 AM, Jan Kratochvil wrote: > > > >(1) Last "call basep->m ()" should have printed "derived::m" > > because "p basep->m" prints "Derived::m()", shouldn't it? > > > > basep->m will always print "base::m" -- your test case did not > declare Base::m virtual. Or is that just an omission in the file you > attached? It was intentional that way (unaware how common it is in C++ to override non-virtual method name by a virtual one, though). I think the following two commands should deal with the same pointer, whithout even talking about which pointer ("Derived::m" or "Base::m") it should be: It does not work now - with the previous testcase cxxinherit.C: (gdb) set print object on (gdb) p basep->m $4 = {void (Derived *)} 0x4006c4 (gdb) call basep->m () base::m > IMO, "object print" should not even exist at all. Currently the "off" mode does not work right for the virtual/virtual case: With the new attached testcase cxxinherit2.C: Starting program: /home/jkratoch/t/cxxinherit2 derived::m derived::m Breakpoint 1, main () at cxxinherit2.C:27 27 return 0; (gdb) show print object Printing of object's derived type based on vtable info is off. (gdb) call basep->m () derived::m (gdb) p basep->m $1 = {void (Base *)} 0x4006a6 (gdb) Regards, Jan --uAKRQypu60I7Lcqm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="cxxinherit2.C" Content-length: 404 #include class Base { public: virtual void m () { puts ("base::m"); } virtual void stub () {} }; class Derived : public Base { public: virtual void m () { puts ("derived::m"); } virtual void stub () {} }; int main () { Derived derived_local; Derived *derivedp = &derived_local; Base *basep = &derived_local; derivedp->m (); basep->m (); return 0; } --uAKRQypu60I7Lcqm--