aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2020-03-07 16:33:45 +0100
committerTom de Vries <tdevries@suse.de>2020-03-07 16:33:45 +0100
commite4003a3495bbdbcb28b3a87467a12b95d30e3b8a (patch)
treef3947838f84cdcfe891e29714591ced936e86f06
parente8932576355851be8bac0b0b86a3be4f2005e47f (diff)
downloadgdb-e4003a3495bbdbcb28b3a87467a12b95d30e3b8a.zip
gdb-e4003a3495bbdbcb28b3a87467a12b95d30e3b8a.tar.gz
gdb-e4003a3495bbdbcb28b3a87467a12b95d30e3b8a.tar.bz2
[gdb] Support anonymous typedef generated by gcc -feliminate-dwarf2-dups
Gcc supports an option -feliminate-dwarf2-dups (up until gcc-7, removed in gcc-8). When running tests with target board unix/-feliminate-dwarf2-dups, we run into: ... (gdb) PASS: gdb.ada/arraydim.exp: print m'length(3) ptype global_3dim_for_gdb_testing^M type = array (Unexpected type in ada_discrete_type_low_bound.^M (gdb) FAIL: gdb.ada/arraydim.exp: ptype global_3dim_for_gdb_testing ... The DWARF for the variable global_3dim_for_gdb_testing looks as follows: ... <0><824>: Abbrev Number: 1 (DW_TAG_compile_unit) <825> DW_AT_name : src/gdb/testsuite/gdb.ada/arraydim/inc.c <1><832>: Abbrev Number: 2 (DW_TAG_array_type) <833> DW_AT_type : <0x874> <2><837>: Abbrev Number: 3 (DW_TAG_subrange_type) <838> DW_AT_type : <0x84a> <83c> DW_AT_upper_bound : 0 <2><83d>: Abbrev Number: 3 (DW_TAG_subrange_type) <83e> DW_AT_type : <0x84a> <842> DW_AT_upper_bound : 1 <2><843>: Abbrev Number: 3 (DW_TAG_subrange_type) <844> DW_AT_type : <0x84a> <848> DW_AT_upper_bound : 2 <2><849>: Abbrev Number: 0 <1><84a>: Abbrev Number: 4 (DW_TAG_typedef) <84b> DW_AT_type : <0x86d> <1><84f>: Abbrev Number: 0 <0><85b>: Abbrev Number: 5 (DW_TAG_compile_unit) <861> DW_AT_name : src/gdb/testsuite/gdb.ada/arraydim/inc.c <1><86d>: Abbrev Number: 6 (DW_TAG_base_type) <86e> DW_AT_byte_size : 8 <86f> DW_AT_encoding : 7 (unsigned) <870> DW_AT_name : long unsigned int <1><874>: Abbrev Number: 7 (DW_TAG_base_type) <875> DW_AT_byte_size : 4 <876> DW_AT_encoding : 5 (signed) <877> DW_AT_name : int <1><87b>: Abbrev Number: 8 (DW_TAG_variable) <87c> DW_AT_name : global_3dim_for_gdb_testing <882> DW_AT_type : <0x832> <886> DW_AT_external : 1 ... The DWARF contains an anonymous typedef at 0x84a, referring to 0x86d. Strictly speaking, the anonymous typedef is illegal DWARF, because a DW_TAG_typedef is defined to have an DW_AT_name attribute containing the name of the typedef as it appears in the source program. The DWARF reading code creates a corresponding type for this typedef, which goes on to confuse the code handling arrays. Rather than trying to support the type representing this anonymous typedef in all the locations where it causes problems, fix this by treating the anonymous typedef as a forwarder DIE in the DWARF reader. Tested on x86_64-linux, with target boards unix and unix/-feliminate-dwarf2-dups. This fixes ~85 failures for unix/-feliminate-dwarf2-dups. gdb/ChangeLog: 2020-03-07 Tom de Vries <tdevries@suse.de> * dwarf2/read.c (read_typedef): Treat anonymous typedef as forwarder DIE.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2/read.c10
2 files changed, 15 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9a25504..fca5648 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-07 Tom de Vries <tdevries@suse.de>
+
+ * dwarf2/read.c (read_typedef): Treat anonymous typedef as forwarder
+ DIE.
+
2020-03-07 Tom Tromey <tom@tromey.com>
* valops.c (value_literal_complex): Remove obsolete comment.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3556908..1d4397d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16816,6 +16816,16 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
sect_offset_str (die->sect_off), objfile_name (objfile));
TYPE_TARGET_TYPE (this_type) = NULL;
}
+ if (name == NULL)
+ {
+ /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
+ anonymous typedefs, which is, strictly speaking, invalid DWARF.
+ Handle these by just returning the target type, rather than
+ constructing an anonymous typedef type and trying to handle this
+ elsewhere. */
+ set_die_type (die, target_type, cu);
+ return target_type;
+ }
return this_type;
}