From patchwork Sun Jun 26 17:20:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 13376 Received: (qmail 56957 invoked by alias); 26 Jun 2016 17:21:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 56943 invoked by uid 89); 26 Jun 2016 17:21:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=disregard, pdi, life X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sun, 26 Jun 2016 17:21:20 +0000 Received: (qmail 11926 invoked by uid 0); 26 Jun 2016 17:21:18 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy5.mail.unifiedlayer.com with SMTP; 26 Jun 2016 17:21:18 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id BVMD1t0062f2jeq01VMGdK; Sun, 26 Jun 2016 11:21:17 -0600 X-Authority-Analysis: v=2.1 cv=OPe0g0qB c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=PnD2wP_eR3oA:10 a=DfiYhpa6zqsA:10 a=pD_ry4oyNxEA:10 a=zstS-IiYAAAA:8 a=NEAV23lmAAAA:8 a=qjaK5rJXg6NlAnZBeBUA:9 a=nhjDBQuiAFebn6ZU:21 a=AlZLt2mI4fG44u9t:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=Bn2pgwyD2vrAyMmN8A2t:22 Received: from [67.176.62.53] (port=40928 helo=bapiya.hsd1.co.comcast.net) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1bHDkA-0007hc-9C; Sun, 26 Jun 2016 11:21:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] PR rust/20162 - fix gdb regressions caused by rust 1.10 Date: Sun, 26 Jun 2016 11:20:56 -0600 Message-Id: <1466961656-26197-1-git-send-email-tom@tromey.com> X-Identified-User: {36111:box522.bluehost.com:elynrobi:tromey.com} {sentby:smtp auth 67.176.62.53 authed with tom+tromey.com} X-Exim-ID: 1bHDkA-0007hc-9C X-Source-Sender: (bapiya.hsd1.co.comcast.net) [67.176.62.53]:40928 X-Source-Auth: tom+tromey.com X-Email-Count: 0 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== PR rust/20162 started life as a reminder to test gdb with versions of rust after 1.8; but now concerns some gdb regressions seen with rust 1.10 ("beta") and 1.11 ("nightly"). The failures turn out to be a discrepancy between how rustc emits DWARF and how gdb interprets it. In particular, rustc will emit DWARF like: <2>: Abbrev Number: 9 (DW_TAG_structure_type) DW_AT_name : (indirect string, offset: 0x46a): HasMethods DW_AT_byte_size : 4 ... <3>: Abbrev Number: 11 (DW_TAG_subprogram) ... DW_AT_name : (indirect string, offset: 0x514f): new gdb wants to see a separate top-level DW_TAG_subprogram that refers to this one via DW_AT_specification; but rustc doesn't emit one. By my reading of DWARF 4 5.5.7, this is ok, and gdb is incorrect here. Fixing this involved a new case in scan_partial_symbols, and then a further change in process_structure_scope to account for the fact that, in Rust, such functions are not methods and should not be attached to the structure type. Next, it turns out that rust is emitting bad values for DW_AT_linkage_name, e.g.: DW_AT_linkage_name: (indirect string, offset: 0x422): _ZN7methods8{{impl}}3newE The the "{{impl}}" stuff is apparently some side effect of a change to the compiler's internal representation. Oops! This also had a simple fix -- disregard these mangled names. With these changes, there are no regressions in the gdb Rust tests with either 1.10 or 1.11. 1.9, the stable release, is still pretty broken, but I think there's nothing much to do about that. These changes are a bit hackish, but no worse, I think, than other kinds of quirk handling already done in the DWARF parser. I have reported all the rustc bugs upstream. I plan to remove these hacks from gdb some suitable time after they have been fixed in released versions of Rust. 2016-06-26 Tom Tromey PR rust/20162: * dwarf2read.c (scan_partial_symbols) : Call scan_partial_symbols for children when reading a Rust CU. (dwarf2_physname): Ignore invalid DW_AT_linkage_name generated by rustc. (process_structure_scope) : Call read_func_scope for Rust. --- gdb/ChangeLog | 10 ++++++++++ gdb/dwarf2read.c | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e98a565..7db8046 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2016-06-26 Tom Tromey + + PR rust/20162: + * dwarf2read.c (scan_partial_symbols) : + Call scan_partial_symbols for children when reading a Rust CU. + (dwarf2_physname): Ignore invalid DW_AT_linkage_name generated by + rustc. + (process_structure_scope) : Call + read_func_scope for Rust. + 2016-06-25 Tom Tromey * rust-lang.c (rust_get_disr_info, rust_print_type): Fix diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6658a38..8d5a83f 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -6695,6 +6695,9 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, { add_partial_symbol (pdi, cu); } + if (cu->language == language_rust && pdi->has_children) + scan_partial_symbols (pdi->die_child, lowpc, highpc, + set_addrmap, cu); break; case DW_TAG_enumeration_type: if (!pdi->is_declaration) @@ -8733,6 +8736,12 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) if (mangled == NULL) mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); + /* rustc emits invalid values for DW_AT_linkage_name. Ignore these. + See https://github.com/rust-lang/rust/issues/32925. */ + if (cu->language == language_rust && mangled != NULL + && strchr (mangled, '{') != NULL) + mangled = NULL; + /* DW_AT_linkage_name is missing in some cases - depend on what GDB has computed. */ if (mangled != NULL) @@ -13315,8 +13324,16 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) } else if (child_die->tag == DW_TAG_subprogram) { - /* C++ member function. */ - dwarf2_add_member_fn (&fi, child_die, type, cu); + /* Rust doesn't have member functions in the C++ sense. + However, it does emit ordinary functions as children + of a struct DIE. */ + if (cu->language == language_rust) + read_func_scope (child_die, cu); + else + { + /* C++ member function. */ + dwarf2_add_member_fn (&fi, child_die, type, cu); + } } else if (child_die->tag == DW_TAG_inheritance) {