From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id 7CEC63858412 for ; Fri, 7 Apr 2023 15:25:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CEC63858412 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 cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway3.mail.pro1.eigbox.com (Postfix) with ESMTP id D87E710047D9C for ; Fri, 7 Apr 2023 15:25:42 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id knyApLk6DChTwknyAplpX9; Fri, 07 Apr 2023 15:25:42 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=BK12EHcG 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=-Qg8vedUpOfewEj0WjoA: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=3twPf7u5lY2DJgwsKXcbP1Kh/Qo5jStaLH1DGFzPaUg=; b=xfVpdvRhagpeWR7evqiIDsx3kW gGVCGbsUgzCMfWx3Ps4QxQlMX6Ho13naNmKtqQiGmnwgm19sgCCiZtqXhR9HmUg9gNyFWj4IdVzfd rx2EsXYcMVY6XJpgusPaIT0jw; 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-ML for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:42 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:49 -0600 Subject: [PATCH 17/19] Convert all_bfds 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-17-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-ML 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: 18 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 gdb_bfd.c to use the new hash table for all_bfds. This patch slightly changes the htab_t pretty-printer test, which was relying on all_bfds. Note that with the new hash table, gdb-specific printers aren't needed; the libstdc++ printers suffice -- in fact, they are better, because the true types of the contents are available. --- gdb/gdb_bfd.c | 45 ++++++++++++--------------------- gdb/testsuite/gdb.gdb/python-helper.exp | 3 ++- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index b05c78218ed..1c8c59cdb6e 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -34,6 +34,7 @@ #include "inferior.h" #include "cli/cli-style.h" #include +#include "gdbsupport/hash-table.h" /* An object of this type is stored in the section's user data when mapping a section. */ @@ -55,7 +56,7 @@ struct gdb_bfd_section_data BFDs; in contrast, this hash is used just to implement "maint info bfd". */ -static htab_t all_bfds; +static gdb::hash_set all_bfds; /* An object of this type is stored in each BFD's user data. */ @@ -469,7 +470,6 @@ static void gdb_bfd_init_data (struct bfd *abfd, struct stat *st) { struct gdb_bfd_data *gdata; - void **slot; gdb_assert (bfd_usrdata (abfd) == nullptr); @@ -480,9 +480,8 @@ gdb_bfd_init_data (struct bfd *abfd, struct stat *st) bfd_set_usrdata (abfd, gdata); /* This is the first we've seen it, so add it to the hash table. */ - slot = htab_find_slot (all_bfds, abfd, INSERT); - gdb_assert (slot && !*slot); - *slot = abfd; + auto insert_pair = all_bfds.insert (abfd); + gdb_assert (insert_pair.second); } /* See gdb_bfd.h. */ @@ -707,7 +706,7 @@ gdb_bfd_unref (struct bfd *abfd) delete gdata; bfd_set_usrdata (abfd, NULL); /* Paranoia. */ - htab_remove_elt (all_bfds, abfd); + all_bfds.erase (abfd); gdb_bfd_close_or_warn (abfd); @@ -1068,25 +1067,6 @@ gdb_bfd_errmsg (bfd_error_type error_tag, char **matching) return ret; } -/* A callback for htab_traverse that prints a single BFD. */ - -static int -print_one_bfd (void **slot, void *data) -{ - bfd *abfd = (struct bfd *) *slot; - struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd); - struct ui_out *uiout = (struct ui_out *) data; - - ui_out_emit_tuple tuple_emitter (uiout, NULL); - uiout->field_signed ("refcount", gdata->refc); - uiout->field_string ("addr", host_address_to_string (abfd)); - uiout->field_string ("filename", bfd_get_filename (abfd), - file_name_style.style ()); - uiout->text ("\n"); - - return 1; -} - /* Implement the 'maint info bfd' command. */ static void @@ -1100,7 +1080,17 @@ maintenance_info_bfds (const char *arg, int from_tty) uiout->table_header (40, ui_left, "filename", "Filename"); uiout->table_body (); - htab_traverse (all_bfds, print_one_bfd, uiout); + for (bfd *abfd : all_bfds) + { + struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd); + + ui_out_emit_tuple tuple_emitter (uiout, nullptr); + uiout->field_signed ("refcount", gdata->refc); + uiout->field_string ("addr", host_address_to_string (abfd)); + uiout->field_string ("filename", bfd_get_filename (abfd), + file_name_style.style ()); + uiout->text ("\n"); + } } /* BFD related per-inferior data. */ @@ -1170,9 +1160,6 @@ void _initialize_gdb_bfd (); void _initialize_gdb_bfd () { - all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, - NULL, xcalloc, xfree); - add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\ List the BFDs that are currently open."), &maintenanceinfolist); diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp index a58e3b601df..9838e128b17 100644 --- a/gdb/testsuite/gdb.gdb/python-helper.exp +++ b/gdb/testsuite/gdb.gdb/python-helper.exp @@ -206,7 +206,8 @@ proc test_python_helper {} { gdb_test -prompt $outer_prompt_re "print *type->main_type" $answer # Test the htab_t pretty-printer. - gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}" + gdb_test -prompt $outer_prompt_re "print varobj_table" \ + "htab_t with ${::decimal} elements" return 0 } -- 2.39.2