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,