From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id EC6713858C5F for ; Fri, 4 Aug 2023 16:19:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC6713858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 53D1310044F53 for ; Fri, 4 Aug 2023 16:19:10 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id RxWAqvDSGIkmWRxWAqpo3d; Fri, 04 Aug 2023 16:19:10 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=S/wcfKgP c=1 sm=1 tr=0 ts=64cd24fe a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=UttIx32zK-AA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=rYVHNtv7FJUVqz7rEFoA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=W/3SpNBzqYOCIO+jhYNnPZjhzfYiN3TEED770vx92jQ=; b=Po2Uhcc/lMoUhAacmyAusHMGB9 GfBu0U6ieOJHv9L0R6rkmxbLHQkFwQr9ky9VOnc0qg7xsMxe4ffu/Mg1VCYOXL7fesRpsz3Fd8Ny2 4ySdrKqqdbnXi6g3/gz8xWKrg; Received: from 71-211-152-221.hlrn.qwest.net ([71.211.152.221]:34574 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qRxWA-001t5A-04; Fri, 04 Aug 2023 10:19:10 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Consolidate calls to bfd_set_cacheable Date: Fri, 4 Aug 2023 10:19:00 -0600 Message-ID: <20230804161900.384191-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 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: 71.211.152.221 X-Source-L: No X-Exim-ID: 1qRxWA-001t5A-04 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-152-221.hlrn.qwest.net (localhost.localdomain) [71.211.152.221]:34574 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.2 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I noticed that some spots in gdb call bfd_set_cacheable after opening a BFD. The BFD file cache is a bit odd. BFDs that are opened locally are unconditionally registered with the cache, and their underlying file descriptor will always be closed when bfd_cache_close_all is called. However, only "cacheable" BFDs will be eligible for reopening when needed -- and by default BFD decides that if a file descriptor is passed in, then it should not be cacheable. If a non-cacheable BFD's file descriptor is closed, there is no offical way to reopen it. gdb needs to call bfd_cache_close_all, because some systems cannot start an executable when it has an open file descriptor referencing it. However, gdb also will sometimes passes an open file descriptor to the various BFD open functions. And, due to lazy DWARF reading, gdb may also need to reopen these BFDs. Rather than having all the callers figure out when exactly to set the cacheable flag, I think it makes sense to consolidate this logic into the gdb_bfd.c wrapper functions. Regression tested on x86-64 Fedora 38. --- gdb/dwarf2/read.c | 1 - gdb/gdb_bfd.c | 5 +++++ gdb/machoread.c | 2 -- gdb/solib.c | 3 --- gdb/symfile.c | 3 --- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 61730f6481c..d5d405f780d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9184,7 +9184,6 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile, gnutarget, desc)); if (sym_bfd == NULL) return NULL; - bfd_set_cacheable (sym_bfd.get (), 1); if (!bfd_check_format (sym_bfd.get (), bfd_object)) return NULL; diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 17e454eb9fd..9227a6ce01e 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -564,6 +564,8 @@ gdb_bfd_open (const char *name, const char *target, int fd, if (abfd == NULL) return NULL; + bfd_set_cacheable (abfd, 1); + bfd_cache_debug_printf ("Creating new bfd %s for %s", host_address_to_string (abfd), bfd_get_filename (abfd)); @@ -877,6 +879,9 @@ gdb_bfd_fopen (const char *filename, const char *target, const char *mode, { bfd *result = bfd_fopen (filename, target, mode, fd); + if (result != nullptr) + bfd_set_cacheable (result, 1); + return gdb_bfd_ref_ptr::new_reference (result); } diff --git a/gdb/machoread.c b/gdb/machoread.c index daf62563754..5154d1a31a3 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -447,8 +447,6 @@ macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd, return; } - bfd_set_cacheable (abfd.get (), 1); - /* Read symbols table. */ storage = bfd_get_symtab_upper_bound (abfd.get ()); symbol_table = (asymbol **) xmalloc (storage); diff --git a/gdb/solib.c b/gdb/solib.c index 701efa85d1a..4f980e9365c 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -430,9 +430,6 @@ solib_bfd_fopen (const char *pathname, int fd) { gdb_bfd_ref_ptr abfd (gdb_bfd_open (pathname, gnutarget, fd)); - if (abfd != NULL && !gdb_bfd_has_target_filename (abfd.get ())) - bfd_set_cacheable (abfd.get (), 1); - if (abfd == NULL) { /* Arrange to free PATHNAME when the error is thrown. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index d28404070cd..1b46ec45f2e 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1762,9 +1762,6 @@ symfile_bfd_open (const char *name) error (_("`%s': can't open to read symbols: %s."), name, bfd_errmsg (bfd_get_error ())); - if (!gdb_bfd_has_target_filename (sym_bfd.get ())) - bfd_set_cacheable (sym_bfd.get (), 1); - if (!bfd_check_format (sym_bfd.get (), bfd_object)) error (_("`%s': can't read symbols: %s."), name, bfd_errmsg (bfd_get_error ())); -- 2.41.0