From patchwork Sun Jan 28 16:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84846 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 1536F385842F for ; Sun, 28 Jan 2024 16:29:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 1031F3858D32 for ; Sun, 28 Jan 2024 16:28:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1031F3858D32 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 1031F3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459292; cv=none; b=SHYEyb1r+7DQABU36NbxenejtHPdOF/ux7iaGDx/l5CjCQ5DPee4ynZurpZPMBQHRFR5FnF0eW62SvIxBZXfZkckcyUw4DJOVrz90afQdcWxcwHdDY8sPrswmVFWxAUK+X/S7DJKwNWolfyLdmQoA9SDpDcqpmrJeY1QfZLEOWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459292; c=relaxed/simple; bh=TsZoGrV+ZVmqIxCC4WgM8UUqUoWqIG26ot2ccEyAycc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=osV5d9LpIHtvw9MgB6J9GHfDzIHx8QhoQbNdkKpan3bX3ZArxmFaqMxPSOh3Hsj0o++AQ8oPLZ+kWgMnC+uJNnda2o270E5Ue5BTEdn8/RGpsXzCUvWwcEyqslLMxqH7m0HTUm1bttpCFXnCRs5cu2SnPyMTSXCDmXe0fO2bufc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5009a.ext.cloudfilter.net ([10.0.29.176]) by cmsmtp with ESMTPS id TyD5rQjjy80oiU80wrP0dE; Sun, 28 Jan 2024 16:28:10 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id U80ur8cfEV9xYU80vr39zR; Sun, 28 Jan 2024 16:28:09 +0000 X-Authority-Analysis: v=2.4 cv=NfP1akP4 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=OYXG0DWI0hzoO5mfSTEA: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=V4k+pyGQ6MYm8714ckCysy+NeHJmMuVmknThKgzwRcg=; b=OHGYHP3SZVtIw5fTIZcSk7Q1P7 LTpzJxHvTflpdutmbJViALkY0v01BW2F+ohZaaAoYwcu6aqQoFnnutURY9LcRaJOrrPq9LLHaVsx/ 8aNfsYggU74q0Za8ffTNFhGNk; 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-2C for gdb-patches@sourceware.org; Sun, 28 Jan 2024 09:28:08 -0700 From: Tom Tromey Date: Sun, 28 Jan 2024 09:28:05 -0700 Subject: [PATCH 1/5] Rename members of index_cache_store_context MIME-Version: 1.0 Message-Id: <20240128-pr-31262-index-cache-race-v1-1-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-2C 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: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGt1O1Q1KGMlGWbixuRMfy5U7G3+b7JVi/tP1ErTmDlRqll4Dw85ixberWsw2TZQjz4awYGGXeIyQOGeae6sOF24EdBkbRonbZNODYM1TYf/Cksr0t3E +08XbFqzmrCrl1ktmNtZ3pNBkW4aek7HcpjCIAi3p4Fe/3hLuKefsAdsuwTNCoEgWmFR+Bhw75XY34vjsk0BYPbQfI4IFmcsaaw= 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_MSPIKE_H2, 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 renames the private members of index_cache_store_context to start with "m_". --- gdb/dwarf2/index-cache.c | 10 +++++----- gdb/dwarf2/index-cache.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 7ddd7b3f974..645e36c66f7 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -104,7 +104,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, m_enabled = false; return; } - build_id_str = build_id_to_string (build_id); + m_build_id_str = build_id_to_string (build_id); /* Get build id of dwz file, if present. */ const dwz_file *dwz = dwarf2_get_dwz_file (per_bfd); @@ -121,7 +121,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, return; } - dwz_build_id_str = build_id_to_string (dwz_build_id); + m_dwz_build_id_str = build_id_to_string (dwz_build_id); } if (ic.m_dir.empty ()) @@ -159,8 +159,8 @@ index_cache::store (dwarf2_per_bfd *per_bfd, if (!ctx.m_enabled) return; - const char *dwz_build_id_ptr = (ctx.dwz_build_id_str.has_value () - ? ctx.dwz_build_id_str->c_str () + const char *dwz_build_id_ptr = (ctx.m_dwz_build_id_str.has_value () + ? ctx.m_dwz_build_id_str->c_str () : nullptr); try @@ -171,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 (), - ctx.build_id_str.c_str (), dwz_build_id_ptr, + ctx.m_build_id_str.c_str (), dwz_build_id_ptr, dw_index_kind::GDB_INDEX); } catch (const gdb_exception_error &except) diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index db2ec82c958..079ed412d2e 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -49,10 +49,10 @@ struct index_cache_store_context bool m_enabled; /* Captured value of build id. */ - std::string build_id_str; + std::string m_build_id_str; /* Captured value of dwz build id. */ - std::optional dwz_build_id_str; + std::optional m_dwz_build_id_str; }; /* Class to manage the access to the DWARF index cache. */ 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; From patchwork Sun Jan 28 16:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84845 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 5459038582A1 for ; Sun, 28 Jan 2024 16:29:27 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 5286F385840E for ; Sun, 28 Jan 2024 16:28:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5286F385840E 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 5286F385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459293; cv=none; b=M4JVS41GM/6I44h84T/6RQ+P1Oe4Lzp6VaVd5yxneQJBY2A6j05k3d0P+hw0BnRxU/rT3ry9PUFoWdKQiJv9hqjgSJBr62FEcxBwWIgbmGJUs8FEUEJBanLTEYfrEmb89aV9Mx+If5dVl87dThAO0+st6JLfz0GduRcrwT+5Vnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459293; c=relaxed/simple; bh=06lyoV60y7mMFO9Vzhe0XHzXzV8nMmfoWz7SvNQdrOE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=C9PbL7rOuUToAyk7uS/Gz2AwVBezPs43+TCQnHxVk9AKOX5HB8T+lvarBSQjl7sgUlIM+bZpKFumw6ZW2vvwsb3Cd1AS0ujxYDwHo1oVbOzLwrTw0PseJnfqGnTKZFeF9W+yVcpXFVCGjXOULCfQybvJ+Piroxfo8jLK7fQehLE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id TuSprHninTHHuU80wrY9kN; Sun, 28 Jan 2024 16:28:11 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id U80vrKU5xYjq0U80wrTDmB; Sun, 28 Jan 2024 16:28:10 +0000 X-Authority-Analysis: v=2.4 cv=afxyIDkt c=1 sm=1 tr=0 ts=65b6809a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=b2a5FaQfZxPO6u7mRWoA: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=hU7xM4ZOQQwnvdT5iqInf5PPfhj+h4SckMqlLVxhp8E=; b=io1GH8FxIF4hO4jEXGsVoASZWM 0fu88ei4gLe/TH4ygkgB59DhvEN9UE1J3Y2KeeTZaFOxUKQUAyxQdoueMlhtyBD/5sjsh0s+TRZvC c2OEr0eStWYK6vDILrKb7TpKt; 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 1rU80v-003tVN-1e for gdb-patches@sourceware.org; Sun, 28 Jan 2024 09:28:09 -0700 From: Tom Tromey Date: Sun, 28 Jan 2024 09:28:07 -0700 Subject: [PATCH 3/5] Capture the per-BFD object in index_cache_store_context MIME-Version: 1.0 Message-Id: <20240128-pr-31262-index-cache-race-v1-3-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: 1rU80v-003tVN-1e 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: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfH/4h55reyEdI+VZOTQf34DfPl1k1SldQcElYCZTJUCFhPf2/lWYXb1QXIpRNTJU2epUxOiPwP8KbqIfeSnNW0DZFtiGQ5Gcv/aDb8qGzHR3EVCNs1sM MtEWsV499AZJE2Qym2pezYl1+mQs+sq/etL4FYeOmoFG/RJK7kaOG/59DguS90hqEwI0ByJRHHHvJfRjoJ4VNUyjHxbR6i60baw= 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, RCVD_IN_MSPIKE_H2, 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 index_cache_store_context to also capture the per-BFD object when it is constructed. This is used when storing to the cache, and this approach makes the code a little simpler. --- gdb/dwarf2/cooked-index.c | 7 +++---- gdb/dwarf2/cooked-index.h | 3 +-- gdb/dwarf2/index-cache.c | 12 ++++++------ gdb/dwarf2/index-cache.h | 6 ++++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index d5a21ee9dec..c53b5129d9e 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -619,7 +619,7 @@ cooked_index::set_contents (vec_type &&vec) gdb::task_group finalizers ([this, ctx = std::move (ctx)] () { m_state->set (cooked_state::FINALIZED); - maybe_write_index (m_per_bfd, ctx); + maybe_write_index (ctx); }); for (auto &idx : m_vector) @@ -825,13 +825,12 @@ cooked_index::dump (gdbarch *arch) } void -cooked_index::maybe_write_index (dwarf2_per_bfd *per_bfd, - const index_cache_store_context &ctx) +cooked_index::maybe_write_index (const index_cache_store_context &ctx) { if (index_for_writing () != nullptr) { /* (maybe) store an index in the cache. */ - global_index_cache.store (m_per_bfd, ctx); + global_index_cache.store (ctx); } m_state->set (cooked_state::CACHE_DONE); } diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 86fbb8ffac4..fd7686205d5 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -716,8 +716,7 @@ class cooked_index : public dwarf_scanner_base private: /* Maybe write the index to the index cache. */ - void maybe_write_index (dwarf2_per_bfd *per_bfd, - const index_cache_store_context &); + void maybe_write_index (const index_cache_store_context &); /* The vector of cooked_index objects. This is stored because the entries are stored on the obstacks in those objects. */ diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index a269eb46a36..91f2af3e275 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -91,7 +91,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_dir (ic.m_dir) + m_dir (ic.m_dir), + m_per_bfd (per_bfd) { if (!m_enabled) return; @@ -154,8 +155,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, /* See dwarf-index-cache.h. */ void -index_cache::store (dwarf2_per_bfd *per_bfd, - const index_cache_store_context &ctx) +index_cache::store (const index_cache_store_context &ctx) { if (!ctx.m_enabled) return; @@ -167,18 +167,18 @@ index_cache::store (dwarf2_per_bfd *per_bfd, try { index_cache_debug ("writing index cache for objfile %s", - bfd_get_filename (per_bfd->obfd)); + bfd_get_filename (ctx.m_per_bfd->obfd)); /* Write the index itself to the directory, using the build id as the filename. */ - write_dwarf_index (per_bfd, ctx.m_dir.c_str (), + write_dwarf_index (ctx.m_per_bfd, ctx.m_dir.c_str (), ctx.m_build_id_str.c_str (), dwz_build_id_ptr, dw_index_kind::GDB_INDEX); } catch (const gdb_exception_error &except) { index_cache_debug ("couldn't store index cache for objfile %s: %s", - bfd_get_filename (per_bfd->obfd), except.what ()); + bfd_get_filename (ctx.m_per_bfd->obfd), except.what ()); } } diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index f66f72caea1..09577aca257 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -51,6 +51,9 @@ struct index_cache_store_context /* Captured value of index cache directory. */ std::string m_dir; + /* The per-bfd object that we're caching. */ + dwarf2_per_bfd *m_per_bfd; + /* Captured value of build id. */ std::string m_build_id_str; @@ -80,8 +83,7 @@ class index_cache void disable (); /* Store an index for the specified object file in the cache. */ - void store (dwarf2_per_bfd *per_bfd, - const index_cache_store_context &); + void store (const index_cache_store_context &); /* Look for an index file matching BUILD_ID. If found, return the contents as an array_view and store the underlying resources (allocated memory, From patchwork Sun Jan 28 16:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84843 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 DBC3F385828E for ; Sun, 28 Jan 2024 16:28:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id 4E9D5385840B for ; Sun, 28 Jan 2024 16:28:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E9D5385840B 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 4E9D5385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459293; cv=none; b=RCDx+1ICnENiGrdrQIcgGlrqqq+AUYkiNYfYligUoct0sWEMDiCvwefk14W+ATClDTdRSpi0l/snsenX/JeDxW3j/1WHNBqnajUJBmDs3uokjl0+8+1G5Zl8gFKMc1OacAz2dPL84tUfo6L6SBRw7Gx+4HppNFXcByYCyGthfVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459293; c=relaxed/simple; bh=yW3HyHdcQjQ/HEOeRp/Ib9PHZYuxhsXnSFmpvJ9AISE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Xogro1vz7lH6krqsrYyYE0mY7jPzcFRCNJu8E3Z+lVu6zq9/uiXfwrqQuFl8joJn/+CuNvZwIaZX/ON6kvi8yI6owQD7pt0QXgb7p+JRtRwMMP0Kf1szdT9e1eWx9d7oD8p8zm1Otcfqmv6FuAlueqCqGPItP/e/a0u1F9E+yF0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id TyD7r79KQ8uLRU80wrKfOe; Sun, 28 Jan 2024 16:28:11 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id U80vrKU6GYjq0U80wrTDmR; Sun, 28 Jan 2024 16:28:10 +0000 X-Authority-Analysis: v=2.4 cv=afxyIDkt c=1 sm=1 tr=0 ts=65b6809a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=bDfMsa-h4ZwmX-kgXM4A: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=LOGfcVUNQujH576I/cqt0G7sMawhwWd6VadMd73lnoY=; b=in/naOVTZHMYT99pIJld+gYdyN h4Il6+thtyMaP3/JFQwkFmY84P6Dj64oXRoCs1AbgpHd2VK0i9GptwUN9Ul9QYFiLDT+8OgI+c+mi dM50uzpewAATdFnET5NCmjLbX; 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 1rU80v-003tVN-2L for gdb-patches@sourceware.org; Sun, 28 Jan 2024 09:28:09 -0700 From: Tom Tromey Date: Sun, 28 Jan 2024 09:28:08 -0700 Subject: [PATCH 4/5] Move the 'store' method to index_cache_store_context MIME-Version: 1.0 Message-Id: <20240128-pr-31262-index-cache-race-v1-4-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: 1rU80v-003tVN-2L 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: 5 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfH/4h55reyEdI+VZOTQf34DfPl1k1SldQcElYCZTJUCFhPf2/lWYXb1QXIpRNTJU2epUxOiPwP8KbqIfeSnNW0DZFtiGQ5Gcv/aDb8qGzHR3EVCNs1sM MtEWsV499AZJE2Qym2pezYl1+mQs+sq/etL4FYeOmoFG/RJK7kaOG/59DguS90hqEwI0ByJRHHHvJfRjoJ4VNUyjHxbR6i60baw= 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, RCVD_IN_MSPIKE_H2, 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 think it is cleaner for 'store' to be a method on index_cache_store_context rather than on the global index cache itself. This patch makes this change. --- gdb/dwarf2/cooked-index.c | 2 +- gdb/dwarf2/index-cache.c | 16 ++++++++-------- gdb/dwarf2/index-cache.h | 8 +++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index c53b5129d9e..ad9fe871552 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -830,7 +830,7 @@ cooked_index::maybe_write_index (const index_cache_store_context &ctx) if (index_for_writing () != nullptr) { /* (maybe) store an index in the cache. */ - global_index_cache.store (ctx); + ctx.store (); } m_state->set (cooked_state::CACHE_DONE); } diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 91f2af3e275..780d2c4f200 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -155,30 +155,30 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, /* See dwarf-index-cache.h. */ void -index_cache::store (const index_cache_store_context &ctx) +index_cache_store_context::store () const { - if (!ctx.m_enabled) + if (!m_enabled) return; - const char *dwz_build_id_ptr = (ctx.m_dwz_build_id_str.has_value () - ? ctx.m_dwz_build_id_str->c_str () + const char *dwz_build_id_ptr = (m_dwz_build_id_str.has_value () + ? m_dwz_build_id_str->c_str () : nullptr); try { index_cache_debug ("writing index cache for objfile %s", - bfd_get_filename (ctx.m_per_bfd->obfd)); + bfd_get_filename (m_per_bfd->obfd)); /* Write the index itself to the directory, using the build id as the filename. */ - write_dwarf_index (ctx.m_per_bfd, ctx.m_dir.c_str (), - ctx.m_build_id_str.c_str (), dwz_build_id_ptr, + write_dwarf_index (m_per_bfd, m_dir.c_str (), + m_build_id_str.c_str (), dwz_build_id_ptr, dw_index_kind::GDB_INDEX); } catch (const gdb_exception_error &except) { index_cache_debug ("couldn't store index cache for objfile %s: %s", - bfd_get_filename (ctx.m_per_bfd->obfd), except.what ()); + bfd_get_filename (m_per_bfd->obfd), except.what ()); } } diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index 09577aca257..95f217ed961 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -40,10 +40,11 @@ struct index_cache_resource struct index_cache_store_context { - friend class index_cache; - index_cache_store_context (const index_cache &ic, dwarf2_per_bfd *per_bfd); + /* Store the index in the cache. */ + void store () const; + private: /* Captured value of enabled (). */ bool m_enabled; @@ -82,9 +83,6 @@ class index_cache /* Disable the cache. */ void disable (); - /* Store an index for the specified object file in the cache. */ - void store (const index_cache_store_context &); - /* Look for an index file matching BUILD_ID. If found, return the contents as an array_view and store the underlying resources (allocated memory, mapped file, etc) in RESOURCE. The returned array_view is valid as long From patchwork Sun Jan 28 16:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84847 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 62D71385842B for ; Sun, 28 Jan 2024 16:29:55 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 5688A3858413 for ; Sun, 28 Jan 2024 16:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5688A3858413 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 5688A3858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459295; cv=none; b=iBwQGPuRuNaAia1mRq1zm5Qbs7kBtlwgK2sHoydbf4S5TC3gLwdTApRuJolFfALva7CpRxElsKWTI1vTxluXT8Knr1WkGUIbPjCMDwIDwSiB4/kQCqDSkYENXlsYPnEFzDuc2rfxdCHyBFOVu8YN3zglSV8GBoK1Ejs+Rte93tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706459295; c=relaxed/simple; bh=mIpto61yYSDvthiqYtFU8gp/HcySpR0Pr5vJo+hruJM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=qYJWypxqfiVRkR+d3qHDO4vcN8LtXl1vLuZFC38GM8ZC+yxq2JBgb0ohc+TRWNn6At1PwJdt8LbX9rYLH5tjyd7rzMpj7w/o3lXPvYuBCUTsHEJpPU6q/XofjF2Prdr27GfrOACG/pAp5n15hJTUb3Q+r2E+RU3cASm8ptsCAWw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTPS id U3PAr2iScCF6GU80xrGEGB; Sun, 28 Jan 2024 16:28:11 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id U80wrC5Yj55BJU80wrzB0Z; Sun, 28 Jan 2024 16:28:10 +0000 X-Authority-Analysis: v=2.4 cv=QcR1A+Xv c=1 sm=1 tr=0 ts=65b6809a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=vRvTRJHNINYyb3rVQ-4A:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677: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=bmVJFnxgJUYEq9H9+nLJgzMOs6W7yvgourUhFeKxxFU=; b=N+ATVMeoj/bkMD8y5xeMBNzWW1 B4zA5E2hJASvXx9AwmhXrMBU0M4NtCVHdyhBjVGbYn6v2X+C9XH+ERHTNAjojhUac5BVlGcfpa3Nc 70r6fqxm52NDziToj8XSQHuEZ; 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 1rU80v-003tVN-33 for gdb-patches@sourceware.org; Sun, 28 Jan 2024 09:28:09 -0700 From: Tom Tromey Date: Sun, 28 Jan 2024 09:28:09 -0700 Subject: [PATCH 5/5] Avoid race when writing to index cache MIME-Version: 1.0 Message-Id: <20240128-pr-31262-index-cache-race-v1-5-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: 1rU80v-003tVN-33 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: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfE0zeKue1J1rRqibzfHQ7U93CNQBT3gAD1DIyUVyC4ME4ZNSCWv03Oni6WE15FMoscw7glgWSS4y65pEvkKVP3XJbjhTy7C2u7bq2yFdGt3/Y8bfRbye zak5HcWTsVXhAHw2fGb9Z4FjD2XewgfVFQCYduP8H9hYjttaHDYwaZavTwpf4HQJQic/O/Myy1fw5hOq7nRIHiRNACuIvZD5rjs= 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_MSPIKE_H2, 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 The background DWARF reader changes introduced a race when writing to the index cache. The problem here is that constructing the index_cache_store_context object should only happen on the main thread, to ensure that the various value captures do not race. This patch adds an assert to the construct to that effect, and then arranges for this object to be constructed by the cooked_index_worker constructor -- which is only invoked on the main thread. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31262 --- gdb/dwarf2/cooked-index.c | 27 ++++++++++++--------------- gdb/dwarf2/cooked-index.h | 15 ++++++++++----- gdb/dwarf2/index-cache.c | 4 ++++ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index ad9fe871552..25f3f132989 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -566,6 +566,15 @@ cooked_index_worker::set (cooked_state desired_state) #endif /* CXX_STD_THREAD */ } +/* See cooked-index.h. */ + +void +cooked_index_worker::write_to_cache (const cooked_index *idx) const +{ + if (idx != nullptr) + m_cache_store.store (); +} + cooked_index::cooked_index (dwarf2_per_objfile *per_objfile, std::unique_ptr &&worker) : m_state (std::move (worker)), @@ -609,17 +618,16 @@ cooked_index::set_contents (vec_type &&vec) m_state->set (cooked_state::MAIN_AVAILABLE); - index_cache_store_context ctx (global_index_cache, m_per_bfd); - /* This is run after finalization is done -- but not before. If this task were submitted earlier, it would have to wait for finalization. However, that would take a slot in the global thread pool, and if enough such tasks were submitted at once, it would cause a livelock. */ - gdb::task_group finalizers ([this, ctx = std::move (ctx)] () + gdb::task_group finalizers ([this] () { m_state->set (cooked_state::FINALIZED); - maybe_write_index (ctx); + m_state->write_to_cache (index_for_writing ()); + m_state->set (cooked_state::CACHE_DONE); }); for (auto &idx : m_vector) @@ -824,17 +832,6 @@ cooked_index::dump (gdbarch *arch) } } -void -cooked_index::maybe_write_index (const index_cache_store_context &ctx) -{ - if (index_for_writing () != nullptr) - { - /* (maybe) store an index in the cache. */ - ctx.store (); - } - m_state->set (cooked_state::CACHE_DONE); -} - /* Wait for all the index cache entries to be written before gdb exits. */ static void diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index fd7686205d5..a5fe479df14 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -511,7 +511,8 @@ class cooked_index_worker public: explicit cooked_index_worker (dwarf2_per_objfile *per_objfile) - : m_per_objfile (per_objfile) + : m_per_objfile (per_objfile), + m_cache_store (global_index_cache, per_objfile->per_bfd) { } virtual ~cooked_index_worker () { } @@ -530,10 +531,15 @@ class cooked_index_worker protected: - /* Let cooked_index call the 'set' method. */ + /* Let cooked_index call the 'set' and 'write_to_cache' methods. */ friend class cooked_index; + + /* Set the current state. */ void set (cooked_state desired_state); + /* Write to the index cache. */ + void write_to_cache (const cooked_index *idx) const; + /* Helper function that does the work of reading. This must be able to be run in a worker thread without problems. */ virtual void do_reading () = 0; @@ -578,6 +584,8 @@ class cooked_index_worker scanning is stopped and this exception will later be reported by the 'wait' method. */ std::optional m_failed; + /* An object used to write to the index cache. */ + index_cache_store_context m_cache_store; }; /* The main index of DIEs. @@ -715,9 +723,6 @@ class cooked_index : public dwarf_scanner_base private: - /* Maybe write the index to the index cache. */ - void maybe_write_index (const index_cache_store_context &); - /* The vector of cooked_index objects. This is stored because the entries are stored on the obstacks in those objects. */ vec_type m_vector; diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 780d2c4f200..d9047ef46bb 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -33,6 +33,7 @@ #include "gdbsupport/selftest.h" #include #include +#include "run-on-main-thread.h" /* When set to true, show debug messages about the index cache. */ static bool debug_index_cache = false; @@ -94,6 +95,9 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic, m_dir (ic.m_dir), m_per_bfd (per_bfd) { + /* Capturing globals may only be done on the main thread. */ + gdb_assert (is_main_thread ()); + if (!m_enabled) return;