From patchwork Fri Aug 23 18:48:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 96417 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 B1E63387743E for ; Fri, 23 Aug 2024 18:53:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id A860B387743E for ; Fri, 23 Aug 2024 18:53:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A860B387743E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A860B387743E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724439198; cv=none; b=dkubb6NoE4HijFo8Jv8IjeeJTShjv06saSLuF+YHPgGwdlpUueK3PH/t6Vo0xhR+qUAJC0jHCoDf0zEaOekAFriAd26+R96RtBKxY44SdwRJD2ShErez0TeUvQif9V6KO2Ve9iXNWjMv9MoaABba7TLVKOhwZM3iFdL5YUCCab8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724439198; c=relaxed/simple; bh=BkrDjd+IGraEjmZABJOFSdC+eOxjN+Y65UxQhloB2HI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FPQAW5SmKQOL+wULY5dAYtAMzxCc9K5ndqsYopqaoqj7r6yfTqRPhm1ZBsdeEzIFKCCHff2FZRcAwjaK9x29LI/q6M1TRdlyiyMODdeaFwyORlHcNSU+txF2kmOIsFp7UgTu5icM0zHAik7ZFsBA+ckI79oDfBvbJJZIuZ1HHOI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E8F7D1E0BB; Fri, 23 Aug 2024 14:53:15 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi , Tom Tromey Subject: [PATCH v4 17/22] Convert all_bfds to new hash table Date: Fri, 23 Aug 2024 14:48:46 -0400 Message-ID: <20240823184910.883268-18-simon.marchi@efficios.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823184910.883268-1-simon.marchi@efficios.com> References: <20240823184910.883268-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1173.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, 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 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. Change-Id: I48b7bd142085287b34bdef8b6db5587581f94280 Co-Authored-By: Tom Tromey --- gdb/gdb_bfd.c | 47 +++++++++---------------- gdb/testsuite/gdb.gdb/python-helper.exp | 3 +- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 0854d571ecf9..e3d095834a9f 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/unordered_set.h" #if CXX_STD_THREAD @@ -80,12 +81,12 @@ struct gdb_bfd_section_data void *map_addr; }; -/* A hash table holding every BFD that gdb knows about. This is not +/* A hash set holding every BFD that gdb knows about. This is not to be confused with 'gdb_bfd_cache', which is used for sharing BFDs; in contrast, this hash is used just to implement "maint info bfd". */ -static htab_t all_bfds; +static gdb::unordered_set all_bfds; /* An object of this type is stored in each BFD's user data. */ @@ -482,7 +483,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); @@ -493,9 +493,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; + bool inserted = all_bfds.emplace (abfd).second; + gdb_assert (inserted); } /* See gdb_bfd.h. */ @@ -734,7 +733,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); @@ -1145,25 +1144,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 @@ -1177,7 +1157,17 @@ maintenance_info_bfds (const char *arg, int from_tty) uiout->table_header (40, ui_left, "filename", "Filename"); uiout->table_body (); - htab_traverse_noresize (all_bfds, print_one_bfd, uiout); + + for (auto abfd : all_bfds) + { + auto gdata = static_cast (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. */ @@ -1272,9 +1262,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 4589edc388fd..99524e075094 100644 --- a/gdb/testsuite/gdb.gdb/python-helper.exp +++ b/gdb/testsuite/gdb.gdb/python-helper.exp @@ -261,7 +261,8 @@ proc test_python_helper {} { } # 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" # Test the intrusive_list pretty-printer. A bug occured in the # pretty-printer for lists with more than one element. Verify that