Support arch-dependent fill
[binutils-gdb.git] / gdb / progspace.c
index 1a465ce42cc6bd41200be1ef870d1839ab9b63f5..54531d9b1fb20b014dae90b95b7e1ed0a2448712 100644 (file)
@@ -1,6 +1,6 @@
 /* Program and address space management, for GDB, the GNU debugger.
 
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -89,6 +89,12 @@ free_address_space (struct address_space *aspace)
   xfree (aspace);
 }
 
+int
+address_space_num (struct address_space *aspace)
+{
+  return aspace->num;
+}
+
 /* Start counting over from scratch.  */
 
 static void
@@ -143,6 +149,7 @@ release_program_space (struct program_space *pspace)
     free_address_space (pspace->aspace);
   resize_section_table (&pspace->target_sections,
                        -resize_section_table (&pspace->target_sections, 0));
+  clear_program_space_solib_cache (pspace);
     /* Discard any data modules have associated with the PSPACE.  */
   program_space_free_data (pspace);
   xfree (pspace);
@@ -180,7 +187,6 @@ remove_program_space (struct program_space *pspace)
 struct program_space *
 clone_program_space (struct program_space *dest, struct program_space *src)
 {
-  struct program_space *new_pspace;
   struct cleanup *old_chain;
 
   old_chain = save_current_program_space ();
@@ -222,6 +228,7 @@ static void
 restore_program_space (void *arg)
 {
   struct program_space *saved_pspace = arg;
+
   set_current_program_space (saved_pspace);
 }
 
@@ -234,21 +241,8 @@ save_current_program_space (void)
 {
   struct cleanup *old_chain = make_cleanup (restore_program_space,
                                            current_program_space);
-  return old_chain;
-}
 
-/* Find program space number NUM; returns NULL if not found.  */
-
-static struct program_space *
-find_program_space_by_num (int num)
-{
-  struct program_space *pspace;
-
-  ALL_PSPACES (pspace)
-    if (pspace->num == num)
-      return pspace;
-
-  return NULL;
+  return old_chain;
 }
 
 /* Returns true iff there's no inferior bound to PSPACE.  */
@@ -256,8 +250,6 @@ find_program_space_by_num (int num)
 static int
 pspace_empty_p (struct program_space *pspace)
 {
-  struct inferior *inf;
-
   if (find_inferior_for_program_space (pspace) != NULL)
       return 0;
 
@@ -406,7 +398,7 @@ maintenance_info_program_spaces_command (char *args, int from_tty)
        error (_("program space ID %d not known."), requested);
     }
 
-  print_program_space (uiout, requested);
+  print_program_space (current_uiout, requested);
 }
 
 /* Simply returns the count of program spaces.  */
@@ -438,24 +430,31 @@ void
 update_address_spaces (void)
 {
   int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch);
-  struct address_space *aspace = NULL;
   struct program_space *pspace;
+  struct inferior *inf;
 
   init_address_spaces ();
 
-  ALL_PSPACES (pspace)
+  if (shared_aspace)
     {
-      free_address_space (pspace->aspace);
+      struct address_space *aspace = new_address_space ();
 
-      if (shared_aspace)
-       {
-         if (aspace == NULL)
-           aspace = new_address_space ();
-         pspace->aspace = aspace;
-       }
-      else
-       pspace->aspace = new_address_space ();
+      free_address_space (current_program_space->aspace);
+      ALL_PSPACES (pspace)
+       pspace->aspace = aspace;
     }
+  else
+    ALL_PSPACES (pspace)
+      {
+       free_address_space (pspace->aspace);
+       pspace->aspace = new_address_space ();
+      }
+
+  for (inf = inferior_list; inf; inf = inf->next)
+    if (gdbarch_has_global_solist (target_gdbarch))
+      inf->aspace = maybe_new_address_space ();
+    else
+      inf->aspace = inf->pspace->aspace;
 }
 
 /* Save the current program space so that it may be restored by a later
@@ -505,6 +504,22 @@ switch_to_program_space_and_thread (struct program_space *pspace)
 
 \f
 
+/* See progspace.h.  */
+
+void
+clear_program_space_solib_cache (struct program_space *pspace)
+{
+  int ix;
+  char *name;
+
+  VEC_free (so_list_ptr, pspace->added_solibs);
+  for (ix = 0; VEC_iterate (char_ptr, pspace->deleted_solibs, ix, name); ++ix)
+    xfree (name);
+  VEC_free (char_ptr, pspace->deleted_solibs);
+}
+
+\f
+
 /* Keep a registry of per-program_space data-pointers required by other GDB
    modules.  */
 
@@ -598,7 +613,8 @@ set_program_space_data (struct program_space *pspace,
 }
 
 void *
-program_space_data (struct program_space *pspace, const struct program_space_data *data)
+program_space_data (struct program_space *pspace,
+                   const struct program_space_data *data)
 {
   gdb_assert (data->index < pspace->num_data);
   return pspace->data[data->index];
@@ -610,8 +626,8 @@ void
 initialize_progspace (void)
 {
   add_cmd ("program-spaces", class_maintenance,
-          maintenance_info_program_spaces_command, _("\
-Info about currently known program spaces."),
+          maintenance_info_program_spaces_command,
+          _("Info about currently known program spaces."),
           &maintenanceinfolist);
 
   /* There's always one program space.  Note that this function isn't