[gdbserver] Move malloc.h include to server.h.
[deliverable/binutils-gdb.git] / gdb / inferior.c
index 87d9a457cef2ff90c102a068c3ba1c7740ef49f5..28c586792b8bc63219242809ee602c4b192a7487 100644 (file)
@@ -1,6 +1,6 @@
 /* Multi-process control for GDB, the GNU debugger.
 
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -29,6 +29,7 @@
 #include "gdbthread.h"
 #include "gdbcore.h"
 #include "symfile.h"
+#include "environ.h"
 
 void _initialize_inferiors (void);
 
@@ -67,6 +68,7 @@ static void
 restore_inferior (void *arg)
 {
   struct inferior *saved_inferior = arg;
+
   set_current_inferior (saved_inferior);
 }
 
@@ -79,6 +81,7 @@ save_current_inferior (void)
 {
   struct cleanup *old_chain = make_cleanup (restore_inferior,
                                            current_inferior_);
+
   return old_chain;
 }
 
@@ -87,6 +90,9 @@ free_inferior (struct inferior *inf)
 {
   discard_all_inferior_continuations (inf);
   inferior_free_data (inf);
+  xfree (inf->args);
+  xfree (inf->terminal);
+  free_environ (inf->environment);
   xfree (inf->private);
   xfree (inf);
 }
@@ -124,8 +130,13 @@ add_inferior_silent (int pid)
   inf->next = inferior_list;
   inferior_list = inf;
 
+  inf->environment = make_environ ();
+  init_environ (inf->environment);
+
   inferior_alloc_data (inf);
 
+  observer_notify_inferior_added (inf);
+
   if (pid != 0)
     inferior_appeared (inf, pid);
 
@@ -187,7 +198,7 @@ delete_threads_of_inferior (int pid)
 /* If SILENT then be quiet -- don't announce a inferior death, or the
    exit of its threads.  */
 
-static void
+void
 delete_inferior_1 (struct inferior *todel, int silent)
 {
   struct inferior *inf, *infprev;
@@ -212,6 +223,8 @@ delete_inferior_1 (struct inferior *todel, int silent)
   else
     inferior_list = inf->next;
 
+  observer_notify_inferior_removed (inf);
+
   free_inferior (inf);
 }
 
@@ -258,7 +271,7 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
 
   /* Notify the observers before removing the inferior from the list,
      so that the observers have a chance to look it up.  */
-  observer_notify_inferior_exit (inf->pid);
+  observer_notify_inferior_exit (inf);
 
   inf->pid = 0;
   if (inf->vfork_parent != NULL)
@@ -272,6 +285,7 @@ void
 exit_inferior (int pid)
 {
   struct inferior *inf = find_inferior_pid (pid);
+
   exit_inferior_1 (inf, 0);
 
   if (print_inferior_events)
@@ -282,6 +296,7 @@ void
 exit_inferior_silent (int pid)
 {
   struct inferior *inf = find_inferior_pid (pid);
+
   exit_inferior_1 (inf, 1);
 }
 
@@ -297,6 +312,7 @@ void
 detach_inferior (int pid)
 {
   struct inferior *inf = find_inferior_pid (pid);
+
   exit_inferior_1 (inf, 1);
 
   if (print_inferior_events)
@@ -308,7 +324,7 @@ inferior_appeared (struct inferior *inf, int pid)
 {
   inf->pid = pid;
 
-  observer_notify_inferior_appeared (pid);
+  observer_notify_inferior_appeared (inf);
 }
 
 void
@@ -516,8 +532,6 @@ print_inferior (struct ui_out *uiout, int requested_inferior)
   /* Compute number of inferiors we will print.  */
   for (inf = inferior_list; inf; inf = inf->next)
     {
-      struct cleanup *chain2;
-
       if (requested_inferior != -1 && inf->num != requested_inferior)
        continue;
 
@@ -731,6 +745,24 @@ remove_inferior_command (char *args, int from_tty)
   delete_inferior_1 (inf, 1);
 }
 
+struct inferior *
+add_inferior_with_spaces (void)
+{
+  struct address_space *aspace;
+  struct program_space *pspace;
+  struct inferior *inf;
+
+  /* If all inferiors share an address space on this system, this
+     doesn't really return a new address space; otherwise, it
+     really does.  */
+  aspace = maybe_new_address_space ();
+  pspace = add_program_space (aspace);
+  inf = add_inferior (0);
+  inf->pspace = pspace;
+  inf->aspace = pspace->aspace;
+
+  return inf;
+}
 
 /* add-inferior [-copies N] [-exec FILENAME]  */
 
@@ -775,18 +807,7 @@ add_inferior_command (char *args, int from_tty)
 
   for (i = 0; i < copies; ++i)
     {
-      struct address_space *aspace;
-      struct program_space *pspace;
-      struct inferior *inf;
-
-      /* If all inferiors share an address space on this system, this
-        doesn't really return a new address space; otherwise, it
-        really does.  */
-      aspace = maybe_new_address_space ();
-      pspace = add_program_space (aspace);
-      inf = add_inferior (0);
-      inf->pspace = pspace;
-      inf->aspace = pspace->aspace;
+      struct inferior *inf = add_inferior_with_spaces ();
 
       printf_filtered (_("Added inferior %d\n"), inf->num);
 
@@ -794,7 +815,7 @@ add_inferior_command (char *args, int from_tty)
        {
          /* Switch over temporarily, while reading executable and
             symbols.q  */
-         set_current_program_space (pspace);
+         set_current_program_space (inf->pspace);
          set_current_inferior (inf);
          switch_to_thread (null_ptid);
 
This page took 0.025341 seconds and 4 git commands to generate.