From patchwork Sun Jan 28 16:28:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84844 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 1A1FD3858436 for ; Sun, 28 Jan 2024 16:29:12 +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 B3A763858C2D for ; Sun, 28 Jan 2024 16:28:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3A763858C2D 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 B3A763858C2D 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=1706459292; cv=none; b=lmZ/xwTxkCzdGs+Qwr5HD44NIKSKdNPLTul3j68TSy0RsBdkyUFLdgH0rVsCME9F7F3+Yb7UuKseGyWtXwmMOsoC84UiRDx02LNeQDAcHLb1iQnuMX2wk6Ivr2x1aBnY6ZSixvf/QBlLWhpR9P2khWZE5yc5vTM1xPp8Zz+N6s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459292; c=relaxed/simple; bh=g3dtbcGOYBGlxtm/iEksiPaZQwlOVISoalsH4vx8C0k=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=tV3C7CriEShhzd36tl1pmVNg2HVsZ8+Q5te2S0r7HjetfFu+jun/ygU1qDvC8kBqIh+I5tljqWD1BJzMrQFuWzBBbUdmdruPXpe4VfjIhx9b5q7gv4gpmJGECa4ax6gIKk01PIvhiOy7PkzW6a9H4RIEH3/YbNOyi7TBB0HumQ0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6008a.ext.cloudfilter.net ([10.0.30.227]) by cmsmtp with ESMTPS id TxH2rFrrq9gG6U80wr3j30; Sun, 28 Jan 2024 16:28:10 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id U80vrdoQtZKctU80vr1V7U; Sun, 28 Jan 2024 16:28:09 +0000 X-Authority-Analysis: v=2.4 cv=a+kjSGeF c=1 sm=1 tr=0 ts=65b68099 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=Y90XMCjnGtJK9GHMgUAA:9 a=QEXdDO2ut3YA:10 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=NXrThf5+QPczUK9M6hlmhEFC2ejr+DlmiXvmBMvAse4=; b=yBT/k1FHzf4Kdj2lalcpwZ55D1 PkK8UAL9R+xBDa+3mBNH312Z2ykP0k/+lmtioeu4vSXjgOpGO73fpy/hU9izyoOs8PyU7UI2MIZvV 0TxeXGk0cvyKj/91xfFbZ+IiG; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:36512 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 1rU80u-003tVN-37 for gdb-patches@sourceware.org; Sun, 28 Jan 2024 09:28:09 -0700 From: Tom Tromey Date: Sun, 28 Jan 2024 09:28:06 -0700 Subject: [PATCH 2/5] Capture directory in index_cache_store_context MIME-Version: 1.0 Message-Id: <20240128-pr-31262-index-cache-race-v1-2-4fe53c5265e3@tromey.com> References: <20240128-pr-31262-index-cache-race-v1-0-4fe53c5265e3@tromey.com> In-Reply-To: <20240128-pr-31262-index-cache-race-v1-0-4fe53c5265e3@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.68.157 X-Source-L: No X-Exim-ID: 1rU80u-003tVN-37 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net ([192.168.0.21]) [97.122.68.157]:36512 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: MS4xfDPOl1XrIsSUOG/FUTCgJpd+aX+8kHO1SUKnv6PY3H2LCDqMDnAqGe0aeSvIkhLBvOrjZFkXqfoBT+nHgWCPvSx5koJknWqOOYzSRzXYdUpj8xm3v/CU WnbBnk0tIYOn2Bs2nQrz7BYFQh0bFP+ZF+aSaM0P49i4nvCfHFrss7IpEO/Mt4F/+JGn24lP6WKVZP7FcV4M/fkoWMAjwmvs3mI= X-Spam-Status: No, score=-3022.7 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 I noticed that index_cache_store_context captures the 'enabled' setting, but not the index cache directory. This patch makes this change, which avoids a possible race -- with background reading, the user could possibly change this directory at the exact moment the writer examines the variable. --- gdb/dwarf2/index-cache.c | 9 +++++---- gdb/dwarf2/index-cache.h | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 645e36c66f7..a269eb46a36 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -90,7 +90,8 @@ index_cache::disable () index_cache_store_context::index_cache_store_context (const index_cache &ic, dwarf2_per_bfd *per_bfd) - : m_enabled (ic.enabled ()) + : m_enabled (ic.enabled ()), + m_dir (ic.m_dir) { if (!m_enabled) return; @@ -124,7 +125,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, m_dwz_build_id_str = build_id_to_string (dwz_build_id); } - if (ic.m_dir.empty ()) + if (m_dir.empty ()) { warning (_("The index cache directory name is empty, skipping store.")); m_enabled = false; @@ -134,7 +135,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, try { /* Try to create the containing directory. */ - if (!mkdir_recursive (ic.m_dir.c_str ())) + if (!mkdir_recursive (m_dir.c_str ())) { warning (_("index cache: could not make cache directory: %s"), safe_strerror (errno)); @@ -170,7 +171,7 @@ index_cache::store (dwarf2_per_bfd *per_bfd, /* Write the index itself to the directory, using the build id as the filename. */ - write_dwarf_index (per_bfd, m_dir.c_str (), + write_dwarf_index (per_bfd, ctx.m_dir.c_str (), ctx.m_build_id_str.c_str (), dwz_build_id_ptr, dw_index_kind::GDB_INDEX); } diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index 079ed412d2e..f66f72caea1 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -48,6 +48,9 @@ struct index_cache_store_context /* Captured value of enabled (). */ bool m_enabled; + /* Captured value of index cache directory. */ + std::string m_dir; + /* Captured value of build id. */ std::string m_build_id_str;