From 778164cffebba2bb48b983ff6164b04e03eb5153 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 9 Jul 2025 09:17:50 -0400 Subject: [PATCH] gdb, gdbserver: use structured bindings in a few places I wanted to change one of these, so I searched for more similar instances, while at it. I think this looks a bit tidier, over unpacking the pairs by hand. Change-Id: Ife4b678f7a6aed01803434197c564d2ab93532a7 Approved-By: Tom Tromey --- gdb/corelow.c | 5 +---- gdb/dictionary.c | 26 +++++++------------------- gdb/solib-svr4.c | 15 +++++---------- gdb/solib.c | 5 ++--- gdb/symtab.c | 5 +---- gdbserver/server.cc | 21 ++++++++------------- 6 files changed, 24 insertions(+), 53 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index 24b949b83e7..a74cb056476 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -451,11 +451,8 @@ core_target::build_file_mappings () const bfd_build_id *core_build_id = build_id_bfd_get (current_program_space->core_bfd ()); - for (const auto &iter : mapped_files) + for (const auto &[filename, file_data] : mapped_files) { - const std::string &filename = iter.first; - const mapped_file &file_data = iter.second; - /* If this mapped file has the same build-id as was discovered for the core-file itself, then we assume this is the main executable. Record the filename as we can use this later. */ diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 91dafd116dc..28e900d9c07 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -952,14 +952,9 @@ mdict_create_hashed (struct obstack *obstack, retval->n_allocated_dictionaries = nsyms.size (); int idx = 0; - for (const auto &pair : nsyms) - { - enum language language = pair.first; - std::vector symlist = pair.second; - - retval->dictionaries[idx++] - = dict_create_hashed (obstack, language, symlist); - } + for (const auto &[language, symlist] : nsyms) + retval->dictionaries[idx++] = dict_create_hashed (obstack, language, + symlist); return retval; } @@ -997,14 +992,9 @@ mdict_create_linear (struct obstack *obstack, retval->n_allocated_dictionaries = nsyms.size (); int idx = 0; - for (const auto &pair : nsyms) - { - enum language language = pair.first; - std::vector symlist = pair.second; - - retval->dictionaries[idx++] - = dict_create_linear (obstack, language, symlist); - } + for (const auto &[language, symlist] : nsyms) + retval->dictionaries[idx++] = dict_create_linear (obstack, language, + symlist); return retval; } @@ -1135,10 +1125,8 @@ mdict_add_pending (struct multidictionary *mdict, gdb::unordered_map> nsyms = collate_pending_symbols_by_language (symbol_list); - for (const auto &pair : nsyms) + for (const auto &[language, symlist] : nsyms) { - enum language language = pair.first; - std::vector symlist = pair.second; struct dictionary *dict = find_language_dictionary (mdict, language); if (dict == nullptr) diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index c72d9ad6f26..af08b754c14 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -3591,16 +3591,11 @@ find_debug_base_for_solib (const solib *solib) auto *lm_info = gdb::checked_static_cast (solib->lm_info.get ()); - for (const auto &tuple : info->solib_lists) - { - CORE_ADDR debug_base = tuple.first; - const std::vector &sos = tuple.second; - - for (const svr4_so &so : sos) - if (svr4_same (solib->original_name.c_str (), so.name.c_str (), - *lm_info, *so.lm_info)) - return debug_base; - } + for (const auto &[debug_base, sos] : info->solib_lists) + for (const svr4_so &so : sos) + if (svr4_same (solib->original_name.c_str (), so.name.c_str (), *lm_info, + *so.lm_info)) + return debug_base; return 0; } diff --git a/gdb/solib.c b/gdb/solib.c index bd9f3cb4dff..3ec2032f012 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1210,14 +1210,13 @@ info_linker_namespace_command (const char *pattern, int from_tty) bool ns_separator = false; - for (auto &solibs_pair : all_solibs_to_print) + for (const auto &[ns, solibs_to_print] : all_solibs_to_print) { if (ns_separator) uiout->message ("\n\n"); else ns_separator = true; - int ns = solibs_pair.first; - std::vector solibs_to_print = solibs_pair.second; + if (solibs_to_print.size () == 0) { uiout->message (_("Linker namespace [[%d]] is not active.\n"), ns); diff --git a/gdb/symtab.c b/gdb/symtab.c index 160a465b676..302f4ebf274 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -6986,11 +6986,8 @@ info_module_subcommand (bool quiet, const char *module_regexp, const char *last_filename = ""; const symbol *last_module_symbol = nullptr; - for (const module_symbol_search &ms : module_symbols) + for (const auto &[p, q] : module_symbols) { - const symbol_search &p = ms.first; - const symbol_search &q = ms.second; - gdb_assert (q.symbol != nullptr); if (last_module_symbol != p.symbol) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index ab69400f97b..4875df7c100 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1018,20 +1018,15 @@ handle_general_set (char *own_buf) }); } - for (const auto &iter : set_options) - { - thread_info *thread = iter.first; - gdb_thread_options options = iter.second; - - if (thread->thread_options != options) - { - threads_debug_printf ("[options for %s are now %s]\n", - target_pid_to_str (thread->id).c_str (), - to_string (options).c_str ()); + for (const auto [thread, options] : set_options) + if (thread->thread_options != options) + { + threads_debug_printf ("[options for %s are now %s]\n", + target_pid_to_str (thread->id).c_str (), + to_string (options).c_str ()); - thread->thread_options = options; - } - } + thread->thread_options = options; + } write_ok (own_buf); return; -- 2.47.2