From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.115]) by sourceware.org (Postfix) with ESMTPS id 3063B394201D for ; Sun, 21 Feb 2021 03:16:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3063B394201D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway32.websitewelcome.com (Postfix) with ESMTP id A45A92ABABD for ; Sat, 20 Feb 2021 21:16:50 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id DfEol3MWpiQiZDfEolL2eM; Sat, 20 Feb 2021 21:16:50 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=soN7/4j8wVCEzxCCxbbEEoJbbp61nAVvJGuWtMoxOg0=; b=uOwFoYzFgSdyMex9vk/SLBm8Wv md6G/A2ZJ5b28hJXWmPGrXG4LMEgbV72vsb8u4+DMuoNdUVvKakJlI9SS8GXxd1EYyOJK2gnU0bhm UcbC4QZje4Q+A2eMhfF8Yk1EX; Received: from 97-122-70-152.hlrn.qwest.net ([97.122.70.152]:56692 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lDfEo-001OUW-Er; Sat, 20 Feb 2021 20:16:50 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/5] Avoid crash on missing dwz file Date: Sat, 20 Feb 2021 20:16:45 -0700 Message-Id: <20210221031647.949270-4-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210221031647.949270-1-tom@tromey.com> References: <20210221031647.949270-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.152 X-Source-L: No X-Exim-ID: 1lDfEo-001OUW-Er X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-152.hlrn.qwest.net (localhost.localdomain) [97.122.70.152]:56692 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Sun, 21 Feb 2021 03:16:52 -0000 If DWARF contains a reference to a "dwz" file, but there is no .gnu_debugaltlink section, then gdb will crash. This happens because dwarf2_get_dwz_file will return NULL, but some callers do not expect this. This patch changes dwarf2_get_dwz_file so that callers can require a dwz file. Then, it updates the callers that are attempting to process references to the dwz file to require one. gdb/ChangeLog 2021-02-20 Tom Tromey * dwarf2/read.h (dwarf2_get_dwz_file): Add 'require' parameter. * dwarf2/read.c (dwarf2_get_dwz_file): Add 'require' parameter. (get_abbrev_section_for_cu, read_attribute_value) (get_debug_line_section): Update. * dwarf2/macro.c (dwarf_decode_macro_bytes): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/dwarf2/macro.c | 6 ++++-- gdb/dwarf2/read.c | 14 +++++++++----- gdb/dwarf2/read.h | 13 ++++++++----- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index afe2f91168b..2ecebe6173c 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -509,7 +509,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, || macinfo_type == DW_MACRO_undef_sup || section_is_dwz) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, + true); body = dwz->read_string (objfile, str_offset); } @@ -693,7 +694,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, if (macinfo_type == DW_MACRO_import_sup) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, + true); dwz->macro.read (objfile); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 0347f91947e..6a755f716d1 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2279,7 +2279,7 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid, /* See dwarf2read.h. */ struct dwz_file * -dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) +dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) { bfd_size_type buildid_len_arg; size_t buildid_len; @@ -2295,7 +2295,11 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd) if (data == NULL) { if (bfd_get_error () == bfd_error_no_error) - return NULL; + { + if (!require) + return nullptr; + error (_("could not read '.gnu_debugaltlink' section")); + } error (_("could not read '.gnu_debugaltlink' section: %s"), bfd_errmsg (bfd_get_error ())); } @@ -6300,7 +6304,7 @@ get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) dwarf2_per_bfd *per_bfd = this_cu->per_bfd; if (this_cu->is_dwz) - abbrev = &dwarf2_get_dwz_file (per_bfd)->abbrev; + abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev; else abbrev = &per_bfd->abbrev; @@ -20515,7 +20519,7 @@ read_attribute_value (const struct die_reader_specs *reader, /* FALLTHROUGH */ case DW_FORM_GNU_strp_alt: { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true); LONGEST str_offset = cu_header->read_offset (abfd, info_ptr, &bytes_read); @@ -21113,7 +21117,7 @@ get_debug_line_section (struct dwarf2_cu *cu) section = &cu->dwo_unit->dwo_file->sections.line; else if (cu->per_cu->is_dwz) { - dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true); section = &dwz->line; } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index d2bae5a7ee8..86ac6b50cc0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -633,11 +633,14 @@ struct signatured_type struct dwo_unit *dwo_unit; }; -/* Open the separate '.dwz' debug file, if needed. Return NULL if - there is no .gnu_debugaltlink section in the file. Error if there - is such a section but the file cannot be found. */ - -extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd); +/* Open the separate '.dwz' debug file, if needed. If there is no + .gnu_debugaltlink section in the file, then the result depends on + REQUIRE: if REQUIRE is true, then error; if REQUIRE is false, + return NULL. Always error if there is such a section but the file + cannot be found. */ + +extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, + bool require = false); /* Return the type of the DIE at DIE_OFFSET in the CU named by PER_CU. */ -- 2.26.2