arm-pikeos: software single step
[deliverable/binutils-gdb.git] / gdb / inferior.c
index 880f25df0eaabbf470866402b6d8c59de5ff983b..17d28c4cf5486f594fb2713238350701c41e860b 100644 (file)
@@ -26,7 +26,7 @@
 #include "gdbcmd.h"
 #include "gdbthread.h"
 #include "ui-out.h"
-#include "observer.h"
+#include "observable.h"
 #include "gdbcore.h"
 #include "symfile.h"
 #include "environ.h"
@@ -45,9 +45,8 @@ DEFINE_REGISTRY (inferior, REGISTRY_ACCESS_FIELD)
 struct inferior *inferior_list = NULL;
 static int highest_inferior_num;
 
-/* Print notices on inferior events (attach, detach, etc.), set with
-   `set print inferior-events'.  */
-static int print_inferior_events = 0;
+/* See inferior.h.  */
+int print_inferior_events = 1;
 
 /* The Current Inferior.  This is a strong reference.  I.e., whenever
    an inferior is the current inferior, its refcount is
@@ -109,7 +108,7 @@ add_inferior_silent (int pid)
       last->next = inf;
     }
 
-  observer_notify_inferior_added (inf);
+  gdb::observers::inferior_added.notify (inf);
 
   if (pid != 0)
     inferior_appeared (inf, pid);
@@ -123,7 +122,9 @@ add_inferior (int pid)
   struct inferior *inf = add_inferior_silent (pid);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[New inferior %d]\n"), pid);
+    printf_unfiltered (_("[New inferior %d (%s)]\n"),
+                      inf->num,
+                      target_pid_to_str (ptid_t (pid)));
 
   return inf;
 }
@@ -140,12 +141,12 @@ delete_thread_of_inferior (struct thread_info *tp, void *data)
   struct delete_thread_of_inferior_arg *arg
     = (struct delete_thread_of_inferior_arg *) data;
 
-  if (ptid_get_pid (tp->ptid) == arg->pid)
+  if (tp->ptid.pid () == arg->pid)
     {
       if (arg->silent)
-       delete_thread_silent (tp->ptid);
+       delete_thread_silent (tp);
       else
-       delete_thread (tp->ptid);
+       delete_thread (tp);
     }
 
   return 0;
@@ -176,7 +177,7 @@ delete_inferior (struct inferior *todel)
   else
     inferior_list = inf->next;
 
-  observer_notify_inferior_removed (inf);
+  gdb::observers::inferior_removed.notify (inf);
 
   /* If this program space is rendered useless, remove it. */
   if (program_space_empty_p (inf->pspace))
@@ -206,7 +207,7 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
 
   iterate_over_threads (delete_thread_of_inferior, &arg);
 
-  observer_notify_inferior_exit (inf);
+  gdb::observers::inferior_exit.notify (inf);
 
   inf->pid = 0;
   inf->fake_pid_p = 0;
@@ -225,18 +226,13 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
 
   inf->pending_detach = 0;
   /* Reset it.  */
-  inf->control = {NO_STOP_QUIETLY};
+  inf->control = inferior_control_state (NO_STOP_QUIETLY);
 }
 
 void
-exit_inferior (int pid)
+exit_inferior (inferior *inf)
 {
-  struct inferior *inf = find_inferior_pid (pid);
-
   exit_inferior_1 (inf, 0);
-
-  if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
 }
 
 void
@@ -248,10 +244,8 @@ exit_inferior_silent (int pid)
 }
 
 void
-exit_inferior_num_silent (int num)
+exit_inferior_silent (inferior *inf)
 {
-  struct inferior *inf = find_inferior_id (num);
-
   exit_inferior_1 (inf, 1);
 }
 
@@ -266,15 +260,9 @@ detach_inferior (inferior *inf)
   exit_inferior_1 (inf, 0);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d detached]\n"), pid);
-}
-
-/* See inferior.h.  */
-
-void
-detach_inferior (int pid)
-{
-  detach_inferior (find_inferior_pid (pid));
+    printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
+                      inf->num,
+                      target_pid_to_str (ptid_t (pid)));
 }
 
 void
@@ -284,7 +272,7 @@ inferior_appeared (struct inferior *inf, int pid)
   inf->has_exit_code = 0;
   inf->exit_code = 0;
 
-  observer_notify_inferior_appeared (inf);
+  gdb::observers::inferior_appeared.notify (inf);
 }
 
 void
@@ -295,7 +283,7 @@ discard_all_inferiors (void)
   for (inf = inferior_list; inf; inf = inf->next)
     {
       if (inf->pid != 0)
-       exit_inferior_silent (inf->pid);
+       exit_inferior_silent (inf);
     }
 }
 
@@ -333,7 +321,7 @@ find_inferior_pid (int pid)
 struct inferior *
 find_inferior_ptid (ptid_t ptid)
 {
-  return find_inferior_pid (ptid_get_pid (ptid));
+  return find_inferior_pid (ptid.pid ());
 }
 
 /* See inferior.h.  */
@@ -371,52 +359,6 @@ iterate_over_inferiors (int (*callback) (struct inferior *, void *),
   return NULL;
 }
 
-int
-valid_gdb_inferior_id (int num)
-{
-  struct inferior *inf;
-
-  for (inf = inferior_list; inf; inf = inf->next)
-    if (inf->num == num)
-      return 1;
-
-  return 0;
-}
-
-int
-pid_to_gdb_inferior_id (int pid)
-{
-  struct inferior *inf;
-
-  for (inf = inferior_list; inf; inf = inf->next)
-    if (inf->pid == pid)
-      return inf->num;
-
-  return 0;
-}
-
-int
-gdb_inferior_id_to_pid (int num)
-{
-  struct inferior *inferior = find_inferior_id (num);
-  if (inferior)
-    return inferior->pid;
-  else
-    return -1;
-}
-
-int
-in_inferior_list (int pid)
-{
-  struct inferior *inf;
-
-  for (inf = inferior_list; inf; inf = inf->next)
-    if (inf->pid == pid)
-      return 1;
-
-  return 0;
-}
-
 int
 have_inferiors (void)
 {
@@ -445,7 +387,7 @@ number_of_live_inferiors (void)
        struct thread_info *tp;
 
        ALL_NON_EXITED_THREADS (tp)
-        if (tp && ptid_get_pid (tp->ptid) == inf->pid)
+        if (tp && tp->ptid.pid () == inf->pid)
           if (target_has_execution_1 (tp->ptid))
             {
               /* Found a live thread in this inferior, go to the next
@@ -514,7 +456,7 @@ static const char *
 inferior_pid_to_str (int pid)
 {
   if (pid != 0)
-    return target_pid_to_str (pid_to_ptid (pid));
+    return target_pid_to_str (ptid_t (pid));
   else
     return _("<null>");
 }
@@ -611,8 +553,6 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
 static void
 detach_inferior_command (const char *args, int from_tty)
 {
-  struct thread_info *tp;
-
   if (!args || !*args)
     error (_("Requires argument (inferior id(s) to detach)"));
 
@@ -621,27 +561,27 @@ detach_inferior_command (const char *args, int from_tty)
     {
       int num = parser.get_number ();
 
-      if (!valid_gdb_inferior_id (num))
+      inferior *inf = find_inferior_id (num);
+      if (inf == NULL)
        {
          warning (_("Inferior ID %d not known."), num);
          continue;
        }
 
-      int pid = gdb_inferior_id_to_pid (num);
-      if (pid == 0)
+      if (inf->pid == 0)
        {
          warning (_("Inferior ID %d is not running."), num);
          continue;
        }
 
-      tp = any_thread_of_process (pid);
-      if (!tp)
+      thread_info *tp = any_thread_of_inferior (inf);
+      if (tp == NULL)
        {
          warning (_("Inferior ID %d has no threads."), num);
          continue;
        }
 
-      switch_to_thread (tp->ptid);
+      switch_to_thread (tp);
 
       detach_command (NULL, from_tty);
     }
@@ -650,8 +590,6 @@ detach_inferior_command (const char *args, int from_tty)
 static void
 kill_inferior_command (const char *args, int from_tty)
 {
-  struct thread_info *tp;
-
   if (!args || !*args)
     error (_("Requires argument (inferior id(s) to kill)"));
 
@@ -660,27 +598,27 @@ kill_inferior_command (const char *args, int from_tty)
     {
       int num = parser.get_number ();
 
-      if (!valid_gdb_inferior_id (num))
+      inferior *inf = find_inferior_id (num);
+      if (inf == NULL)
        {
          warning (_("Inferior ID %d not known."), num);
          continue;
        }
 
-      int pid = gdb_inferior_id_to_pid (num);
-      if (pid == 0)
+      if (inf->pid == 0)
        {
          warning (_("Inferior ID %d is not running."), num);
          continue;
        }
 
-      tp = any_thread_of_process (pid);
-      if (!tp)
+      thread_info *tp = any_thread_of_inferior (inf);
+      if (tp == NULL)
        {
          warning (_("Inferior ID %d has no threads."), num);
          continue;
        }
 
-      switch_to_thread (tp->ptid);
+      switch_to_thread (tp);
 
       target_kill ();
     }
@@ -702,18 +640,16 @@ inferior_command (const char *args, int from_tty)
 
   if (inf->pid != 0)
     {
-      if (inf->pid != ptid_get_pid (inferior_ptid))
+      if (inf != current_inferior ())
        {
-         struct thread_info *tp;
-
-         tp = any_thread_of_process (inf->pid);
-         if (!tp)
+         thread_info *tp = any_thread_of_inferior (inf);
+         if (tp == NULL)
            error (_("Inferior has no threads."));
 
-         switch_to_thread (tp->ptid);
+         switch_to_thread (tp);
        }
 
-      observer_notify_user_selected_context_changed
+      gdb::observers::user_selected_context_changed.notify
        (USER_SELECTED_INFERIOR
         | USER_SELECTED_THREAD
         | USER_SELECTED_FRAME);
@@ -721,10 +657,11 @@ inferior_command (const char *args, int from_tty)
   else
     {
       set_current_inferior (inf);
-      switch_to_thread (null_ptid);
+      switch_to_no_thread ();
       set_current_program_space (inf->pspace);
 
-      observer_notify_user_selected_context_changed (USER_SELECTED_INFERIOR);
+      gdb::observers::user_selected_context_changed.notify
+       (USER_SELECTED_INFERIOR);
     }
 }
 
@@ -784,7 +721,7 @@ add_inferior_with_spaces (void)
      doesn't really return a new address space; otherwise, it
      really does.  */
   aspace = maybe_new_address_space ();
-  pspace = add_program_space (aspace);
+  pspace = new program_space (aspace);
   inf = add_inferior (0);
   inf->pspace = pspace;
   inf->aspace = pspace->aspace;
@@ -854,7 +791,7 @@ add_inferior_command (const char *args, int from_tty)
             symbols.q.  */
          set_current_program_space (inf->pspace);
          set_current_inferior (inf);
-         switch_to_thread (null_ptid);
+         switch_to_no_thread ();
 
          exec_file_attach (exec.get (), from_tty);
          symbol_file_add_main (exec.get (), add_flags);
@@ -928,7 +865,7 @@ clone_inferior_command (const char *args, int from_tty)
         doesn't really return a new address space; otherwise, it
         really does.  */
       aspace = maybe_new_address_space ();
-      pspace = add_program_space (aspace);
+      pspace = new program_space (aspace);
       inf = add_inferior (0);
       inf->pspace = pspace;
       inf->aspace = pspace->aspace;
@@ -942,7 +879,7 @@ clone_inferior_command (const char *args, int from_tty)
       printf_filtered (_("Added inferior %d.\n"), inf->num);
 
       set_current_inferior (inf);
-      switch_to_thread (null_ptid);
+      switch_to_no_thread ();
       clone_program_space (pspace, orginf->pspace);
     }
 }
@@ -988,19 +925,22 @@ initialize_inferiors (void)
      can only allocate an inferior when all those modules have done
      that.  Do this after initialize_progspace, due to the
      current_program_space reference.  */
-  current_inferior_ = add_inferior (0);
+  current_inferior_ = add_inferior_silent (0);
   current_inferior_->incref ();
   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)."));
+  add_info ("inferiors", info_inferiors_command,
+           _("Print a list of inferiors being managed.\n\
+Usage: info inferiors [ID]...\n\
+If IDs are specified, the list is limited to just those inferiors.\n\
+By default all inferiors are displayed."));
 
   c = add_com ("add-inferior", no_class, add_inferior_command, _("\
 Add a new inferior.\n\
-Usage: add-inferior [-copies <N>] [-exec <FILENAME>]\n\
+Usage: add-inferior [-copies N] [-exec FILENAME]\n\
 N is the optional number of inferiors to add, default is 1.\n\
 FILENAME is the file name of the executable to use\n\
 as main program."));
@@ -1012,22 +952,25 @@ Usage: remove-inferiors ID..."));
 
   add_com ("clone-inferior", no_class, clone_inferior_command, _("\
 Clone inferior ID.\n\
-Usage: clone-inferior [-copies <N>] [ID]\n\
+Usage: clone-inferior [-copies N] [ID]\n\
 Add N copies of inferior ID.  The new inferior has the same\n\
 executable loaded as the copied inferior.  If -copies is not specified,\n\
 adds 1 copy.  If ID is not specified, it is the current inferior\n\
 that is cloned."));
 
   add_cmd ("inferiors", class_run, detach_inferior_command, _("\
-Detach from inferior ID (or list of IDS)."),
+Detach from inferior ID (or list of IDS).\n\
+Usage; detach inferiors ID..."),
           &detachlist);
 
   add_cmd ("inferiors", class_run, kill_inferior_command, _("\
-Kill inferior ID (or list of IDs)."),
+Kill inferior ID (or list of IDs).\n\
+Usage: kill inferiors ID..."),
           &killlist);
 
   add_cmd ("inferior", class_run, inferior_command, _("\
 Use this command to switch between inferiors.\n\
+Usage: inferior ID\n\
 The new inferior ID must be currently known."),
           &cmdlist);
 
This page took 0.03228 seconds and 4 git commands to generate.