[4/4] Remove a use of iterate_over_threads from mi-main.c

Message ID 20190919212825.7586-5-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 19, 2019, 9:28 p.m. UTC
  This removes one use of iterate_over_threads from mi-main.c.

gdb/ChangeLog
2019-09-19  Tom Tromey  <tom@tromey.com>

	* mi/mi-main.c (run_inferiors): Rename from run_one_inferior.
	Change type.
	(mi_cmd_exec_run): Update.  Use bool.
---
 gdb/ChangeLog    |  6 +++++
 gdb/mi/mi-main.c | 57 +++++++++++++++++++++++-------------------------
 2 files changed, 33 insertions(+), 30 deletions(-)
  

Patch

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2ece3602056..30cc79ce27c 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -391,44 +391,41 @@  mi_cmd_exec_interrupt (const char *command, char **argv, int argc)
     }
 }
 
-/* Callback for iterate_over_inferiors which starts the execution
-   of the given inferior.
+/* Start the execution of all inferiors.
 
-   ARG is a pointer to an integer whose value, if non-zero, indicates
-   that the program should be stopped when reaching the main subprogram
-   (similar to what the CLI "start" command does).  */
+   RUN_CMD is the run command to use, either "run" or "start".  */
 
-static int
-run_one_inferior (struct inferior *inf, void *arg)
+static void
+run_inferiors (const char *run_cmd)
 {
-  int start_p = *(int *) arg;
-  const char *run_cmd = start_p ? "start" : "run";
-  struct target_ops *run_target = find_run_target ();
-  int async_p = mi_async && run_target->can_async_p ();
-
-  if (inf->pid != 0)
+  for (inferior *inf : all_inferiors_safe ())
     {
-      thread_info *tp = any_thread_of_inferior (inf);
-      if (tp == NULL)
-	error (_("Inferior has no threads."));
+      struct target_ops *run_target = find_run_target ();
+      int async_p = mi_async && run_target->can_async_p ();
 
-      switch_to_thread (tp);
-    }
-  else
-    {
-      set_current_inferior (inf);
-      switch_to_no_thread ();
-      set_current_program_space (inf->pspace);
+      if (inf->pid != 0)
+	{
+	  thread_info *tp = any_thread_of_inferior (inf);
+	  if (tp == NULL)
+	    error (_("Inferior has no threads."));
+
+	  switch_to_thread (tp);
+	}
+      else
+	{
+	  set_current_inferior (inf);
+	  switch_to_no_thread ();
+	  set_current_program_space (inf->pspace);
+	}
+      mi_execute_cli_command (run_cmd, async_p,
+			      async_p ? "&" : NULL);
     }
-  mi_execute_cli_command (run_cmd, async_p,
-			  async_p ? "&" : NULL);
-  return 0;
 }
 
 void
 mi_cmd_exec_run (const char *command, char **argv, int argc)
 {
-  int start_p = 0;
+  bool start_p = false;
 
   /* Parse the command options.  */
   enum opt
@@ -453,7 +450,7 @@  mi_cmd_exec_run (const char *command, char **argv, int argc)
       switch ((enum opt) opt)
 	{
 	case START_OPT:
-	  start_p = 1;
+	  start_p = true;
 	  break;
 	}
     }
@@ -463,15 +460,15 @@  mi_cmd_exec_run (const char *command, char **argv, int argc)
   if (oind != argc)
     error (_("Invalid argument: %s"), argv[oind]);
 
+  const char *run_cmd = start_p ? "start" : "run";
   if (current_context->all)
     {
       scoped_restore_current_pspace_and_thread restore_pspace_thread;
 
-      iterate_over_inferiors (run_one_inferior, &start_p);
+      run_inferiors (run_cmd);
     }
   else
     {
-      const char *run_cmd = start_p ? "start" : "run";
       struct target_ops *run_target = find_run_target ();
       int async_p = mi_async && run_target->can_async_p ();