]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove uses of iterate_over_inferiors in top.c
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 17 Jan 2020 14:58:57 +0000 (09:58 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 17 Jan 2020 14:59:10 +0000 (09:59 -0500)
Replace with range-based for loops.

gdb/ChangeLog:

* top.c (struct qt_args): Remove.
(kill_or_detach): Change return type to void, replace `void *`
parameter with a proper one.
(print_inferior_quit_action):  Likewise.
(quit_confirm): Use range-based for loop to iterate over inferiors.
(quit_force): Likewise.

gdb/ChangeLog
gdb/top.c

index 0d3660249faf69077a348c5799eb1b56ae759424..abe7ab76621a70659c107246c7221f6f00a0b973 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-17  Simon Marchi  <simon.marchi@efficios.com>
+
+       * top.c (struct qt_args): Remove.
+       (kill_or_detach): Change return type to void, replace `void *`
+       parameter with a proper one.
+       (print_inferior_quit_action):  Likewise.
+       (quit_confirm): Use range-based for loop to iterate over inferiors.
+       (quit_force): Likewise.
+
 2020-01-17  Simon Marchi  <simon.marchi@efficios.com>
 
        * mi/mi-main.c (run_one_inferior): Change return type to void, replace
index a266bfa59256406b64624b1ee6547c1668b15293..f702af9acd34a766dd71627ec13e17e9d9bd1a63 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1607,21 +1607,14 @@ set_prompt (const char *s)
 }
 \f
 
-struct qt_args
-{
-  int from_tty;
-};
-
-/* Callback for iterate_over_inferiors.  Kills or detaches the given
-   inferior, depending on how we originally gained control of it.  */
+/* Kills or detaches the given inferior, depending on how we originally
+   gained control of it.  */
 
-static int
-kill_or_detach (struct inferior *inf, void *args)
+static void
+kill_or_detach (inferior *inf, int from_tty)
 {
-  struct qt_args *qt = (struct qt_args *) args;
-
   if (inf->pid == 0)
-    return 0;
+    return;
 
   thread_info *thread = any_thread_of_inferior (inf);
   if (thread != NULL)
@@ -1632,37 +1625,30 @@ kill_or_detach (struct inferior *inf, void *args)
       if (target_has_execution)
        {
          if (inf->attach_flag)
-           target_detach (inf, qt->from_tty);
+           target_detach (inf, from_tty);
          else
            target_kill ();
        }
     }
-
-  return 0;
 }
 
-/* Callback for iterate_over_inferiors.  Prints info about what GDB
-   will do to each inferior on a "quit".  ARG points to a struct
-   ui_out where output is to be collected.  */
+/* Prints info about what GDB will do to inferior INF on a "quit".  OUT is
+   where to collect the output.  */
 
-static int
-print_inferior_quit_action (struct inferior *inf, void *arg)
+static void
+print_inferior_quit_action (inferior *inf, ui_file *out)
 {
-  struct ui_file *stb = (struct ui_file *) arg;
-
   if (inf->pid == 0)
-    return 0;
+    return;
 
   if (inf->attach_flag)
-    fprintf_filtered (stb,
+    fprintf_filtered (out,
                      _("\tInferior %d [%s] will be detached.\n"), inf->num,
                      target_pid_to_str (ptid_t (inf->pid)).c_str ());
   else
-    fprintf_filtered (stb,
+    fprintf_filtered (out,
                      _("\tInferior %d [%s] will be killed.\n"), inf->num,
                      target_pid_to_str (ptid_t (inf->pid)).c_str ());
-
-  return 0;
 }
 
 /* If necessary, make the user confirm that we should quit.  Return
@@ -1679,7 +1665,10 @@ quit_confirm (void)
   string_file stb;
 
   stb.puts (_("A debugging session is active.\n\n"));
-  iterate_over_inferiors (print_inferior_quit_action, &stb);
+
+  for (inferior *inf : all_inferiors ())
+    print_inferior_quit_action (inf, &stb);
+
   stb.puts (_("\nQuit anyway? "));
 
   return query ("%s", stb.c_str ());
@@ -1712,7 +1701,6 @@ void
 quit_force (int *exit_arg, int from_tty)
 {
   int exit_code = 0;
-  struct qt_args qt;
 
   undo_terminal_modifications_before_exit ();
 
@@ -1723,15 +1711,14 @@ quit_force (int *exit_arg, int from_tty)
   else if (return_child_result)
     exit_code = return_child_result_value;
 
-  qt.from_tty = from_tty;
-
   /* We want to handle any quit errors and exit regardless.  */
 
   /* Get out of tfind mode, and kill or detach all inferiors.  */
   try
     {
       disconnect_tracing ();
-      iterate_over_inferiors (kill_or_detach, &qt);
+      for (inferior *inf : all_inferiors ())
+       kill_or_detach (inf, from_tty);
     }
   catch (const gdb_exception &ex)
     {