This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: set print objct pros/cons [Re: [Keith Seitz] Re: [tools-team]Status 2008-09-01]
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 <Derived::m()>
(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 <Base::m()>
(gdb)
Regards,
Jan
#include <stdio.h>
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;
}