Article View: gnu.gdb.bug
Article #7GDB 4.7, misadjusts 'this' pointer
From: Alexander Klaiber
Date: Tue, 27 Oct 1992 20:21
Date: Tue, 27 Oct 1992 20:21
138 lines
3992 bytes
3992 bytes
gdb: gdb-4.7
compiled-with: decstation/ultrix 4.1 'cc'
host&target: decstation/ultrix 4.1
test program compiled with: gcc-2.2.2 -g
Summary: 'this' pointer not properly adjusted when calling virtual functions
(apparently only when multiple inheritance is used)
In the code below, 'this' is not properly adjusted when calling the virtual
function foo. As the transcript shows, gcc and gdb differ in what they
think 'this' should be.
When class B inherits from class D only (i.e. avoiding the multiple inheritance
case), things seem to work right.
Note 1: I reported a similar bug starting in version 4.4, which only
involved single inheritance. That one seems to be fixed now, thanks.
Note 2: gcc-2.2.2 still seems to have trouble with method search for multiple
inheritance. Possibly the two bugs (gcc,gdb) are related.
Maybe pass on *your* code for method searching in the inheritance
graph to them (theirs is wrong), and get *their* code for adjusting of
'this' for gdb... at least that way, both gcc and gdb would be
consistent.
Code and transcript follow:
=====================================================================
#include <stdio.h>
/* Class hierarchy:
C D.foo
\ /
\ /
B.foo
|
|
Test
*/
class A {
public:
A();
int a;
};
class C {
public:
C();
int c;
};
class D {
public:
D();
int d;
virtual void foo();
};
class B : public C, public D {
public:
int b;
B();
virtual void foo();
};
class Test : public A, public B {
public:
Test();
int test;
};
//
A::A() { a = 'a'; }
C::C() { c = 'c'; }
B::B() { b = 'b'; }
void B::foo() { printf("B::foo this=0x%x, b=%c\n", this, b); }
D::D() { d = 'd'; }
void D::foo() { printf("D::foo this=0x%x, d=%c\n", this, d); }
Test::Test() { test = 't'; }
//
main() {
Test t;
B b;
Test* tt = &t;
B* bb = &b;
B* bt = &t;
tt->foo(); // line 69
bb->foo();
bt->foo();
}
=====================================================================
[smelt:TEST.05.11/BUG - 147] % gcc -v
Reading specs from /uns/trial/lib/gcc-lib/decstation/2.2.2/specs
gcc version 2.2.2
[smelt:TEST.05.11/BUG - 148] % gcc -g test.C
[smelt:TEST.05.11/BUG - 149] % cat .gdbinit
b 69
run
echo --- debugger results:\n
call tt->foo()
call bb->foo()
call bt->foo()
echo -----------------\n
echo --- real results:\n
cont
[smelt:TEST.05.11/BUG - 150] % gdb a.out
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
Breakpoint 1 at 0x4003f4: file test.C, line 69.
Breakpoint 1, main () at test.C:69
69 tt->foo();
--- debugger results:
B::foo this=0x7fffb878, b=` <=== 'this' is WRONG !!!
B::foo this=0x7fffb864, b=` <=== 'this' is WRONG !!!
B::foo this=0x7fffb878, b=` <=== 'this' is WRONG !!!
-----------------
--- real results:
B::foo this=0x7fffb87c, b=b
B::foo this=0x7fffb868, b=b
B::foo this=0x7fffb87c, b=b
(gdb) q
Technical Details
Message-ID:
<1992Oct27.202126.12587@beaver.cs.washington.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!june.cs.washington.edu!klaiberReferences:
<9210270104.AA08301@rice-chex>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!june.cs.washington.edu!klaiber From: klaiber@june.cs.washington.edu (Alexander Klaiber) Newsgroups: gnu.gdb.bug Subject: GDB 4.7, misadjusts 'this' pointer Keywords: C++, multiple inheritance, this Message-ID: <1992Oct27.202126.12587@beaver.cs.washington.edu> Date: 27 Oct 92 20:21:26 GMT Article-I.D.: beaver.1992Oct27.202126.12587 References: <9210270104.AA08301@rice-chex> Sender: gnulists@ai.mit.edu Distribution: gnu Organization: Computer Science & Engineering, U. of Washington, Seattle Lines: 138 Approved: bug-gdb@prep.ai.mit.edu