From patchwork Sun Oct 29 17:35:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 78683 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 129053870C0A for ; Sun, 29 Oct 2023 17:39:42 +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 84431385DC19 for ; Sun, 29 Oct 2023 17:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84431385DC19 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 84431385DC19 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=1698601113; cv=none; b=DQ/KGEBB0j9D8T3XzqXjuk6AEglkq3USA1IT35sXd6+wICVFVyy1pJUMFHpl6EFVGI91NaMRDptAIUPuthZBzwvr8JUWhJolwmFviY/eBuUbODluTxL4V/GFUk164h5ZtDHqVrZMwCozO3m6yeNeRIYwivdfLR7uXC70qLAQCUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698601113; c=relaxed/simple; bh=17mT1rjuHJ/K3ItccjmqyK2bLxJovF7WTkO+oJfB4zc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w0yavqyi5wrCXUiij7wsdcPUn0ST70IG6vgakq0xdYfOxTXaVsUfYP7NwcHiI0B8R/bHsuJsopPPA/rDxD77THt7Y7Ck3iHC/qql3O/uYWMZSfjxR91BkhphKTP92cCudB2ciSrUqmV9yOkIPKWIcodRd104GsWeXxmhmEKvwDw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6010a.ext.cloudfilter.net ([10.0.30.248]) by cmsmtp with ESMTPS id x3WXqA0QZ6nOZx9k2qvsTi; Sun, 29 Oct 2023 17:38:26 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id x9k1qfhnHruMPx9k1qNsKy; Sun, 29 Oct 2023 17:38:25 +0000 X-Authority-Analysis: v=2.4 cv=ZNHEJF3b c=1 sm=1 tr=0 ts=653e9891 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=bhdUkHdE2iEA:10 a=Qbun_eYptAEA:10 a=v0RHch5GQAZndExIyqMA: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:References:In-Reply-To: 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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=84LUtWz0vcfKMyf/qSDMJd77h8F841djlRCuKdTvJqo=; b=mKeXdjiNPNEeZq4yLVvIsXtsYd FFoZq9RH3xorqiqr6g9lcwqDQJVOhbP54wt//wBMhREZijuW5W02vOoB8RQ9lQXy1KfF88/FZBcIT XtvFct2eQyGxzBSq+cw2srcD7; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:47464 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1qx9k0-000nk4-36; Sun, 29 Oct 2023 11:38:25 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 05/15] Move cooked_index_storage to cooked-index.h Date: Sun, 29 Oct 2023 11:35:24 -0600 Message-ID: <20231029173839.471514-6-tom@tromey.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231029173839.471514-1-tom@tromey.com> References: <20231029173839.471514-1-tom@tromey.com> MIME-Version: 1.0 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.77.73 X-Source-L: No X-Exim-ID: 1qx9k0-000nk4-36 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:47464 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: MS4xfPCCj2CKTuV0gLc/H9Sqv/e61/NHLDhWREvUK0GkUEUGD92FDLMENMyicUtYdedIu+W7g7Nc/dwQvYnTUjGvik3G4bpKFfDSoY0+wgHQgt/A31G5IJdv ruqOB80g7ER9qqe0XWv/DU5wRKyBPnuGvBSIq5TtqHIhCj54oo0eVW9xTNK1PVDOOcNMZnUONVjxxZOgIkwu0uu7tqggSA3E/DE= X-Spam-Status: No, score=-3024.3 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 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 moves cooked_index_storage to cooked-index.h. This is needed by a subsequent patch. --- gdb/dwarf2/cooked-index.h | 70 ++++++++++++++++++++ gdb/dwarf2/read.c | 135 ++++++++++++-------------------------- 2 files changed, 111 insertions(+), 94 deletions(-) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 5aacb321c91..0db6e8003b9 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -33,6 +33,7 @@ #include "gdbsupport/thread-pool.h" #include "dwarf2/mapped-index.h" #include "dwarf2/tag.h" +#include "dwarf2/abbrev-cache.h" #include "gdbsupport/range-chain.h" struct dwarf2_per_cu_data; @@ -354,6 +355,75 @@ class cooked_index_shard gdb::future m_future; }; +class cutu_reader; + +/* An instance of this is created when scanning DWARF to create a + cooked index. */ + +class cooked_index_storage +{ +public: + + cooked_index_storage (); + DISABLE_COPY_AND_ASSIGN (cooked_index_storage); + + /* Return the current abbrev cache. */ + abbrev_cache *get_abbrev_cache () + { + return &m_abbrev_cache; + } + + /* Return the DIE reader corresponding to PER_CU. If no such reader + has been registered, return NULL. */ + cutu_reader *get_reader (dwarf2_per_cu_data *per_cu); + + /* Preserve READER by storing it in the local hash table. */ + cutu_reader *preserve (std::unique_ptr reader); + + /* Add an entry to the index. The arguments describe the entry; see + cooked-index.h. The new entry is returned. */ + const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, + cooked_index_flag flags, + const char *name, + const cooked_index_entry *parent_entry, + dwarf2_per_cu_data *per_cu) + { + return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu); + } + + /* Install the current addrmap into the shard being constructed, + then transfer ownership of the index to the caller. */ + std::unique_ptr release () + { + m_index->install_addrmap (&m_addrmap); + return std::move (m_index); + } + + /* Return the mutable addrmap that is currently being created. */ + addrmap_mutable *get_addrmap () + { + return &m_addrmap; + } + +private: + + /* Hash function for a cutu_reader. */ + static hashval_t hash_cutu_reader (const void *a); + + /* Equality function for cutu_reader. */ + static int eq_cutu_reader (const void *a, const void *b); + + /* The abbrev cache used by this indexer. */ + abbrev_cache m_abbrev_cache; + /* A hash table of cutu_reader objects. */ + htab_up m_reader_hash; + /* The index shard that is being constructed. */ + std::unique_ptr m_index; + + /* A writeable addrmap being constructed by this scanner. */ + addrmap_mutable m_addrmap; +}; + /* The main index of DIEs. The parallel DIE indexers create cooked_index_shard objects. Then, these are all handled to a cooked_index for storage and final indexing. The index is diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 024b66cc7ad..e8cd4496395 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -745,7 +745,6 @@ show_dwarf_max_cache_age (struct ui_file *file, int from_tty, static void dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu); -class cooked_index_storage; static void build_type_psymtabs_reader (cutu_reader *reader, cooked_index_storage *storage); @@ -4434,105 +4433,53 @@ get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list) } -/* An instance of this is created when scanning DWARF to create a - cooked index. */ - -class cooked_index_storage +cooked_index_storage::cooked_index_storage () + : m_reader_hash (htab_create_alloc (10, hash_cutu_reader, + eq_cutu_reader, + htab_delete_entry, + xcalloc, xfree)), + m_index (new cooked_index_shard) { -public: - - cooked_index_storage () - : m_reader_hash (htab_create_alloc (10, hash_cutu_reader, - eq_cutu_reader, - htab_delete_entry, - xcalloc, xfree)), - m_index (new cooked_index_shard) - { - } - - DISABLE_COPY_AND_ASSIGN (cooked_index_storage); - - /* Return the current abbrev cache. */ - abbrev_cache *get_abbrev_cache () - { - return &m_abbrev_cache; - } - - /* Return the DIE reader corresponding to PER_CU. If no such reader - has been registered, return NULL. */ - cutu_reader *get_reader (dwarf2_per_cu_data *per_cu) - { - int index = per_cu->index; - return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (), - &index, index); - } - - /* Preserve READER by storing it in the local hash table. */ - cutu_reader *preserve (std::unique_ptr reader) - { - m_abbrev_cache.add (reader->release_abbrev_table ()); - - int index = reader->cu->per_cu->index; - void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index, - index, INSERT); - gdb_assert (*slot == nullptr); - cutu_reader *result = reader.get (); - *slot = reader.release (); - return result; - } - - /* Add an entry to the index. The arguments describe the entry; see - cooked-index.h. The new entry is returned. */ - const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, - cooked_index_flag flags, - const char *name, - const cooked_index_entry *parent_entry, - dwarf2_per_cu_data *per_cu) - { - return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu); - } - - /* Install the current addrmap into the index shard being constructed, - then transfer ownership of the index to the caller. */ - std::unique_ptr release () - { - m_index->install_addrmap (&m_addrmap); - return std::move (m_index); - } - - /* Return the mutable addrmap that is currently being created. */ - addrmap_mutable *get_addrmap () - { - return &m_addrmap; - } +} -private: +cutu_reader * +cooked_index_storage::get_reader (dwarf2_per_cu_data *per_cu) +{ + int index = per_cu->index; + return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (), + &index, index); +} - /* Hash function for a cutu_reader. */ - static hashval_t hash_cutu_reader (const void *a) - { - const cutu_reader *reader = (const cutu_reader *) a; - return reader->cu->per_cu->index; - } +cutu_reader * +cooked_index_storage::preserve (std::unique_ptr reader) +{ + m_abbrev_cache.add (reader->release_abbrev_table ()); - /* Equality function for cutu_reader. */ - static int eq_cutu_reader (const void *a, const void *b) - { - const cutu_reader *ra = (const cutu_reader *) a; - const int *rb = (const int *) b; - return ra->cu->per_cu->index == *rb; - } + int index = reader->cu->per_cu->index; + void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index, + index, INSERT); + gdb_assert (*slot == nullptr); + cutu_reader *result = reader.get (); + *slot = reader.release (); + return result; +} - /* The abbrev cache used by this indexer. */ - abbrev_cache m_abbrev_cache; - /* A hash table of cutu_reader objects. */ - htab_up m_reader_hash; - /* The index shard that is being constructed. */ - std::unique_ptr m_index; +/* Hash function for a cutu_reader. */ +hashval_t +cooked_index_storage::hash_cutu_reader (const void *a) +{ + const cutu_reader *reader = (const cutu_reader *) a; + return reader->cu->per_cu->index; +} - /* A writeable addrmap being constructed by this scanner. */ - addrmap_mutable m_addrmap; -}; +/* Equality function for cutu_reader. */ +int +cooked_index_storage::eq_cutu_reader (const void *a, const void *b) +{ + const cutu_reader *ra = (const cutu_reader *) a; + const int *rb = (const int *) b; + return ra->cu->per_cu->index == *rb; +} /* An instance of this is created to index a CU. */