Inferior without argument prints detail of current inferior.
[binutils-gdb.git] / gdb / inferior.c
index 3ff0512c381e03ea1ef03c37460948b8b19c6c9b..49f869a4c783a93472b2c2bec082c0a2316dae8b 100644 (file)
@@ -635,34 +635,50 @@ inferior_command (const char *args, int from_tty)
   struct inferior *inf;
   int num;
 
-  num = parse_and_eval_long (args);
-
-  inf = find_inferior_id (num);
-  if (inf == NULL)
-    error (_("Inferior ID %d not known."), num);
-
-  if (inf->pid != 0)
+  if (args == nullptr)
     {
-      if (inf != current_inferior ())
-       {
-         thread_info *tp = any_thread_of_inferior (inf);
-         if (tp == NULL)
-           error (_("Inferior has no threads."));
+      inf = current_inferior ();
+      gdb_assert (inf != nullptr);
+      const char *filename = inf->pspace->exec_filename.get ();
 
-         switch_to_thread (tp);
-       }
+      if (filename == nullptr)
+       filename = _("<noexec>");
 
-      gdb::observers::user_selected_context_changed.notify
-       (USER_SELECTED_INFERIOR
-        | USER_SELECTED_THREAD
-        | USER_SELECTED_FRAME);
+      printf_filtered (_("[Current inferior is %d [%s] (%s)]\n"),
+                      inf->num, inferior_pid_to_str (inf->pid).c_str (),
+                      filename);
     }
   else
     {
-      switch_to_inferior_no_thread (inf);
+      num = parse_and_eval_long (args);
+
+      inf = find_inferior_id (num);
+      if (inf == NULL)
+       error (_("Inferior ID %d not known."), num);
+
+      if (inf->pid != 0)
+       {
+         if (inf != current_inferior ())
+           {
+             thread_info *tp = any_thread_of_inferior (inf);
+             if (tp == NULL)
+               error (_("Inferior has no threads."));
 
-      gdb::observers::user_selected_context_changed.notify
-       (USER_SELECTED_INFERIOR);
+             switch_to_thread (tp);
+           }
+
+         gdb::observers::user_selected_context_changed.notify
+           (USER_SELECTED_INFERIOR
+            | USER_SELECTED_THREAD
+            | USER_SELECTED_FRAME);
+       }
+      else
+       {
+         switch_to_inferior_no_thread (inf);
+
+         gdb::observers::user_selected_context_changed.notify
+           (USER_SELECTED_INFERIOR);
+       }
     }
 }