From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 3B4FA385840C for ; Fri, 7 Apr 2023 15:25:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B4FA385840C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 9085610047F94 for ; Fri, 7 Apr 2023 15:25:42 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id knyApoKGCFhsVknyApK5qe; Fri, 07 Apr 2023 15:25:42 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=ELjDb3VC c=1 sm=1 tr=0 ts=643035f6 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=_dMr5OX9suqoNhTj5OMA:9 a=QEXdDO2ut3YA:10:nop_charset_2 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=VUsXwWMkTJEcc+QFXCKzKwocY9BVYrWPDEH3bwpdda4=; b=mbqTWOdBOAt2kalEHnUsBpt3Ak UlxvkDWdU245uuh3QqdU1WNDEZG5ufisXSwbn8Ueq9wE+by7Xc9l5kBNM2PAWB4mVZWI/ayZ65PQ2 8m07cXhYfGT3sPdaFenjCZvB+; Received: from 75-166-159-36.hlrn.qwest.net ([75.166.159.36]:60392 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pknyA-001hDU-DL for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:42 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:47 -0600 Subject: [PATCH 15/19] Convert abbrevs to new hash table MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230407-t-robin-hood-hash-v1-15-900d93ef1510@tromey.com> References: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> In-Reply-To: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 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: 75.166.159.36 X-Source-L: No X-Exim-ID: 1pknyA-001hDU-DL X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-159-36.hlrn.qwest.net ([192.168.0.21]) [75.166.159.36]:60392 X-Source-Auth: tom+tromey.com X-Email-Count: 16 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This converts the DWARF abbrevs themselves to use the new hash table. --- gdb/dwarf2/abbrev.c | 46 --------------------------------------------- gdb/dwarf2/abbrev.h | 54 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c index 1ebf8f6eed5..e82824033d4 100644 --- a/gdb/dwarf2/abbrev.c +++ b/gdb/dwarf2/abbrev.c @@ -30,52 +30,6 @@ #include "dwarf2/leb.h" #include "bfd.h" -/* Hash function for an abbrev. */ - -static hashval_t -hash_abbrev (const void *item) -{ - const struct abbrev_info *info = (const struct abbrev_info *) item; - /* Warning: if you change this next line, you must also update the - other code in this class using the _with_hash functions. */ - return info->number; -} - -/* Comparison function for abbrevs. */ - -static int -eq_abbrev (const void *lhs, const void *rhs) -{ - const struct abbrev_info *l_info = (const struct abbrev_info *) lhs; - const struct abbrev_info *r_info = (const struct abbrev_info *) rhs; - return l_info->number == r_info->number; -} - -/* Abbreviation tables. - - In DWARF version 2, the description of the debugging information is - stored in a separate .debug_abbrev section. Before we read any - dies from a section we read in all abbreviations and install them - in a hash table. */ - -abbrev_table::abbrev_table (sect_offset off, struct dwarf2_section_info *sect) - : sect_off (off), - section (sect), - m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev, - nullptr, xcalloc, xfree)) -{ -} - -/* Add an abbreviation to the table. */ - -void -abbrev_table::add_abbrev (struct abbrev_info *abbrev) -{ - void **slot = htab_find_slot_with_hash (m_abbrevs.get (), abbrev, - abbrev->number, INSERT); - *slot = abbrev; -} - /* Helper function that returns true if a DIE with the given tag might plausibly be indexed. */ diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h index 00cfbacf2d0..44750d7eb87 100644 --- a/gdb/dwarf2/abbrev.h +++ b/gdb/dwarf2/abbrev.h @@ -60,7 +60,12 @@ struct abbrev_info struct abbrev_table; typedef std::unique_ptr abbrev_table_up; -/* Top level data structure to contain an abbreviation table. */ +/* Top level data structure to contain an abbreviation table. + + In DWARF version 2, the description of the debugging information is + stored in a separate .debug_abbrev section. Before we read any + dies from a section we read in all abbreviations and install them + in a hash table. */ struct abbrev_table { @@ -76,12 +81,10 @@ struct abbrev_table const struct abbrev_info *lookup_abbrev (unsigned int abbrev_number) const { - struct abbrev_info search; - search.number = abbrev_number; - - return (struct abbrev_info *) htab_find_with_hash (m_abbrevs.get (), - &search, - abbrev_number); + auto iter = m_abbrevs.find (abbrev_number, abbrev_number); + if (iter == m_abbrevs.end ()) + return nullptr; + return *iter; } /* Where the abbrev table came from. @@ -92,15 +95,46 @@ struct abbrev_table private: - abbrev_table (sect_offset off, struct dwarf2_section_info *sect); + abbrev_table (sect_offset off, struct dwarf2_section_info *sect) + : sect_off (off), + section (sect) + { + } DISABLE_COPY_AND_ASSIGN (abbrev_table); /* Add an abbreviation to the table. */ - void add_abbrev (struct abbrev_info *abbrev); + void add_abbrev (struct abbrev_info *abbrev) + { m_abbrevs.insert (abbrev); } + + struct abbrev_traits + { + typedef abbrev_info *value_type; + + static bool is_empty (const value_type &val) + { return val == nullptr; } + + static bool equals (const value_type &lhs, const value_type &rhs) + { + return lhs->number == rhs->number; + } + + static bool equals (const value_type &lhs, unsigned int rhs) + { + return lhs->number == rhs; + } + + static size_t hash (const value_type &val) + { + /* Warning: if you change this next line, you must also update + the other code in this class that computes the hash by + hand.. */ + return val->number; + } + }; /* Hash table of abbrevs. */ - htab_up m_abbrevs; + gdb::traited_hash_table m_abbrevs; /* Storage for the abbrev table. */ auto_obstack m_abbrev_obstack; -- 2.39.2