]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb, gdbserver: use structured bindings in a few places
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Jul 2025 13:17:50 +0000 (09:17 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 23 Jul 2025 18:08:23 +0000 (14:08 -0400)
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>
gdb/corelow.c
gdb/dictionary.c
gdb/solib-svr4.c
gdb/solib.c
gdb/symtab.c
gdbserver/server.cc

index 24b949b83e7917f7f243be14df6aeaad2ee08072..a74cb0564768e45a65ff067a30c2155b2f8a86d7 100644 (file)
@@ -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.  */
index 91dafd116dc27b21efbc0f4ef0c057f656d25b2b..28e900d9c07a9c39c89a8aa3dffb90d7a1b635ac 100644 (file)
@@ -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)
index c72d9ad6f2605fe317ea4293ef8e1344d71a4f34..af08b754c14e593b88f680acbe11b41f986fe02f 100644 (file)
@@ -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;
 }
index bd9f3cb4dff4664d2a48bcd615fe318ac67aa08b..3ec2032f01289011ba1bc3a651b076364f9438f1 100644 (file)
@@ -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);
index 160a465b676268ef12104ff41753a1175183e27f..302f4ebf2746221f5b1b8b9c50e88bac796c7ec3 100644 (file)
@@ -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)
index ab69400f97b98fa2f706918e262168b79628fd64..4875df7c100bdfe9fd94496a1cfe095efdf16b67 100644 (file)
@@ -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;