From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id 950E33858C30 for ; Fri, 7 Apr 2023 15:25:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 950E33858C30 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 cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id E6B3510047423 for ; Fri, 7 Apr 2023 15:25:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id kny9pNc1ONX2akny9p1QO4; Fri, 07 Apr 2023 15:25:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=NMAQR22g c=1 sm=1 tr=0 ts=643035f5 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=rfOID86329tGnJx2QQwA: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=obW5jNOxenhr+9VJ+2t1/xalr518fHLhC4LeDszS3tg=; b=GsmMv0yo+twc+P3hcfTbcetqfh XT9RQB0BNqI/JcfvsBLZQtjBRZABgO0LHMQV7N2jgmSPBvzUAIELC2/45EKcdQgqbL5Z5lAG30E6h C/Old4t04N8XNZ5PoSbVyt8Vv; 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 1pkny9-001hDU-Pb for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:41 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:42 -0600 Subject: [PATCH 10/19] Convert compile/compile.c 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-10-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: 1pkny9-001hDU-Pb 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: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.6 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 compile/compile.c to use the new hash table. This change is also an example of the new hash_map template. --- gdb/compile/compile.c | 151 ++++---------------------------------------------- gdb/compile/compile.h | 10 +++- 2 files changed, 18 insertions(+), 143 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index c07686c32e0..d3c2554a90e 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -60,112 +60,15 @@ static struct cmd_list_element *compile_command_list; bool compile_debug; -/* Object of this type are stored in the compiler's symbol_err_map. */ - -struct symbol_error -{ - /* The symbol. */ - - const struct symbol *sym; - - /* The error message to emit. This is malloc'd and owned by the - hash table. */ - - char *message; -}; - -/* An object that maps a gdb type to a gcc type. */ - -struct type_map_instance -{ - /* The gdb type. */ - - struct type *type; - - /* The corresponding gcc type handle. */ - - gcc_type gcc_type_handle; -}; - -/* Hash a type_map_instance. */ - -static hashval_t -hash_type_map_instance (const void *p) -{ - const struct type_map_instance *inst = (const struct type_map_instance *) p; - - return htab_hash_pointer (inst->type); -} - -/* Check two type_map_instance objects for equality. */ - -static int -eq_type_map_instance (const void *a, const void *b) -{ - const struct type_map_instance *insta = (const struct type_map_instance *) a; - const struct type_map_instance *instb = (const struct type_map_instance *) b; - - return insta->type == instb->type; -} - -/* Hash function for struct symbol_error. */ - -static hashval_t -hash_symbol_error (const void *a) -{ - const struct symbol_error *se = (const struct symbol_error *) a; - - return htab_hash_pointer (se->sym); -} - -/* Equality function for struct symbol_error. */ - -static int -eq_symbol_error (const void *a, const void *b) -{ - const struct symbol_error *sea = (const struct symbol_error *) a; - const struct symbol_error *seb = (const struct symbol_error *) b; - - return sea->sym == seb->sym; -} - -/* Deletion function for struct symbol_error. */ - -static void -del_symbol_error (void *a) -{ - struct symbol_error *se = (struct symbol_error *) a; - - xfree (se->message); - xfree (se); -} - -/* Constructor for compile_instance. */ - -compile_instance::compile_instance (struct gcc_base_context *gcc_fe, - const char *options) - : m_gcc_fe (gcc_fe), m_gcc_target_options (options), - m_type_map (htab_create_alloc (10, hash_type_map_instance, - eq_type_map_instance, - xfree, xcalloc, xfree)), - m_symbol_err_map (htab_create_alloc (10, hash_symbol_error, - eq_symbol_error, del_symbol_error, - xcalloc, xfree)) -{ -} - /* See compile-internal.h. */ bool compile_instance::get_cached_type (struct type *type, gcc_type *ret) const { - struct type_map_instance inst, *found; - - inst.type = type; - found = (struct type_map_instance *) htab_find (m_type_map.get (), &inst); - if (found != NULL) + auto iter = m_type_map.find (type); + if (iter != m_type_map.end ()) { - *ret = found->gcc_type_handle; + *ret = iter->second; return true; } @@ -177,25 +80,13 @@ compile_instance::get_cached_type (struct type *type, gcc_type *ret) const void compile_instance::insert_type (struct type *type, gcc_type gcc_type) { - struct type_map_instance inst, *add; - void **slot; - - inst.type = type; - inst.gcc_type_handle = gcc_type; - slot = htab_find_slot (m_type_map.get (), &inst, INSERT); - - add = (struct type_map_instance *) *slot; /* The type might have already been inserted in order to handle recursive types. */ - if (add != NULL && add->gcc_type_handle != gcc_type) + auto iter = m_type_map.find (type); + if (iter != m_type_map.end () && (*iter).second != gcc_type) error (_("Unexpected type id from GCC, check you use recent enough GCC.")); - if (add == NULL) - { - add = XNEW (struct type_map_instance); - *add = inst; - *slot = add; - } + m_type_map.insert (type, gcc_type); } /* See compile-internal.h. */ @@ -204,19 +95,7 @@ void compile_instance::insert_symbol_error (const struct symbol *sym, const char *text) { - struct symbol_error e; - void **slot; - - e.sym = sym; - slot = htab_find_slot (m_symbol_err_map.get (), &e, INSERT); - if (*slot == NULL) - { - struct symbol_error *ep = XNEW (struct symbol_error); - - ep->sym = sym; - ep->message = xstrdup (text); - *slot = ep; - } + m_symbol_err_map.insert (sym, text); } /* See compile-internal.h. */ @@ -224,20 +103,12 @@ compile_instance::insert_symbol_error (const struct symbol *sym, void compile_instance::error_symbol_once (const struct symbol *sym) { - struct symbol_error search; - struct symbol_error *err; - - if (m_symbol_err_map == NULL) - return; - - search.sym = sym; - err = (struct symbol_error *) htab_find (m_symbol_err_map.get (), &search); - if (err == NULL || err->message == NULL) + auto iter = m_symbol_err_map.find (sym); + if (iter == m_symbol_err_map.end () || (*iter).second.empty ()) return; - gdb::unique_xmalloc_ptr message (err->message); - err->message = NULL; - error (_("%s"), message.get ()); + std::string message = std::move ((*iter).second); + error (_("%s"), message.c_str ()); } /* Implement "show debug compile". */ diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h index a3b6a18fe20..d8703326d68 100644 --- a/gdb/compile/compile.h +++ b/gdb/compile/compile.h @@ -19,6 +19,7 @@ #define COMPILE_COMPILE_H #include "gcc-c-interface.h" +#include "gdbsupport/hash-table.h" struct ui_file; struct gdbarch; @@ -33,7 +34,10 @@ struct dynamic_prop; class compile_instance { public: - compile_instance (struct gcc_base_context *gcc_fe, const char *options); + compile_instance (struct gcc_base_context *gcc_fe, const char *options) + : m_gcc_fe (gcc_fe), + m_gcc_target_options (options) + { } virtual ~compile_instance () { @@ -135,10 +139,10 @@ class compile_instance std::string m_gcc_target_options; /* Map from gdb types to gcc types. */ - htab_up m_type_map; + gdb::hash_map m_type_map; /* Map from gdb symbols to gcc error messages to emit. */ - htab_up m_symbol_err_map; + gdb::hash_map m_symbol_err_map; }; /* Public function that is called from compile_control case in the -- 2.39.2