]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Finding data member in virtual base class
authorWeimin Pan <weimin.pan@oracle.com>
Mon, 8 Oct 2018 21:16:59 +0000 (21:16 +0000)
committerWeimin Pan <weimin.pan@oracle.com>
Mon, 8 Oct 2018 21:23:50 +0000 (21:23 +0000)
commit9f6b697b0efd4ba4e2cb21ac17d2b18a23f81abd
treec9b6950d1f7a4e1618079b5f27b652523c795e19
parent780f601cf3bfd2eb141c2ea32b673b5bd0956a33
Finding data member in virtual base class

This patch fixes the original problem - printing member in a virtual base,
using various expressions, do not yield the same value. Simple test case
below demonstrates the problem:

% cat t.cc
struct base { int i; };
typedef base tbase;
struct derived: virtual tbase { void func() { } };
int main() { derived().func(); }
% g++ -g t.cc
% gdb a.out
(gdb) break derived::func
(gdb) run
(gdb) p i
$1 = 0
(gdb) p base::i
$3 = 0
(gdb) p derived::i
$4 = 4196392

To fix the problem, add function get_baseclass_offset() which searches
recursively for the base class along the class hierarchy. If the base
is virtual, it uses "vptr" in virtual class object, which indexes to
its derived class's vtable, to get and returns the baseclass offset.
If the base is non-virtual, it returns the accumulated offset of its
parent classes. The offset is then added to the address of the class
object to access its member in value_struct_elt_for_reference().
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/virtbase2.cc [new file with mode: 0644]
gdb/testsuite/gdb.cp/virtbase2.exp [new file with mode: 0644]
gdb/valops.c