From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57113 invoked by alias); 15 Jun 2018 23:45:47 -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 55982 invoked by uid 89); 15 Jun 2018 23:45:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=Internal, 2018-05-29, 20180529 X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Jun 2018 23:45:27 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5FNiaUg059278 for ; Fri, 15 Jun 2018 23:45:19 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2jk0xrjnq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 15 Jun 2018 23:45:19 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5FNjI7g027705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 15 Jun 2018 23:45:18 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5FNjHfm017106 for ; Fri, 15 Jun 2018 23:45:17 GMT Received: from localhost.us.oracle.com (/10.211.15.129) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Jun 2018 16:45:17 -0700 From: Weimin Pan To: gdb-patches@sourceware.org Subject: [PATCH PR gdb/16841] virtual inheritance via typedef cannot find base Date: Fri, 15 Jun 2018 23:45:00 -0000 Message-Id: <1529106313-11806-1-git-send-email-weimin.pan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8925 signatures=668702 X-SW-Source: 2018-06/txt/msg00414.txt.bz2 Fix failure to find member of a typedef base class The test case below demonstrates the problem, as described in this PR's Comment 5: typedef struct { int x; } A; struct C : A { int y; }; int main() { C c; return 55; } $ gdb a.out (gdb) ptype C::x Internal error: non-aggregate type to value_struct_elt_for_reference In value_struct_elt_for_reference(), need to call check_typedef() on the aggregate type to handle the case of *curtype being ptr->typedef. Tested on x86_64-linux. No regressions. --- gdb/ChangeLog | 6 +++++ gdb/testsuite/ChangeLog | 6 +++++ gdb/testsuite/gdb.cp/typedef-base-ptype.cc | 30 +++++++++++++++++++++++ gdb/testsuite/gdb.cp/typedef-base-ptype.exp | 37 +++++++++++++++++++++++++++++ gdb/valops.c | 2 +- 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.cp/typedef-base-ptype.cc create mode 100644 gdb/testsuite/gdb.cp/typedef-base-ptype.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ff2f145..99a3175 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-06-12 Weimin Pan + + PR gdb/16841 + * valops.c (value_struct_elt_for_reference): Call check_typedef on + aggregate type to get its real type before accessing it. + 2018-05-29 Weimin Pan * minsyms.h (lookup_minimal_symbol_and_objfile): Remove declaration. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b2938b1..78771d3 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-06-12 Weimin Pan + + PR gdb/16841 + * gdb/testsuite/gdb.cp/typedef-base-ptype.cc: New file. + * gdb/testsuite/gdb.cp/typedef-base-ptype.exp: New file. + 2018-05-24 Andrew Burgess PR gdb/23203 diff --git a/gdb/testsuite/gdb.cp/typedef-base-ptype.cc b/gdb/testsuite/gdb.cp/typedef-base-ptype.cc new file mode 100644 index 0000000..bfbcc4a --- /dev/null +++ b/gdb/testsuite/gdb.cp/typedef-base-ptype.cc @@ -0,0 +1,30 @@ +/* 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 . */ + +typedef struct { + int x; +} A; + +struct C : A { + int y; +}; + +int main() +{ + C c; + return 55; +} diff --git a/gdb/testsuite/gdb.cp/typedef-base-ptype.exp b/gdb/testsuite/gdb.cp/typedef-base-ptype.exp new file mode 100644 index 0000000..e588fd3 --- /dev/null +++ b/gdb/testsuite/gdb.cp/typedef-base-ptype.exp @@ -0,0 +1,37 @@ +# 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 . + +if { [skip_cplus_tests] } { continue } + +standard_testfile .cc + +if [get_compiler_info "c++"] { + return -1 +} + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { + return -1 +} + +clean_restart $testfile + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +gdb_test "ptype C::x" \ + "type = int" \ + "ptype typedef base struct member" diff --git a/gdb/valops.c b/gdb/valops.c index 62a86c0..3970a25 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3343,7 +3343,7 @@ value_struct_elt_for_reference (struct type *domain, int offset, int want_address, enum noside noside) { - struct type *t = curtype; + struct type *t = check_typedef (curtype); int i; struct value *v, *result; -- 1.8.3.1