* progspace.c (update_address_spaces): Update inferior address spaces
[binutils-gdb.git] / gdb / progspace.c
index 1a465ce42cc6bd41200be1ef870d1839ab9b63f5..42139fd4599e3bcc7f6bcfe7d3b5a64ed6162bfd 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, 2010 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
@@ -237,20 +243,6 @@ save_current_program_space (void)
   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;
-}
-
 /* Returns true iff there's no inferior bound to PSPACE.  */
 
 static int
@@ -438,24 +430,30 @@ 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);
-
-      if (shared_aspace)
-       {
-         if (aspace == NULL)
-           aspace = new_address_space ();
-         pspace->aspace = aspace;
-       }
-      else
-       pspace->aspace = new_address_space ();
+      struct address_space *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