Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v2] gdb: use gdb::unordered_{set,map} at a few places
Date: Thu, 13 Nov 2025 16:43:56 -0500	[thread overview]
Message-ID: <20251113214507.359286-1-simon.marchi@efficios.com> (raw)
In-Reply-To: <20251113213506.313040-1-simon.marchi@efficios.com>

New in v2:

 - I forgot to actually build-test with all targets enabled, so I was
   missing a change in solib-rocm.c.

Use the gdb:: set/map types instead of the std:: ones.  I only changed
places in files I can build on my dev machine.

I needed to explicitly default the move constructor and assigment
operator in proc_mem_file.  I think this is ok, as nothing takes the
address of a proc_mem_file, requiring it not to move.

I also needed to do it for refcnt_fd, in solib-rocm.c.  It's a bit odd
to prevent moving / copying a refcnt_fd, as this struct doesn't directly
hold a resource, but I think I get why it was done.

Change-Id: If6f2d7ba3b1ae338eba38b0ab9f987400e661dff
---
 gdb/aarch64-tdep.c           |  2 +-
 gdb/amdgpu-tdep.c            |  2 +-
 gdb/amdgpu-tdep.h            |  9 ++++-----
 gdb/arch/amd64-linux-tdesc.c |  3 ++-
 gdb/arch/i386-linux-tdesc.c  |  3 ++-
 gdb/i386-tdep.c              |  3 +--
 gdb/linux-nat.c              |  6 ++++--
 gdb/solib-rocm.c             | 12 ++++++------
 gdb/solib-svr4.c             |  2 +-
 gdb/x86-nat.c                |  4 +---
 10 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 89142e0a2149..b1cc17499bfb 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -66,7 +66,7 @@
 #define HA_MAX_NUM_FLDS		4
 
 /* All possible aarch64 target descriptors.  */
-static std::unordered_map <aarch64_features, target_desc *> tdesc_aarch64_map;
+static gdb::unordered_map <aarch64_features, target_desc *> tdesc_aarch64_map;
 
 /* The standard register names, and all the valid aliases for them.
    We're not adding fp here, that name is already taken, see
diff --git a/gdb/amdgpu-tdep.c b/gdb/amdgpu-tdep.c
index a2cb7d8984ac..e0f64ee4b21e 100644
--- a/gdb/amdgpu-tdep.c
+++ b/gdb/amdgpu-tdep.c
@@ -356,7 +356,7 @@ using amd_dbgapi_register_type_enum_up
 
 /* Map type lookup names to types.  */
 using amd_dbgapi_register_type_map
-  = std::unordered_map<std::string, amd_dbgapi_register_type_up>;
+  = gdb::unordered_map<std::string, amd_dbgapi_register_type_up>;
 
 /* Parse S as a ULONGEST, raise an error on overflow.  */
 
diff --git a/gdb/amdgpu-tdep.h b/gdb/amdgpu-tdep.h
index 67bcaaf243a5..ac30023d74fc 100644
--- a/gdb/amdgpu-tdep.h
+++ b/gdb/amdgpu-tdep.h
@@ -23,9 +23,8 @@
 #include "gdbarch.h"
 
 #include <amd-dbgapi/amd-dbgapi.h>
-#include <unordered_map>
 
-/* Provide std::unordered_map::Hash for amd_dbgapi_register_id_t.  */
+/* Provide gdb::unordered_map::Hash for amd_dbgapi_register_id_t.  */
 struct register_id_hash
 {
   size_t
@@ -35,7 +34,7 @@ struct register_id_hash
   }
 };
 
-/* Provide std::unordered_map::Equal for amd_dbgapi_register_id_t.  */
+/* Provide gdb::unordered_map::Equal for amd_dbgapi_register_id_t.  */
 struct register_id_equal_to
 {
   bool
@@ -74,12 +73,12 @@ struct amdgpu_gdbarch_tdep : gdbarch_tdep_base
   std::vector<int> dwarf_regnum_to_gdb_regnum;
 
   /* A map of gdb regnums keyed by they equivalent register_id.  */
-  std::unordered_map<amd_dbgapi_register_id_t, int, register_id_hash,
+  gdb::unordered_map<amd_dbgapi_register_id_t, int, register_id_hash,
 		     register_id_equal_to>
     regnum_map;
 
   /* A map of register_class_ids keyed by their name.  */
-  std::unordered_map<std::string, amd_dbgapi_register_class_id_t>
+  gdb::unordered_map<std::string, amd_dbgapi_register_class_id_t>
     register_class_map;
 };
 
diff --git a/gdb/arch/amd64-linux-tdesc.c b/gdb/arch/amd64-linux-tdesc.c
index 879666274e0e..4a7f2329f23d 100644
--- a/gdb/arch/amd64-linux-tdesc.c
+++ b/gdb/arch/amd64-linux-tdesc.c
@@ -21,6 +21,7 @@
 #include "arch/amd64-linux-tdesc.h"
 #include "arch/amd64.h"
 #include "arch/x86-linux-tdesc-features.h"
+#include "gdbsupport/unordered_map.h"
 
 
 /* See arch/amd64-linux-tdesc.h.  */
@@ -29,7 +30,7 @@ const struct target_desc *
 amd64_linux_read_description (uint64_t xstate_bv, bool is_x32)
 {
   /* The type used for the amd64 and x32 target description caches.  */
-  using tdesc_cache_type = std::unordered_map<uint64_t, const target_desc_up>;
+  using tdesc_cache_type = gdb::unordered_map<uint64_t, target_desc_up>;
 
   /* Caches for the previously seen amd64 and x32 target descriptions,
      indexed by the xstate_bv value that created the target
diff --git a/gdb/arch/i386-linux-tdesc.c b/gdb/arch/i386-linux-tdesc.c
index bd736eb68817..74f192b9c37c 100644
--- a/gdb/arch/i386-linux-tdesc.c
+++ b/gdb/arch/i386-linux-tdesc.c
@@ -21,6 +21,7 @@
 #include "arch/i386-linux-tdesc.h"
 #include "arch/i386.h"
 #include "arch/x86-linux-tdesc-features.h"
+#include "gdbsupport/unordered_map.h"
 
 /* See arch/i386-linux-tdesc.h.  */
 
@@ -31,7 +32,7 @@ i386_linux_read_description (uint64_t xstate_bv)
      xstate_bv value that created the target description.  This
      needs to be static within this function to ensure it is initialised
      before first use.  */
-  static std::unordered_map<uint64_t, const target_desc_up> i386_tdesc_cache;
+  static gdb::unordered_map<uint64_t, target_desc_up> i386_tdesc_cache;
 
   /* Only some bits are checked when creating a tdesc, but the
      XSTATE_BV value contains other feature bits that are not relevant
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index e00b3337beaf..72d880a7a8a0 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -62,7 +62,6 @@
 #include "user-regs.h"
 #include "expression.h"
 #include <algorithm>
-#include <unordered_set>
 #include "producer.h"
 #include "infcall.h"
 #include "maint.h"
@@ -4206,7 +4205,7 @@ static std::string
 i386_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p,
 			   const std::string &regname, int regnum)
 {
-  static const std::unordered_set<std::string> reg_assoc
+  static const gdb::unordered_set<std::string> reg_assoc
     = { "ax", "bx", "cx", "dx",
 	"si", "di", "bp", "sp" };
 
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 0c24e10c2c9e..cb33c0a9b844 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -63,7 +63,6 @@
 #include "gdbsupport/scope-exit.h"
 #include "gdbsupport/gdb-sigmask.h"
 #include "gdbsupport/common-debug.h"
-#include <unordered_map>
 
 /* This comment documents high-level logic of this file.
 
@@ -4039,6 +4038,9 @@ class proc_mem_file
     gdb_assert (m_fd.get () != -1);
   }
 
+  proc_mem_file (proc_mem_file &&) = default;
+  proc_mem_file & operator= (proc_mem_file &&) = default;
+
   ~proc_mem_file ()
   {
     linux_nat_debug_printf ("closing fd %d for /proc/%d/task/%ld/mem",
@@ -4067,7 +4069,7 @@ class proc_mem_file
    (also default), we don't create an inferior for the fork child, but
    we still need to remove breakpoints from the fork child's
    memory.  */
-static std::unordered_map<int, proc_mem_file> proc_mem_file_map;
+static gdb::unordered_map<int, proc_mem_file> proc_mem_file_map;
 
 /* Close the /proc/PID/mem file for PID.  */
 
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index b48e4426fd41..b328cc7b5d06 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -32,8 +32,6 @@
 #include "solib-svr4.h"
 #include "symfile.h"
 
-#include <unordered_map>
-
 namespace {
 
 /* Per inferior cache of opened file descriptors.  */
@@ -60,15 +58,17 @@ struct rocm_solib_fd_cache
 private:
   struct refcnt_fd
   {
-    DISABLE_COPY_AND_ASSIGN (refcnt_fd);
     refcnt_fd (int fd, int refcnt) : fd (fd), refcnt (refcnt) {}
 
+    refcnt_fd (refcnt_fd &&) = default;
+    refcnt_fd &operator=(refcnt_fd &&other) = default;
+
     int fd = -1;
     int refcnt = 0;
   };
 
   inferior *m_inferior;
-  std::unordered_map<std::string, refcnt_fd> m_cache;
+  gdb::unordered_map<std::string, refcnt_fd> m_cache;
 };
 
 int
@@ -101,7 +101,7 @@ rocm_solib_fd_cache::open (const std::string &filename,
 int
 rocm_solib_fd_cache::close (int fd, fileio_error *target_errno)
 {
-  using cache_val = std::unordered_map<std::string, refcnt_fd>::value_type;
+  using cache_val = gdb::unordered_map<std::string, refcnt_fd>::value_type;
   auto it
     = std::find_if (m_cache.begin (), m_cache.end (),
 		    [fd](const cache_val &s) { return s.second.fd == fd; });
@@ -544,7 +544,7 @@ rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
     tokens.emplace_back (uri.substr (last));
 
   /* Create a tag-value map from the tokenized query/fragment.  */
-  std::unordered_map<std::string_view, std::string_view,
+  gdb::unordered_map<std::string_view, std::string_view,
 		     gdb::string_view_hash> params;
   for (std::string_view token : tokens)
     {
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index c91e0b2c37b4..2d15e7dfd8a5 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3758,7 +3758,7 @@ svr4_solib_ops::get_solibs_in_ns (int nsid) const
      faster, and to be able to remove SOs from the map, to avoid
      returning the dynamic linker multiple times.  */
   CORE_ADDR debug_base = info->namespace_id[nsid];
-  std::unordered_map<std::string, const lm_info_svr4 *> namespace_solibs;
+  gdb::unordered_map<std::string, const lm_info_svr4 *> namespace_solibs;
   for (svr4_so &so : info->solib_lists[debug_base])
     namespace_solibs[so.name] = so.lm_info.get ();
 
diff --git a/gdb/x86-nat.c b/gdb/x86-nat.c
index eb44dd58a4f4..381364cdd70e 100644
--- a/gdb/x86-nat.c
+++ b/gdb/x86-nat.c
@@ -21,8 +21,6 @@
 #include "cli/cli-cmds.h"
 #include "inferior.h"
 
-#include <unordered_map>
-
 /* Support for hardware watchpoints and breakpoints using the x86
    debug registers.
 
@@ -42,7 +40,7 @@ struct x86_dr_low_type x86_dr_low;
    need to keep track of processes that aren't bound to any inferior
    (e.g., fork children, checkpoints).  */
 
-static std::unordered_map<pid_t,
+static gdb::unordered_map<pid_t,
 			  struct x86_debug_reg_state> x86_debug_process_state;
 
 /* See x86-nat.h.  */

base-commit: fd3b1c4f4c111444dfe6ff9c3f00a5469e7cd8a6
-- 
2.51.2


  reply	other threads:[~2025-11-13 21:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 21:35 [PATCH] " Simon Marchi
2025-11-13 21:43 ` Simon Marchi [this message]
2025-11-14 19:49   ` [PATCH v2] " Tom Tromey
2025-11-14 20:00     ` Simon Marchi
2025-11-14 20:05       ` Tom Tromey
2025-11-14 20:32         ` Simon Marchi
2025-11-14 21:10           ` Tom Tromey
2025-11-14 21:15             ` Simon Marchi
2025-11-14 21:43               ` Tom Tromey
2025-11-14 22:20                 ` Simon Marchi
2025-11-17 15:58                   ` Tom Tromey
2025-11-17 16:31                     ` Simon Marchi
2026-07-27 16:21                       ` Daniel Fellows

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251113214507.359286-1-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox