This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
set print objct pros/cons [Re: [Keith Seitz] Re: [tools-team]Status 2008-09-01]
Hi,
just found out `set print object on' is not such a clear win:
(gdb) b 27
Breakpoint 1 at 0x40069b: file cxxinherit.C, line 27.
(gdb) r
Starting program: /home/jkratoch/t/cxxinherit
derived::m
base::m
Breakpoint 1, main () at cxxinherit.C:27
27 return 0;
(gdb) show print object
Printing of object's derived type based on vtable info is off.
(gdb) p derivedp->m
$1 = {void (Derived *)} 0x4006c4 <Derived::m()>
(gdb) p basep->m
$2 = {void (Base *)} 0x4006a2 <Base::m()>
(gdb) call derivedp->m ()
derived::m
(gdb) call basep->m ()
base::m
(gdb) set print object on
(gdb) p derivedp->m
$3 = {void (Derived *)} 0x4006c4 <Derived::m()>
(gdb) p basep->m
$4 = {void (Derived *)} 0x4006c4 <Derived::m()>
(gdb) call derivedp->m ()
derived::m
(gdb) call basep->m ()
base::m
(1) Last "call basep->m ()" should have printed "derived::m"
because "p basep->m" prints "Derived::m()", shouldn't it?
(2) A lookup can succeed in both "off" and "on" cases with different results.
One should fix (1) as it looks just as a bug to me.
Afterwards for (2) maybe any C++ print should be evaluated both ways and if
the resulting `struct value' differs it should print both values with a warning?
("any C++ print" could be optimized somehow, not the point here.)
Thanks,
Jan
#include <stdio.h>
class Base
{
public:
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;
}