From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32486 invoked by alias); 24 Jul 2018 23:26:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32475 invoked by uid 89); 24 Jul 2018 23:26:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=articles, Inheritance X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Jul 2018 23:26:48 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6ONNbA8081684; Tue, 24 Jul 2018 23:26:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=XBmFPR8j/VH7uXjTeE8h3fbHBAFy35rVDGgQKIK/Thg=; b=zs2DNyarQbfl96aj9243a4MwDfBRk1KVLRkIc0l7npnZMJgZe2cgH691B5bSMnOkhaso SCSLylq2evwfgJZeIcOlljL0IpCZD+oogGpHnmehKlMPIOhzBbXICadmyNsFk/3qhU/k 4qP7FKwABhFH0N7tuSLhSovy3t831SDulP12GC7fkwJDzveDLoVkbDqAZDKWy1F5Egz9 GyiiZNUqzLesAbQaHmCkyxyVkBGlE9xt0Lf1rZh9+tsEozU9pJKHj4XHKk0kJGaeDP7u HlWTToHdXVzjswbQhQWyqs7/n7UwBVdjIe4rZ738rUYZUjJt//+9wLEl9rKtGP7ATS9b jA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2kbv8t37fh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Jul 2018 23:26:43 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6ONQgnJ022283 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Jul 2018 23:26:43 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6ONQgDx004091; Tue, 24 Jul 2018 23:26:42 GMT Received: from [10.132.96.98] (/10.132.96.98) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 24 Jul 2018 16:26:42 -0700 Subject: Re: [PATCH PR gdb/16841] virtual inheritance via typedef cannot find base To: Simon Marchi , gdb-patches@sourceware.org References: <1532128565-75923-1-git-send-email-weimin.pan@oracle.com> <9fb7e028-44c2-1cec-32e0-b1431c95f074@ericsson.com> From: Weimin Pan Message-ID: Date: Tue, 24 Jul 2018 23:26:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <9fb7e028-44c2-1cec-32e0-b1431c95f074@ericsson.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-07/txt/msg00685.txt.bz2 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