diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2025-07-09 09:17:50 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2025-07-23 14:08:23 -0400 |
commit | 778164cffebba2bb48b983ff6164b04e03eb5153 (patch) | |
tree | e5a81fced85ff2e09a6405bd06d96945cd1befaf | |
parent | ae114fb523efe908f9e807359e2f494ee64d2801 (diff) | |
download | binutils-778164cffebba2bb48b983ff6164b04e03eb5153.zip binutils-778164cffebba2bb48b983ff6164b04e03eb5153.tar.gz binutils-778164cffebba2bb48b983ff6164b04e03eb5153.tar.bz2 |
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 <tom@tromey.com>
-rw-r--r-- | gdb/corelow.c | 5 | ||||
-rw-r--r-- | gdb/dictionary.c | 26 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 15 | ||||
-rw-r--r-- | gdb/solib.c | 5 | ||||
-rw-r--r-- | gdb/symtab.c | 5 | ||||
-rw-r--r-- | gdbserver/server.cc | 21 |
6 files changed, 24 insertions, 53 deletions
diff --git a/gdb/corelow.c b/gdb/corelow.c index 24b949b..a74cb05 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 91dafd1..28e900d 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<symbol *> 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<symbol *> 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<enum language, std::vector<symbol *>> 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<symbol *> 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 c72d9ad..af08b75 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<const lm_info_svr4 *> (solib->lm_info.get ()); - for (const auto &tuple : info->solib_lists) - { - CORE_ADDR debug_base = tuple.first; - const std::vector<svr4_so> &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 bd9f3cb..3ec2032 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<const solib *> 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 160a465..302f4eb 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 ab69400..4875df7 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; |