Message ID | 20200307022544.GA2485@delia |
---|---|
State | New, archived |
Headers |
Received: (qmail 39420 invoked by alias); 7 Mar 2020 02:26:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 39411 invoked by uid 89); 7 Mar 2020 02:26:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=DW_TAG_typedef, dw_tag_typedef X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Mar 2020 02:26:01 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5D2F4B15A for <gdb-patches@sourceware.org>; Sat, 7 Mar 2020 02:25:47 +0000 (UTC) Date: Sat, 7 Mar 2020 03:25:45 +0100 From: Tom de Vries <tdevries@suse.de> To: gdb-patches@sourceware.org Subject: [PATCH][gdb] Support anonymous typedef generated by gcc -feliminate-dwarf2-dups Message-ID: <20200307022544.GA2485@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes |
Commit Message
Tom de Vries
March 7, 2020, 2:25 a.m. UTC
Hi, 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. OK for trunk? Thanks, - Tom [gdb] Support anonymous typedef generated by gcc -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. --- gdb/dwarf2/read.c | 5 +++++ 1 file changed, 5 insertions(+)
Comments
On 2020-03-06 9:25 p.m., Tom de Vries wrote: > Hi, > > 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. > > OK for trunk? > > Thanks, > - Tom > > [gdb] Support anonymous typedef generated by gcc -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. > > --- > gdb/dwarf2/read.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 3556908cf5..bd9fbd698d 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -16816,6 +16816,11 @@ 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) > + { > + set_die_type (die, target_type, cu); > + return target_type; > + } > return this_type; > } > > Hi Tom, That's fine with me, but please add a comment that explains: 1. Why would name be ever be NULL here (gcc <= 7 with that option produce invalid DWARF) 2. How we decide to handle it (drop the typedef, just use the type it points to) The future poor soul who will do refactoring in the DWARF reading code will appreciative it :). Thanks, Simon
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3556908cf5..bd9fbd698d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -16816,6 +16816,11 @@ 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) + { + set_die_type (die, target_type, cu); + return target_type; + } return this_type; }