aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeimin Pan <weimin.pan@oracle.com>2018-06-18 21:15:13 +0000
committerWeimin Pan <weimin.pan@oracle.com>2018-06-18 21:31:55 +0000
commitbf2977b5f3d25779cdc06ba79c05244d70bd8b59 (patch)
tree2df84ac75e329116c9438e67178b160785f36f9c
parentc4eb05ff9a3739378f8a846751da4d0e221b4c8c (diff)
downloadgdb-bf2977b5f3d25779cdc06ba79c05244d70bd8b59.zip
gdb-bf2977b5f3d25779cdc06ba79c05244d70bd8b59.tar.gz
gdb-bf2977b5f3d25779cdc06ba79c05244d70bd8b59.tar.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.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.cp/typedef-base.cc30
-rw-r--r--gdb/testsuite/gdb.cp/typedef-base.exp39
-rw-r--r--gdb/valops.c2
5 files changed, 84 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4fc6cf5..7b108bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -970,6 +970,12 @@
* symfile.c (addr_info_make_relative): Likewise.
* thread.c (value_in_thread_stack_temporaries): Likewise.
+2018-06-12 Weimin Pan <weimin.pan@oracle.com>
+
+ 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 <weimin.pan@oracle.com>
* minsyms.h (lookup_minimal_symbol_and_objfile): Remove declaration.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 173ee2b..a812061 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,4 @@
+<<<<<<< HEAD
2018-06-18 Tom de Vries <tdevries@suse.de>
* gdb.ada/bp_inlined_func.exp: Allow 5 breakpoint locations.
@@ -95,6 +96,13 @@
* gdb.base/endian.exp: New test.
* gdb.base/endian.c: New test source.
+=======
+2018-06-12 Weimin Pan <weimin.pan@oracle.com>
+
+ PR gdb/16841
+ * gdb.cp/typedef-base.cc: New file.
+ * gdb.cp/typedef-base.exp: New file.
+>>>>>>> Fix failure to find member of a typedef base class
2018-05-24 Andrew Burgess <andrew.burgess@embecosm.com>
diff --git a/gdb/testsuite/gdb.cp/typedef-base.cc b/gdb/testsuite/gdb.cp/typedef-base.cc
new file mode 100644
index 0000000..f54ed10
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/typedef-base.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 <http://www.gnu.org/licenses/>. */
+
+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.exp b/gdb/testsuite/gdb.cp/typedef-base.exp
new file mode 100644
index 0000000..2e8ca8c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/typedef-base.exp
@@ -0,0 +1,39 @@
+# 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 <http://www.gnu.org/licenses/>.
+#
+# Make sure that inheritance through a typedef is well handled.
+
+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 9337457..9bdbf22 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;