From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26658 invoked by alias); 14 Sep 2018 18:26:53 -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 26649 invoked by uid 89); 14 Sep 2018 18:26:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_PASS autolearn=ham version=3.3.2 spammy=HTo:D*oracle.com, EOF, intuitive, Heres X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Sep 2018 18:26:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1536949607; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FsxkM+ImzaXvO3NydgqyjWIQQbnZeSFtdrG8qzmyRz0=; b=IYGZnp/b9ooUX4j2OJXBViZUw/8M3+6boP0wc/2o6O5cE2UR+U73gRu1mCeK8ztx 5DCq8FbVcM0MZm0SOx48z5ZtM4bk/0WAKmcH5kXDMg2lx0YVyZrZK9qb0ZCEGF3L gCjP7fD0RSoO8gDEZynEFBFAkszsFMjFn+x2ReJG9W8=; Received: from ESESSMB504.ericsson.se (Unknown_Domain [153.88.183.122]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id 01.67.22015.76DFB9B5; Fri, 14 Sep 2018 20:26:47 +0200 (CEST) Received: from ESESSMR505.ericsson.se (153.88.183.127) by ESESSMB504.ericsson.se (153.88.183.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 14 Sep 2018 20:26:29 +0200 Received: from ESESSMB504.ericsson.se (153.88.183.165) by ESESSMR505.ericsson.se (153.88.183.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 14 Sep 2018 20:26:29 +0200 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB504.ericsson.se (153.88.183.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Fri, 14 Sep 2018 20:26:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6jeDOr3Uv0MkfRvYXP0jAGkrHB020+9ZYk5Mc3Gx0kc=; b=iUXAeVkFfpKkaPEhYK6Obtn9qWfBYyvFDGqw4WO6yagkDE6V5EXsEXLJMIs6MrCCKI8GiLUzDabAtQFaQevg7mzekaEFUArT+I/0quqDXA+L7K95hMWJlzwMEXe7d1CDBvKNPVm0RZ7uJYZBVw32900QlBYeFrkV0W2GMKbLayE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [142.133.60.138] (192.75.88.130) by DM6PR15MB2395.namprd15.prod.outlook.com (2603:10b6:5:8d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.18; Fri, 14 Sep 2018 18:26:26 +0000 Subject: Re: [PATCH v3 PR gdb/16841] virtual inheritance via typedef cannot find base To: Weimin Pan , References: <1536800471-78975-1-git-send-email-weimin.pan@oracle.com> From: Simon Marchi CC: Tom Tromey Message-ID: <136d54d3-7ee2-6640-5858-10831f53b8b1@ericsson.com> Date: Fri, 14 Sep 2018 18:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1536800471-78975-1-git-send-email-weimin.pan@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00458.txt.bz2 On 2018-09-12 09:01 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, 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(). > > Tested on amd64-linux-gnu. No regressions. I have some last nits about the test, but I'd like Tom to give the final approval, since he clearly knows this stuff better than I do. If everything is fine with him, then there is no need to post a new version, just fix it up and push. > --- > gdb/ChangeLog | 7 +++ > gdb/testsuite/ChangeLog | 6 +++ > gdb/testsuite/gdb.cp/virtbase2.cc | 46 +++++++++++++++++++++ > gdb/testsuite/gdb.cp/virtbase2.exp | 78 ++++++++++++++++++++++++++++++++++++ > gdb/valops.c | 63 ++++++++++++++++++++++++++++- > 5 files changed, 199 insertions(+), 1 deletions(-) > create mode 100644 gdb/testsuite/gdb.cp/virtbase2.cc > create mode 100644 gdb/testsuite/gdb.cp/virtbase2.exp > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index c47c111..9cbd8ca 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,10 @@ > +2018-09-12 Weimin Pan > + > + PR gdb/16841 > + * valops.c (get_virtual_base_offset): New function. > + (value_struct_elt_for_reference): Use it to get virtual base offset > + and add it in calculating class member address. > + > 2018-06-29 Pedro Alves > > * gdb/amd64-tdep.h (amd64_create_target_description): Add > diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog > index 93c849c..46f16d7 100644 > --- a/gdb/testsuite/ChangeLog > +++ b/gdb/testsuite/ChangeLog > @@ -1,3 +1,9 @@ > +2018-09-12 Weimin Pan > + > + PR gdb/16841 > + * gdb.cp/virtbase2.cc: New file. > + * gdb.cp/virtbase2.exp: New file. > + > 2018-06-29 Pedro Alves > > * gdb.threads/names.exp: Adjust expected "info threads" output. > diff --git a/gdb/testsuite/gdb.cp/virtbase2.cc b/gdb/testsuite/gdb.cp/virtbase2.cc > new file mode 100644 > index 0000000..60c95c4 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/virtbase2.cc > @@ -0,0 +1,46 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2018 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +struct superbase { > + int x; > + superbase () : x(22) {} > +}; > + > +struct base : superbase { > + int i; > + double d; > + base() : i(55), d(6.6) {} > +}; > + > +typedef base tbase; > +struct derived: virtual tbase > +{ > + void func_d() { } > +}; > + > +struct foo: virtual derived > +{ > + void func_f() { } > +}; > + > +int main() > +{ > + derived().func_d(); > + foo().func_f(); > +} > + > + Remove the trailing empty lines here, git shows a warning when applying the patch: Applying: virtual inheritance via typedef cannot find base Using index info to reconstruct a base tree... M gdb/ChangeLog M gdb/testsuite/ChangeLog M gdb/valops.c .git/rebase-apply/patch:90: new blank line at EOF. + warning: 1 line adds whitespace errors. > diff --git a/gdb/testsuite/gdb.cp/virtbase2.exp b/gdb/testsuite/gdb.cp/virtbase2.exp > new file mode 100644 > index 0000000..4c14419 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/virtbase2.exp > @@ -0,0 +1,78 @@ > +# Copyright 2018 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Make sure printing virtual base class data member works correctly (PR16841) > + > +if { [skip_cplus_tests] } { continue } > + > +standard_testfile .cc > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { > + return -1 > +} > + > +if {![runto_main]} then { > + perror "couldn't run to main" > + continue > +} > +> +proc make_scope_list { scopes } { Please add a comment for this proc, since it's not very intuitive. Here's a suggestion: # From a list of nested scopes, generate all possible ways of accessing something # in those scopes. For example, with the argument {foo bar baz}, this proc will # return: # - {} (empty string) # - baz:: # - bar:: # - bar::baz:: # - foo:: # - foo::baz:: # - foo::bar:: # - foo::bar::baz:: Thanks! Simon