From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AOT1OYR4GWDWLwAAWB0awg (envelope-from ) for ; Tue, 02 Feb 2021 11:06:28 -0500 Received: by simark.ca (Postfix, from userid 112) id EB3801EF80; Tue, 2 Feb 2021 11:06:28 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 919621E590 for ; Tue, 2 Feb 2021 11:06:27 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05BCB398882D; Tue, 2 Feb 2021 16:06:27 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 90CE4398882D for ; Tue, 2 Feb 2021 16:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 90CE4398882D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 90003B04C for ; Tue, 2 Feb 2021 16:06:23 +0000 (UTC) Date: Tue, 2 Feb 2021 17:06:21 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Handle missing aranges with debug_names Message-ID: <20210202160620.GA23023@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-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.dwarf2/template-specification-full-name.exp with target board cc-with-debug-names, we get: ... (gdb) print apply^M $1 = {void (void)} 0x4004a7 ()>^M Warning: the current language does not match this frame.^M (gdb) FAIL: gdb.dwarf2/template-specification-full-name.exp: print apply ... The current language is supposed to be set to c++, but that fails because we fail to find the CU corresponding to the pc in main. This is due to the fact that the dwarf test-case does not provide a .debug_aranges section for the CU containing main. Fix this conservatively by: - skipping the .debug_aranges section if missing CUs are detected, and - skipping the .debug_names section if the .debug_aranges reading failed. Tested on x86_64-linux with target board cc-with-debug-names. Any comments? Thanks, - Tom [gdb/symtab] Handle missing aranges with debug_names gdb/ChangeLog: 2021-02-02 Tom de Vries PR symtab/27298 * dwarf2/read.c (create_addrmap_from_aranges): Detect and handle missing and duplicate CUs. (dwarf2_read_debug_names): Handle failure to read .debug_ranges. gdb/testsuite/ChangeLog: 2021-02-02 Tom de Vries PR symtab/27298 * lib/gdb.exp (gdb_load_no_complaints): Make complaints detection more specific. --- gdb/dwarf2/read.c | 32 ++++++++++++++++++++++++++++++++ gdb/testsuite/lib/gdb.exp | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 872b4e7bcf2..625d25a4e26 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -82,6 +82,7 @@ #include #include #include +#include #include "gdbsupport/selftest.h" #include "rust-lang.h" #include "gdbsupport/pathstuff.h" @@ -2870,6 +2871,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, dwarf2_per_cu_data *, gdb::hash_enum> debug_info_offset_to_per_cu; + std::unordered_set> cus; for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units) { const auto insertpair @@ -2881,6 +2883,7 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, objfile_name (objfile), sect_offset_str (per_cu->sect_off)); return; } + cus.emplace (per_cu->sect_off); } section->read (objfile); @@ -2942,6 +2945,19 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, } dwarf2_per_cu_data *const per_cu = per_cu_it->second; + auto cu_it = cus.find (sect_offset (debug_info_offset)); + if (cu_it == cus.end ()) + { + warning (_("Section .debug_aranges in %s entry at offset %s:" + " duplicate debug_info_offset %s," + " ignoring .debug_aranges."), + objfile_name (objfile), + plongest (entry_addr - section->buffer), + pulongest (debug_info_offset)); + return; + } + cus.erase (cu_it); + const uint8_t address_size = *addr++; if (address_size < 1 || address_size > 8) { @@ -3012,6 +3028,13 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, } } + if (!cus.empty ()) + { + warning (_("Section .debug_aranges does not contain entries" + " for all CUs, ignoring .debug_aranges.")); + return; + } + objfile->partial_symtabs->psymtabs_addrmap = addrmap_create_fixed (mutable_map, objfile->partial_symtabs->obstack ()); } @@ -5424,6 +5447,15 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) } create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges); + if (objfile->partial_symtabs->psymtabs_addrmap == nullptr) + { + warning (_("Could not read '.debug_aranges' section;" + " skipping .debug_names.")); + /* Clear to prevent asserts. */ + per_objfile->per_bfd->all_comp_units.clear (); + per_objfile->per_bfd->all_type_units.clear (); + return false; + } per_bfd->debug_names_table = std::move (map); per_bfd->using_index = 1; diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 53ac9f1408c..dbbf239dab9 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5124,8 +5124,8 @@ proc gdb_load_no_complaints { arg } { gdb_load $arg # Verify that there were no complaints. - set re "^Reading symbols from \[^\r\n\]*\r\n$gdb_prompt $" - gdb_assert {[regexp $re $gdb_file_cmd_msg]} "No complaints" + set re "\r\nDuring symbol reading: " + gdb_assert {![regexp $re $gdb_file_cmd_msg]} "No complaints" # Restore saved setting of complaints. gdb_test_no_output "set complaints $save" ""