From: Simon Marchi Date: Thu, 13 Nov 2025 21:43:56 +0000 (-0500) Subject: gdb: use gdb::unordered_{set,map} at a few places X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=965deba12083d600eada3937b99699a873e0dcbe;p=thirdparty%2Fbinutils-gdb.git gdb: use gdb::unordered_{set,map} at a few places 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 Approved-By: Tom Tromey --- diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 0bb23944297..e44f84c42f4 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 tdesc_aarch64_map; +static gdb::unordered_map 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 a2cb7d8984a..e0f64ee4b21 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; + = gdb::unordered_map; /* Parse S as a ULONGEST, raise an error on overflow. */ diff --git a/gdb/amdgpu-tdep.h b/gdb/amdgpu-tdep.h index 67bcaaf243a..ac30023d74f 100644 --- a/gdb/amdgpu-tdep.h +++ b/gdb/amdgpu-tdep.h @@ -23,9 +23,8 @@ #include "gdbarch.h" #include -#include -/* 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 dwarf_regnum_to_gdb_regnum; /* A map of gdb regnums keyed by they equivalent register_id. */ - std::unordered_map regnum_map; /* A map of register_class_ids keyed by their name. */ - std::unordered_map + gdb::unordered_map register_class_map; }; diff --git a/gdb/arch/amd64-linux-tdesc.c b/gdb/arch/amd64-linux-tdesc.c index 879666274e0..4a7f2329f23 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; + using tdesc_cache_type = gdb::unordered_map; /* 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 bd736eb6881..74f192b9c37 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 i386_tdesc_cache; + static gdb::unordered_map 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 e00b3337bea..72d880a7a8a 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -62,7 +62,6 @@ #include "user-regs.h" #include "expression.h" #include -#include #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 ®name, int regnum) { - static const std::unordered_set reg_assoc + static const gdb::unordered_set reg_assoc = { "ax", "bx", "cx", "dx", "si", "di", "bp", "sp" }; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 0c24e10c2c9..322b44eae65 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 /* This comment documents high-level logic of this file. @@ -4039,6 +4038,11 @@ public: gdb_assert (m_fd.get () != -1); } + DISABLE_COPY_AND_ASSIGN (proc_mem_file); + + 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 +4071,7 @@ private: (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 proc_mem_file_map; +static gdb::unordered_map 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 b48e4426fd4..af7eff22b71 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -32,8 +32,6 @@ #include "solib-svr4.h" #include "symfile.h" -#include - namespace { /* Per inferior cache of opened file descriptors. */ @@ -60,15 +58,19 @@ 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) {} + DISABLE_COPY_AND_ASSIGN (refcnt_fd); + + refcnt_fd (refcnt_fd &&) = default; + refcnt_fd &operator=(refcnt_fd &&other) = default; + int fd = -1; int refcnt = 0; }; inferior *m_inferior; - std::unordered_map m_cache; + gdb::unordered_map m_cache; }; int @@ -101,7 +103,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::value_type; + using cache_val = gdb::unordered_map::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 +546,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 params; for (std::string_view token : tokens) { diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index c91e0b2c37b..2d15e7dfd8a 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 namespace_solibs; + gdb::unordered_map 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 eb44dd58a4f..381364cdd70 100644 --- a/gdb/x86-nat.c +++ b/gdb/x86-nat.c @@ -21,8 +21,6 @@ #include "cli/cli-cmds.h" #include "inferior.h" -#include - /* 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 x86_debug_process_state; /* See x86-nat.h. */