Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / mi / mi-interp.c
index e055dce59ea5ba09a92373b715a936a4502bdedf..d4baa485210875aef0e04be48ed2188f1d6f1525 100644 (file)
@@ -1,6 +1,6 @@
 /* MI Interpreter Definitions and Commands for GDB, the GNU debugger.
 
-   Copyright (C) 2002-2018 Free Software Foundation, Inc.
+   Copyright (C) 2002-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -43,7 +43,8 @@
    interpreter.  */
 
 static void mi_execute_command_wrapper (const char *cmd);
-static void mi_execute_command_input_handler (char *cmd);
+static void mi_execute_command_input_handler
+  (gdb::unique_xmalloc_ptr<char> &&cmd);
 
 /* These are hooks that we put in place while doing interpreter_exec
    so we can report interesting things that happened "behind the MI's
@@ -294,14 +295,14 @@ mi_on_sync_execution_done (void)
 /* mi_execute_command_wrapper wrapper suitable for INPUT_HANDLER.  */
 
 static void
-mi_execute_command_input_handler (char *cmd)
+mi_execute_command_input_handler (gdb::unique_xmalloc_ptr<char> &&cmd)
 {
   struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
   struct ui *ui = current_ui;
 
   ui->prompt_state = PROMPT_NEEDED;
 
-  mi_execute_command_wrapper (cmd);
+  mi_execute_command_wrapper (cmd.get ());
 
   /* Print a prompt, indicating we're ready for further input, unless
      we just started a synchronous command.  In that case, we're about
@@ -951,6 +952,24 @@ mi_output_running (struct thread_info *thread)
     }
 }
 
+/* Return true if there are multiple inferiors loaded.  This is used
+   for backwards compatibility -- if there's only one inferior, output
+   "all", otherwise, output each resumed thread individually.  */
+
+static bool
+multiple_inferiors_p ()
+{
+  int count = 0;
+  for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
+    {
+      count++;
+      if (count > 1)
+       return true;
+    }
+
+  return false;
+}
+
 static void
 mi_on_resume_1 (struct mi_interp *mi, ptid_t ptid)
 {
@@ -968,43 +987,15 @@ mi_on_resume_1 (struct mi_interp *mi, ptid_t ptid)
                          current_token ? current_token : "");
     }
 
-  if (ptid.pid () == -1)
+  /* Backwards compatibility.  If doing a wildcard resume and there's
+     only one inferior, output "all", otherwise, output each resumed
+     thread individually.  */
+  if ((ptid == minus_one_ptid || ptid.is_pid ())
+      && !multiple_inferiors_p ())
     fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"all\"\n");
-  else if (ptid.is_pid ())
-    {
-      int count = 0;
-      inferior *inf;
-
-      /* Backwards compatibility.  If there's only one inferior,
-        output "all", otherwise, output each resumed thread
-        individually.  */
-      ALL_INFERIORS (inf)
-       if (inf->pid != 0)
-         {
-           count++;
-           if (count > 1)
-             break;
-         }
-
-      if (count == 1)
-       fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"all\"\n");
-      else
-       {
-         thread_info *tp;
-         inferior *curinf = current_inferior ();
-
-         ALL_NON_EXITED_THREADS (tp)
-           if (tp->inf == curinf)
-             mi_output_running (tp);
-       }
-    }
   else
-    {
-      thread_info *ti = find_thread_ptid (ptid);
-
-      gdb_assert (ti);
-      mi_output_running (ti);
-    }
+    for (thread_info *tp : all_non_exited_threads (ptid))
+      mi_output_running (tp);
 
   if (!running_result_record_printed && mi_proceeded)
     {
This page took 0.033095 seconds and 4 git commands to generate.