From patchwork Sun Nov 12 20:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 79661 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E0D33858421 for ; Sun, 12 Nov 2023 20:26:10 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id 87F023858D20 for ; Sun, 12 Nov 2023 20:25:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87F023858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 87F023858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699820736; cv=none; b=pKlS8QfoMdRVs8te69XDlW3a5BN9kUjhiiExLuWmM/YTtaICTWawKdglFl4XFlDnD0WNg0cYjzrp9hLMyxyL5LJ2rHk295eORPNJMYXtjM2jtPty3FC1xd3YUUDdrXJUMa+v/PNsShWaELXA4k3hV9sfzb4JKBHLTVYnJF9HN0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699820736; c=relaxed/simple; bh=sjfdqWikjRwBXyYtOp6U2TNXWp2FpBqohbY4AN+ACaw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BNgZiFEzzvpdUvpwHgIr4xsqJdCBXar7MWDdCsgfFfn92QAdaVdN+nN+goMTvLmVq4Z+pcNpjcglx71S0/t8wGeuhpJfo8OpZBmlq3dh/+5X0ioROgx5l8tOYpqUhyW/8ktEs7PUAY2uXS0vp21vHC9cXsK8DCxDIPQoxBigxg0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id 2DoYr9RwHWcCI2H1RrP2ha; Sun, 12 Nov 2023 20:25:33 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 2H1QrfEy21J282H1QrZzrl; Sun, 12 Nov 2023 20:25:32 +0000 X-Authority-Analysis: v=2.4 cv=Tqz1ORbh c=1 sm=1 tr=0 ts=655134bc a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=Qbun_eYptAEA:10 a=cLqGVXOHAAAA:8 a=HZhKZHtF7bVGL2gTaW8A:9 a=QEXdDO2ut3YA:10 a=YPgwqnNh2vws5ntuPRLs:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=SQPPpL8FIKaMhdUhIGD/9io6FC8mYFMfSxiH3yPqAFI=; b=fJ1DeA0orqun2EyL0YbTFC5XRQ 4nbWXudqjEl1CvuRuZTcJHtjoGXzxV5dNELgo7yCG8esMY0VGW+PR9vXQVbnaqHO1hRck8BzY2dNZ EZkYFp1wR3+nGU3pd2J+kYtJA; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:34540 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1r2H1P-000cUU-2b for gdb-patches@sourceware.org; Sun, 12 Nov 2023 13:25:31 -0700 From: Tom Tromey Date: Sun, 12 Nov 2023 13:25:39 -0700 Subject: [PATCH v2 02/18] Pre-read DWZ section data MIME-Version: 1.0 Message-Id: <20231112-t-bg-dwarf-reading-v2-2-70fb170012ba@tromey.com> References: <20231112-t-bg-dwarf-reading-v2-0-70fb170012ba@tromey.com> In-Reply-To: <20231112-t-bg-dwarf-reading-v2-0-70fb170012ba@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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.77.73 X-Source-L: No X-Exim-ID: 1r2H1P-000cUU-2b X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net ([192.168.0.21]) [97.122.77.73]:34540 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfHribbrpfczlNgJvhvHiN/B9i9yn4JkipStOu1mnm6EAkKbBmcpPxvwS5s27M9meNbNSnga0DO5GLxSYKv+A582TVhMIt1WOu87YcTW7q4JMpGjoZbDT 78xXzhznfpIh23oB/siNb7NMhOUAetZ0WpnkVPlBLCk8SHMxYDP/G0xqhc97Q1YXi/CmUicVGLCZd2099BGqdPatWmK8B0FFlD8= X-Spam-Status: No, score=-3024.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes the DWZ code to pre-read the section data and somewhat simplify the DWZ API. This makes it easier to add the bfd_cache_close call to the new dwarf2_read_dwz_file function -- after this is done, there shouldn't be a reason to keep the BFD's file descriptor open. --- gdb/dwarf2/dwz.c | 90 +++++++++++++++++++++++++----------------------------- gdb/dwarf2/dwz.h | 13 ++++++-- gdb/dwarf2/macro.c | 2 -- gdb/dwarf2/read.c | 8 +---- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index edd5b56d778..13f95801ebb 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -53,49 +53,35 @@ dwz_file::read_string (struct objfile *objfile, LONGEST str_offset) /* A helper function to find the sections for a .dwz file. */ static void -locate_dwz_sections (bfd *abfd, asection *sectp, dwz_file *dwz_file) +locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp, + dwz_file *dwz_file) { + dwarf2_section_info *sect = nullptr; + /* Note that we only support the standard ELF names, because .dwz is ELF-only (at the time of writing). */ if (dwarf2_elf_names.abbrev.matches (sectp->name)) - { - dwz_file->abbrev.s.section = sectp; - dwz_file->abbrev.size = bfd_section_size (sectp); - } + sect = &dwz_file->abbrev; else if (dwarf2_elf_names.info.matches (sectp->name)) - { - dwz_file->info.s.section = sectp; - dwz_file->info.size = bfd_section_size (sectp); - } + sect = &dwz_file->info; else if (dwarf2_elf_names.str.matches (sectp->name)) - { - dwz_file->str.s.section = sectp; - dwz_file->str.size = bfd_section_size (sectp); - } + sect = &dwz_file->str; else if (dwarf2_elf_names.line.matches (sectp->name)) - { - dwz_file->line.s.section = sectp; - dwz_file->line.size = bfd_section_size (sectp); - } + sect = &dwz_file->line; else if (dwarf2_elf_names.macro.matches (sectp->name)) - { - dwz_file->macro.s.section = sectp; - dwz_file->macro.size = bfd_section_size (sectp); - } + sect = &dwz_file->macro; else if (dwarf2_elf_names.gdb_index.matches (sectp->name)) - { - dwz_file->gdb_index.s.section = sectp; - dwz_file->gdb_index.size = bfd_section_size (sectp); - } + sect = &dwz_file->gdb_index; else if (dwarf2_elf_names.debug_names.matches (sectp->name)) - { - dwz_file->debug_names.s.section = sectp; - dwz_file->debug_names.size = bfd_section_size (sectp); - } + sect = &dwz_file->debug_names; else if (dwarf2_elf_names.types.matches (sectp->name)) + sect = &dwz_file->types; + + if (sect != nullptr) { - dwz_file->types.s.section = sectp; - dwz_file->types.size = bfd_section_size (sectp); + sect->s.section = sectp; + sect->size = bfd_section_size (sectp); + sect->read (objfile); } } @@ -190,20 +176,13 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid, /* See dwz.h. */ -struct dwz_file * -dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) +void +dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile) { bfd_size_type buildid_len_arg; size_t buildid_len; bfd_byte *buildid; - - if (per_bfd->dwz_file.has_value ()) - { - dwz_file *result = per_bfd->dwz_file->get (); - if (require && result == nullptr) - error (_("could not read '.gnu_debugaltlink' section")); - return result; - } + dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; /* This may query the user via the debuginfod support, so it may only be run in the main thread. */ @@ -219,11 +198,7 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) if (data == NULL) { if (bfd_get_error () == bfd_error_no_error) - { - if (!require) - return nullptr; - error (_("could not read '.gnu_debugaltlink' section")); - } + return; error (_("could not read '.gnu_debugaltlink' section: %s"), bfd_errmsg (bfd_get_error ())); } @@ -292,9 +267,28 @@ dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) (new struct dwz_file (std::move (dwz_bfd))); for (asection *sec : gdb_bfd_sections (result->dwz_bfd)) - locate_dwz_sections (result->dwz_bfd.get (), sec, result.get ()); + locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (), + sec, result.get ()); gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ()); + bfd_cache_close (result->dwz_bfd.get ()); + per_bfd->dwz_file = std::move (result); - return per_bfd->dwz_file->get (); +} + +/* See dwz.h. */ + +struct dwz_file * +dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) +{ + gdb_assert (!require || per_bfd->dwz_file.has_value ()); + + dwz_file *result = nullptr; + if (per_bfd->dwz_file.has_value ()) + { + result = per_bfd->dwz_file->get (); + if (require && result == nullptr) + error (_("could not read '.gnu_debugaltlink' section")); + } + return result; } diff --git a/gdb/dwarf2/dwz.h b/gdb/dwarf2/dwz.h index 5f61b5e1216..a427cda902d 100644 --- a/gdb/dwarf2/dwz.h +++ b/gdb/dwarf2/dwz.h @@ -65,13 +65,20 @@ struct dwz_file const char *read_string (struct objfile *objfile, LONGEST str_offset); }; -/* Open the separate '.dwz' debug file, if needed. If there is no +/* Return the separate '.dwz' debug file. 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. */ + return NULL. */ extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require = false); +/* Open the separate '.dwz' debug file, if needed. This just sets the + appropriate field in the per-BFD structure. If the DWZ file + exists, the relevant sections are read in as well. Throws an error + if the .gnu_debugaltlink section exists but the file cannot be + found. */ + +extern void dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile); + #endif /* GDB_DWARF2_DWZ_H */ diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index 78cce2d69eb..a354e894753 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -735,8 +735,6 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true); - dwz->macro.read (objfile); - include_section = &dwz->macro; include_bfd = include_section->get_bfd_owner (); include_mac_end = dwz->macro.buffer + dwz->macro.size; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f88e5023734..d277c21622f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3217,7 +3217,7 @@ dwarf2_initialize_objfile (struct objfile *objfile) main thread. */ try { - dwarf2_get_dwz_file (per_bfd); + dwarf2_read_dwz_file (per_objfile); } catch (const gdb_exception_error &err) { @@ -5134,12 +5134,6 @@ create_all_units (dwarf2_per_objfile *per_objfile) dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); if (dwz != NULL) { - /* Pre-read the sections we'll need to construct an index. */ - struct objfile *objfile = per_objfile->objfile; - dwz->abbrev.read (objfile); - dwz->info.read (objfile); - dwz->str.read (objfile); - dwz->line.read (objfile); read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1, types_htab, rcuh_kind::COMPILE);