From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 4/4] gdb: use gdb::unordered_string_map throughout
Date: Fri, 13 Feb 2026 00:38:51 -0500 [thread overview]
Message-ID: <20260213053912.3520505-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260213053912.3520505-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@efficios.com>
Change all uses of
gdb::unordered_map<string, T>
to
gdb::unordered_string_map<T>
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
---
gdb/ada-exp.y | 2 +-
gdb/amdgpu-tdep.c | 2 +-
gdb/amdgpu-tdep.h | 2 +-
gdb/corelow.c | 6 +++---
gdb/cp-namespace.c | 2 +-
gdb/elfread.c | 2 +-
gdb/gdb_bfd.c | 2 +-
gdb/gdbarch-selftests.c | 2 +-
gdb/mi/mi-cmds.c | 2 +-
gdb/solib-rocm.c | 4 ++--
gdb/solib-svr4.c | 2 +-
gdb/source-cache.h | 2 +-
gdb/tui/tui-layout.h | 2 +-
gdb/xml-tdesc.c | 2 +-
14 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 771a867c4ae6..e02f1e6d10a2 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -97,7 +97,7 @@ struct ada_parse_state
std::vector<ada_assign_up> assignments;
/* Track currently active iterated assignment names. */
- gdb::unordered_map<std::string, std::vector<ada_index_var_operation *>>
+ gdb::unordered_string_map<std::vector<ada_index_var_operation *>>
iterated_associations;
auto_obstack temp_space;
diff --git a/gdb/amdgpu-tdep.c b/gdb/amdgpu-tdep.c
index fc45623f92b1..5a275165fbb2 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<std::string, amd_dbgapi_register_type_up>;
+ = gdb::unordered_string_map<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 c0adf55fdf60..5404c2901b54 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<std::string, amd_dbgapi_register_class_id_t>
+ gdb::unordered_string_map<amd_dbgapi_register_class_id_t>
register_class_map;
};
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 658ff6e0198c..a28a707c293a 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -124,7 +124,7 @@ struct mapped_file_info
/* A type that maps a string to a build-id. */
using string_to_build_id_map
- = gdb::unordered_map<std::string, const bfd_build_id *>;
+ = gdb::unordered_string_map<const bfd_build_id *>;
/* 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<std::string, struct bfd *> bfd_map;
+ gdb::unordered_string_map<struct bfd *> bfd_map;
gdb::unordered_set<std::string> 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<std::string, map_entry> mapped_files;
+ gdb::unordered_string_map<map_entry> 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 2e3c539507cc..efdb2a2c850a 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<std::string, block_symbol>;
+using symbol_map = gdb::unordered_string_map<block_symbol>;
/* 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 010744639118..04e9a986031c 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<std::string, CORE_ADDR>;
+using elf_gnu_ifunc_cache = gdb::unordered_string_map<CORE_ADDR>;
static const registry<objfile>::key<elf_gnu_ifunc_cache>
elf_objfile_gnu_ifunc_cache_data;
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 98ea46677493..1933166b5fbf 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<std::string, unsigned long> bfd_error_string_counts;
+ gdb::unordered_string_map<unsigned long> bfd_error_string_counts;
};
/* Per-inferior data key. */
diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c
index 424281134a36..c89ad5ce5fde 100644
--- a/gdb/gdbarch-selftests.c
+++ b/gdb/gdbarch-selftests.c
@@ -133,7 +133,7 @@ register_name_test (struct gdbarch *gdbarch)
scoped_mock_context<test_target_ops> mockctx (gdbarch);
/* Track the number of times each register name appears. */
- gdb::unordered_map<std::string, int> name_counts;
+ gdb::unordered_string_map<int> 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 552eafbbcbc4..48d85e8785c8 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<std::string, mi_command_up> mi_cmd_table;
+static gdb::unordered_string_map<mi_command_up> mi_cmd_table;
/* MI command with a pure MI implementation. */
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index c17d5932b553..291694176821 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -69,7 +69,7 @@ struct rocm_solib_fd_cache
};
inferior *m_inferior;
- gdb::unordered_map<std::string, refcnt_fd> m_cache;
+ gdb::unordered_string_map<refcnt_fd> 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<std::string, refcnt_fd>::value_type;
+ using cache_val = gdb::unordered_string_map<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; });
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index c8d78fbfc1dd..aeb6cd30f423 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<std::string, const lm_info_svr4 *> namespace_solibs;
+ gdb::unordered_string_map<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/source-cache.h b/gdb/source-cache.h
index 09f65cea62f4..ab4955e553ed 100644
--- a/gdb/source-cache.h
+++ b/gdb/source-cache.h
@@ -97,7 +97,7 @@ class source_cache
/* The file offset cache. The key is the full name of the source
file. */
- gdb::unordered_map<std::string, std::vector<off_t>> m_offset_cache;
+ gdb::unordered_string_map<std::vector<off_t>> m_offset_cache;
/* The list of files where styling failed. */
gdb::unordered_set<std::string> m_no_styling_files;
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index ca9afbabae6b..536174c784d4 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -367,7 +367,7 @@ typedef std::function<tui_win_info * (const char *name)> window_factory;
/* The type for a data structure that maps a window name to that window's
factory function. */
-typedef gdb::unordered_map<std::string, window_factory> window_types_map;
+typedef gdb::unordered_string_map<window_factory> 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 ac73708f005d..472c604254a8 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<std::string, target_desc_up> xml_cache;
+static gdb::unordered_string_map<target_desc_up> xml_cache;
/* Callback data for target description parsing. */
--
2.53.0
next prev parent reply other threads:[~2026-02-13 5:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-13 5:38 [PATCH 1/4] gdb/elfread: add debug output for GNU ifunc resolution simon.marchi
2026-02-13 5:38 ` [PATCH 2/4] gdb/elfread: replace ifunc htab_t with gdb::unordered_map simon.marchi
2026-02-13 5:38 ` [PATCH 3/4] gdbsupport: add gdb::unordered_string_map simon.marchi
2026-02-13 5:38 ` simon.marchi [this message]
2026-02-13 8:30 ` [PATCH 1/4] gdb/elfread: add debug output for GNU ifunc resolution Eli Zaretskii
2026-02-13 17:20 ` Simon Marchi
2026-02-13 18:27 ` Kevin Buettner
2026-02-13 19:10 ` Simon Marchi
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=20260213053912.3520505-4-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/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