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