From: Simon Marchi Date: Mon, 9 Feb 2026 19:15:00 +0000 (-0500) Subject: gdb: use gdb::unordered_string_map throughout X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1478fa3e483ab25fd15e8b275d8d3c29f7c9b5f5;p=thirdparty%2Fbinutils-gdb.git gdb: use gdb::unordered_string_map throughout Change all uses of gdb::unordered_map to gdb::unordered_string_map Using unordered_string_map avoids constructing a temporary std::string (possibly with dynamic allocation) when looking up values from `const char *`. I don't see any downsides to using unordered_string_map over unordered_map, even if all the lookups are done using existing std::string objects that would be built anyway. I think there are places where we could refactor the code to avoid constructing unnecessary std::string objects, but that is out of scope for this patch. There should be no change of behavior with this patch. Change-Id: Ic4df78b97f2755d5821bb66942b9e4d9a79a3dc5 Approved-by: Kevin Buettner --- diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 771a867c4ae..e02f1e6d10a 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -97,7 +97,7 @@ struct ada_parse_state std::vector assignments; /* Track currently active iterated assignment names. */ - gdb::unordered_map> + gdb::unordered_string_map> iterated_associations; auto_obstack temp_space; diff --git a/gdb/amdgpu-tdep.c b/gdb/amdgpu-tdep.c index fc45623f92b..5a275165fbb 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 - = gdb::unordered_map; + = gdb::unordered_string_map; /* Parse S as a ULONGEST, raise an error on overflow. */ diff --git a/gdb/amdgpu-tdep.h b/gdb/amdgpu-tdep.h index c0adf55fdf6..5404c2901b5 100644 --- a/gdb/amdgpu-tdep.h +++ b/gdb/amdgpu-tdep.h @@ -78,7 +78,7 @@ struct amdgpu_gdbarch_tdep : gdbarch_tdep_base regnum_map; /* A map of register_class_ids keyed by their name. */ - gdb::unordered_map + gdb::unordered_string_map register_class_map; }; diff --git a/gdb/corelow.c b/gdb/corelow.c index 658ff6e0198..a28a707c293 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -124,7 +124,7 @@ private: /* A type that maps a string to a build-id. */ using string_to_build_id_map - = gdb::unordered_map; + = gdb::unordered_string_map; /* A type that maps a build-id to a string. */ using build_id_to_string_map @@ -402,7 +402,7 @@ core_target::core_target (gdb_bfd_ref_ptr cbfd_ref) void core_target::build_file_mappings () { - gdb::unordered_map bfd_map; + gdb::unordered_string_map bfd_map; gdb::unordered_set unavailable_paths; /* All files mapped into the core file. The key is the filename. */ @@ -2122,7 +2122,7 @@ gdb_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd) }; /* All files mapped into the core file. The key is the filename. */ - gdb::unordered_map mapped_files; + gdb::unordered_string_map mapped_files; /* Get the build-id of the core file. At least on Linux, this will be the build-id for the main executable. If other targets add the diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 2e3c539507c..efdb2a2c850 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -349,7 +349,7 @@ cp_lookup_symbol_in_namespace (const char *the_namespace, const char *name, } /* Type used for collecting symbols. Maps names to symbols. */ -using symbol_map = gdb::unordered_map; +using symbol_map = gdb::unordered_string_map; /* This version of the function is internal, use the wrapper unless the list of ambiguous symbols is needed. diff --git a/gdb/elfread.c b/gdb/elfread.c index 2ad904cf4cb..7e38f623d12 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -660,7 +660,7 @@ elf_rel_plt_read (minimal_symbol_reader &reader, /* Per-objfile cache mapping function names to resolved ifunc addresses. */ -using elf_gnu_ifunc_cache = gdb::unordered_map; +using elf_gnu_ifunc_cache = gdb::unordered_string_map; static const registry::key elf_objfile_gnu_ifunc_cache_data; diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 98ea4667749..1933166b5fb 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -1241,7 +1241,7 @@ maintenance_info_bfds (const char *arg, int from_tty) struct bfd_inferior_data { - gdb::unordered_map bfd_error_string_counts; + gdb::unordered_string_map bfd_error_string_counts; }; /* Per-inferior data key. */ diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c index 424281134a3..c89ad5ce5fd 100644 --- a/gdb/gdbarch-selftests.c +++ b/gdb/gdbarch-selftests.c @@ -133,7 +133,7 @@ register_name_test (struct gdbarch *gdbarch) scoped_mock_context mockctx (gdbarch); /* Track the number of times each register name appears. */ - gdb::unordered_map name_counts; + gdb::unordered_string_map name_counts; const int num_regs = gdbarch_num_cooked_regs (gdbarch); for (auto regnum = 0; regnum < num_regs; regnum++) diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 552eafbbcbc..48d85e8785c 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -26,7 +26,7 @@ /* MI command table (built at run time). */ -static gdb::unordered_map mi_cmd_table; +static gdb::unordered_string_map mi_cmd_table; /* MI command with a pure MI implementation. */ diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index c17d5932b55..29169417682 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -69,7 +69,7 @@ private: }; inferior *m_inferior; - gdb::unordered_map m_cache; + gdb::unordered_string_map m_cache; }; int @@ -102,7 +102,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 = gdb::unordered_map::value_type; + using cache_val = gdb::unordered_string_map::value_type; auto it = std::find_if (m_cache.begin (), m_cache.end (), [fd](const cache_val &s) { return s.second.fd == fd; }); diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index c8d78fbfc1d..aeb6cd30f42 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -3753,7 +3753,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]; - gdb::unordered_map namespace_solibs; + gdb::unordered_string_map namespace_solibs; for (svr4_so &so : info->solib_lists[debug_base]) namespace_solibs[so.name] = so.lm_info.get (); diff --git a/gdb/source-cache.h b/gdb/source-cache.h index 09f65cea62f..ab4955e553e 100644 --- a/gdb/source-cache.h +++ b/gdb/source-cache.h @@ -97,7 +97,7 @@ private: /* The file offset cache. The key is the full name of the source file. */ - gdb::unordered_map> m_offset_cache; + gdb::unordered_string_map> m_offset_cache; /* The list of files where styling failed. */ gdb::unordered_set m_no_styling_files; diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index ca9afbabae6..536174c784d 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -367,7 +367,7 @@ typedef std::function window_factory; /* The type for a data structure that maps a window name to that window's factory function. */ -typedef gdb::unordered_map window_types_map; +typedef gdb::unordered_string_map window_types_map; /* Register a new TUI window type. NAME is the name of the window type. FACTORY is a function that can be called to instantiate the diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c index ac73708f005..472c604254a 100644 --- a/gdb/xml-tdesc.c +++ b/gdb/xml-tdesc.c @@ -64,7 +64,7 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher) then we will create unnecessary duplicate gdbarches. See gdbarch_list_lookup_by_info. */ -static gdb::unordered_map xml_cache; +static gdb::unordered_string_map xml_cache; /* Callback data for target description parsing. */