This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH PR gdb/16841] virtual inheritance via typedef cannot find base




On 7/24/2018 3:18 PM, Simon Marchi wrote:
On 2018-07-20 07:16 PM, Weimin Pan wrote:
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
$2 = 0
(gdb) p derived::base::i
$3 = 0
(gdb) p derived::i
$4 = 4196392

To fix the problem, the virtual-base offset, relative to its derived class,
needs to be fetched, via baseclass_offset(), and used in calculating the
address of its data member in value_struct_elt_for_reference().
Hi Weimin,

I have looked at this a little bit, but unfortunately I don't really understand
what's going on (maybe somebody else does and could review it?).  I understand
the issue, and can see that your patch fixes it, but I don't understand how it
does it.  It would help if you could walk us through your code.  It maybe also
means that some comments would be appropriate, to explain what's going on.

Thanks,

Simon

Hi Simon,

Since a virtual base offset is stored in its derived class's vtable, my code simply (1) checks if base class "curtype" is virtual in its derived class "domain" and (2) calls baseclass_offset() to get its
offset if it is.

Please check out the following article which provides a detailed explanation about the layout:

Memory Layout for Multiple and Virtual Inheritance

https://web.archive.org/web/20160413064252/http://www.phpcompiler.org/articles/virtualinheritance.html

Thanks,
Weimin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]