]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/inferior.c
List inferiors/threads/pspaces in ascending order
[thirdparty/binutils-gdb.git] / gdb / inferior.c
index f46e1e336cc4a34c42191d55ec44c8411e2d077d..157e236f9e83debc6587b3ef753880a6259570b0 100644 (file)
@@ -1,6 +1,6 @@
 /* Multi-process control for GDB, the GNU debugger.
 
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "gdbthread.h"
 #include "ui-out.h"
 #include "observer.h"
-#include "gdbthread.h"
 #include "gdbcore.h"
 #include "symfile.h"
 #include "environ.h"
 #include "cli/cli-utils.h"
 #include "continuations.h"
+#include "arch-utils.h"
+#include "target-descriptions.h"
+#include "readline/tilde.h"
 
 void _initialize_inferiors (void);
 
@@ -72,7 +74,7 @@ set_current_inferior (struct inferior *inf)
 static void
 restore_inferior (void *arg)
 {
-  struct inferior *saved_inferior = arg;
+  struct inferior *saved_inferior = (struct inferior *) arg;
 
   set_current_inferior (saved_inferior);
 }
@@ -98,7 +100,8 @@ free_inferior (struct inferior *inf)
   xfree (inf->args);
   xfree (inf->terminal);
   free_environ (inf->environment);
-  xfree (inf->private);
+  target_desc_info_free (inf->tdesc_info);
+  xfree (inf->priv);
   xfree (inf);
 }
 
@@ -125,15 +128,24 @@ add_inferior_silent (int pid)
 {
   struct inferior *inf;
 
-  inf = xmalloc (sizeof (*inf));
+  inf = XNEW (struct inferior);
   memset (inf, 0, sizeof (*inf));
   inf->pid = pid;
 
   inf->control.stop_soon = NO_STOP_QUIETLY;
 
   inf->num = ++highest_inferior_num;
-  inf->next = inferior_list;
-  inferior_list = inf;
+
+  if (inferior_list == NULL)
+    inferior_list = inf;
+  else
+    {
+      struct inferior *last;
+
+      for (last = inferior_list; last->next != NULL; last = last->next)
+       ;
+      last->next = inf;
+    }
 
   inf->environment = make_environ ();
   init_environ (inf->environment);
@@ -168,7 +180,8 @@ struct delete_thread_of_inferior_arg
 static int
 delete_thread_of_inferior (struct thread_info *tp, void *data)
 {
-  struct delete_thread_of_inferior_arg *arg = data;
+  struct delete_thread_of_inferior_arg *arg
+    = (struct delete_thread_of_inferior_arg *) data;
 
   if (ptid_get_pid (tp->ptid) == arg->pid)
     {
@@ -181,11 +194,8 @@ delete_thread_of_inferior (struct thread_info *tp, void *data)
   return 0;
 }
 
-/* If SILENT then be quiet -- don't announce a inferior death, or the
-   exit of its threads.  */
-
 void
-delete_inferior_1 (struct inferior *todel, int silent)
+delete_inferior (struct inferior *todel)
 {
   struct inferior *inf, *infprev;
   struct delete_thread_of_inferior_arg arg;
@@ -200,7 +210,7 @@ delete_inferior_1 (struct inferior *todel, int silent)
     return;
 
   arg.pid = inf->pid;
-  arg.silent = silent;
+  arg.silent = 1;
 
   iterate_over_threads (delete_thread_of_inferior, &arg);
 
@@ -211,29 +221,13 @@ delete_inferior_1 (struct inferior *todel, int silent)
 
   observer_notify_inferior_removed (inf);
 
-  free_inferior (inf);
-}
-
-void
-delete_inferior (int pid)
-{
-  struct inferior *inf = find_inferior_pid (pid);
-
-  delete_inferior_1 (inf, 0);
-
-  if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
-}
-
-void
-delete_inferior_silent (int pid)
-{
-  struct inferior *inf = find_inferior_pid (pid);
+  /* If this program space is rendered useless, remove it. */
+  if (program_space_empty_p (inf->pspace))
+    delete_program_space (inf->pspace);
 
-  delete_inferior_1 (inf, 1);
+  free_inferior (inf);
 }
 
-
 /* If SILENT then be quiet -- don't announce a inferior exit, or the
    exit of its threads.  */
 
@@ -272,8 +266,6 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
       inf->vfork_child = NULL;
     }
 
-  inf->has_exit_code = 0;
-  inf->exit_code = 0;
   inf->pending_detach = 0;
 }
 
@@ -309,7 +301,7 @@ detach_inferior (int pid)
 {
   struct inferior *inf = find_inferior_pid (pid);
 
-  exit_inferior_1 (inf, 1);
+  exit_inferior_1 (inf, 0);
 
   if (print_inferior_events)
     printf_unfiltered (_("[Inferior %d detached]\n"), pid);
@@ -319,6 +311,8 @@ void
 inferior_appeared (struct inferior *inf, int pid)
 {
   inf->pid = pid;
+  inf->has_exit_code = 0;
+  inf->exit_code = 0;
 
   observer_notify_inferior_appeared (inf);
 }
@@ -364,12 +358,23 @@ find_inferior_pid (int pid)
   return NULL;
 }
 
-/* Find an inferior bound to PSPACE.  */
+/* See inferior.h */
+
+struct inferior *
+find_inferior_ptid (ptid_t ptid)
+{
+  return find_inferior_pid (ptid_get_pid (ptid));
+}
+
+/* See inferior.h.  */
 
 struct inferior *
 find_inferior_for_program_space (struct program_space *pspace)
 {
-  struct inferior *inf;
+  struct inferior *inf = current_inferior ();
+
+  if (inf->pspace == pspace)
+    return inf;
 
   for (inf = inferior_list; inf != NULL; inf = inf->next)
     {
@@ -472,8 +477,8 @@ have_live_inferiors (void)
   return inf != NULL;
 }
 
-/* Prune away automatically added program spaces that aren't required
-   anymore.  */
+/* Prune away any unused inferiors, and then prune away no longer used
+   program spaces.  */
 
 void
 prune_inferiors (void)
@@ -495,11 +500,9 @@ prune_inferiors (void)
        }
 
       *ss_link = ss->next;
-      delete_inferior_1 (ss, 1);
+      delete_inferior (ss);
       ss = *ss_link;
     }
-
-  prune_program_spaces ();
 }
 
 /* Simply returns the count of inferiors.  */
@@ -584,9 +587,8 @@ print_inferior (struct ui_out *uiout, char *requested_inferiors)
       ui_out_field_string (uiout, "target-id",
                           inferior_pid_to_str (inf->pid));
 
-      if (inf->pspace->ebfd)
-       ui_out_field_string (uiout, "exec",
-                            bfd_get_filename (inf->pspace->ebfd));
+      if (inf->pspace->pspace_exec_filename != NULL)
+       ui_out_field_string (uiout, "exec", inf->pspace->pspace_exec_filename);
       else
        ui_out_field_skip (uiout, "exec");
 
@@ -633,6 +635,11 @@ detach_inferior_command (char *args, int from_tty)
        }
 
       pid = gdb_inferior_id_to_pid (num);
+      if (pid == 0)
+       {
+         warning (_("Inferior ID %d is not running."), num);
+         continue;
+       }
 
       tp = any_thread_of_process (pid);
       if (!tp)
@@ -669,6 +676,11 @@ kill_inferior_command (char *args, int from_tty)
        }
 
       pid = gdb_inferior_id_to_pid (num);
+      if (pid == 0)
+       {
+         warning (_("Inferior ID %d is not running."), num);
+         continue;
+       }
 
       tp = any_thread_of_process (pid);
       if (!tp)
@@ -700,8 +712,8 @@ inferior_command (char *args, int from_tty)
   printf_filtered (_("[Switching to inferior %d [%s] (%s)]\n"),
                   inf->num,
                   inferior_pid_to_str (inf->pid),
-                  (inf->pspace->ebfd
-                   ? bfd_get_filename (inf->pspace->ebfd)
+                  (inf->pspace->pspace_exec_filename != NULL
+                   ? inf->pspace->pspace_exec_filename
                    : _("<noexec>")));
 
   if (inf->pid != 0)
@@ -736,7 +748,7 @@ inferior_command (char *args, int from_tty)
   else if (inf->pid != 0)
     {
       ui_out_text (current_uiout, "\n");
-      print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+      print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
     }
 }
 
@@ -784,7 +796,7 @@ remove_inferior_command (char *args, int from_tty)
          continue;
        }
 
-      delete_inferior_1 (inf, 1);
+      delete_inferior (inf);
     }
 }
 
@@ -794,6 +806,7 @@ add_inferior_with_spaces (void)
   struct address_space *aspace;
   struct program_space *pspace;
   struct inferior *inf;
+  struct gdbarch_info info;
 
   /* If all inferiors share an address space on this system, this
      doesn't really return a new address space; otherwise, it
@@ -804,6 +817,14 @@ add_inferior_with_spaces (void)
   inf->pspace = pspace;
   inf->aspace = pspace->aspace;
 
+  /* Setup the inferior's initial arch, based on information obtained
+     from the global "set ..." options.  */
+  gdbarch_info_init (&info);
+  inf->gdbarch = gdbarch_find_by_info (info);
+  /* The "set ..." options reject invalid settings, so we should
+     always have a valid arch by now.  */
+  gdb_assert (inf->gdbarch != NULL);
+
   return inf;
 }
 
@@ -838,7 +859,8 @@ add_inferior_command (char *args, int from_tty)
                  ++argv;
                  if (!*argv)
                    error (_("No argument to -exec"));
-                 exec = *argv;
+                 exec = tilde_expand (*argv);
+                 make_cleanup (xfree, exec);
                }
            }
          else
@@ -942,6 +964,12 @@ clone_inferior_command (char *args, int from_tty)
       inf = add_inferior (0);
       inf->pspace = pspace;
       inf->aspace = pspace->aspace;
+      inf->gdbarch = orginf->gdbarch;
+
+      /* If the original inferior had a user specified target
+        description, make the clone use it too.  */
+      if (target_desc_info_from_user_p (inf->tdesc_info))
+       copy_inferior_target_desc_info (inf, orginf);
 
       printf_filtered (_("Added inferior %d.\n"), inf->num);
 
@@ -977,6 +1005,8 @@ initialize_inferiors (void)
   current_inferior_ = add_inferior (0);
   current_inferior_->pspace = current_program_space;
   current_inferior_->aspace = current_program_space->aspace;
+  /* The architecture will be initialized shortly, by
+     initialize_current_architecture.  */
 
   add_info ("inferiors", info_inferiors_command, 
            _("IDs of specified inferiors (all inferiors if no argument)."));