From: Weimin Pan <weimin.pan@oracle.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH PR gdb/16841] virtual inheritance via typedef cannot find base
Date: Tue, 24 Jul 2018 23:26:00 -0000 [thread overview]
Message-ID: <c5ad8467-c4bb-ecb6-9a5d-55a89a959338@oracle.com> (raw)
In-Reply-To: <9fb7e028-44c2-1cec-32e0-b1431c95f074@ericsson.com>
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
next prev parent reply other threads:[~2018-07-24 23:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-20 23:50 Weimin Pan
2018-07-24 22:18 ` Simon Marchi
2018-07-24 23:26 ` Weimin Pan [this message]
2018-07-29 2:28 ` Tom Tromey
2018-07-30 17:58 ` Wei-min Pan
2018-07-31 15:42 ` Tom Tromey
-- strict thread matches above, loose matches on Subject: below --
2018-06-15 23:45 Weimin Pan
2018-06-17 1:06 ` Simon Marchi
2018-06-18 16:12 ` Wei-min Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c5ad8467-c4bb-ecb6-9a5d-55a89a959338@oracle.com \
--to=weimin.pan@oracle.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).