Move free_all_objfiles to program_space
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index a635f7783e6e9e545ae141bb3292592040bc1306..56854cc5c63bdf92de7263faad8f492970119134 100644 (file)
@@ -54,6 +54,7 @@
 #include "btrace.h"
 #include "gdbsupport/pathstuff.h"
 
+#include <algorithm>
 #include <vector>
 
 /* Keep a registry of per-objfile data-pointers required by other GDB
@@ -371,23 +372,6 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
     }
 
   per_bfd = get_objfile_bfd_data (this, abfd);
-
-  /* Add this file onto the tail of the linked list of other such files.  */
-
-  if (object_files == NULL)
-    object_files = this;
-  else
-    {
-      struct objfile *last_one;
-
-      for (last_one = object_files;
-          last_one->next;
-          last_one = last_one->next);
-      last_one->next = this;
-    }
-
-  /* Rebuild section map next time we need it.  */
-  get_objfile_pspace_data (pspace)->new_objfiles_available = 1;
 }
 
 /* Retrieve the gdbarch associated with OBJFILE.  */
@@ -473,51 +457,6 @@ separate_debug_iterator::operator++ ()
   return *this;
 }
 
-/* Unlink OBJFILE from the list of known objfiles.  */
-
-static void
-unlink_objfile (struct objfile *objfile)
-{
-  struct objfile **objpp;
-
-  for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
-    {
-      if (*objpp == objfile)
-       {
-         *objpp = (*objpp)->next;
-         objfile->next = NULL;
-         return;
-       }
-    }
-
-  internal_error (__FILE__, __LINE__,
-                 _("unlink_objfile: objfile already unlinked"));
-}
-
-/* Put one object file before a specified on in the global list.
-   This can be used to make sure an object file is destroyed before
-   another when using objfiles_safe to free all objfiles.  */
-static void
-put_objfile_before (struct objfile *objfile, struct objfile *before_this)
-{
-  struct objfile **objp;
-
-  unlink_objfile (objfile);
-  
-  for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
-    {
-      if (*objp == before_this)
-       {
-         objfile->next = *objp;
-         *objp = objfile;
-         return;
-       }
-    }
-  
-  internal_error (__FILE__, __LINE__,
-                 _("put_objfile_before: before objfile not in list"));
-}
-
 /* Add OBJFILE as a separate debug objfile of PARENT.  */
 
 static void
@@ -535,10 +474,6 @@ add_separate_debug_objfile (struct objfile *objfile, struct objfile *parent)
   objfile->separate_debug_objfile_backlink = parent;
   objfile->separate_debug_objfile_link = parent->separate_debug_objfile;
   parent->separate_debug_objfile = objfile;
-
-  /* Put the separate debug object before the normal one, this is so that
-     usage of objfiles_safe will stay safe.  */
-  put_objfile_before (objfile, parent);
 }
 
 /* See objfiles.h.  */
@@ -550,6 +485,12 @@ objfile::make (bfd *bfd_, const char *name_, objfile_flags flags_,
   objfile *result = new objfile (bfd_, name_, flags_);
   if (parent != nullptr)
     add_separate_debug_objfile (result, parent);
+
+  current_program_space->add_objfile (result, parent);
+
+  /* Rebuild section map next time we need it.  */
+  get_objfile_pspace_data (current_program_space)->new_objfiles_available = 1;
+
   return result;
 }
 
@@ -558,6 +499,7 @@ objfile::make (bfd *bfd_, const char *name_, objfile_flags flags_,
 void
 objfile::unlink ()
 {
+  current_program_space->remove_objfile (this);
   delete this;
 }
 
@@ -648,13 +590,6 @@ objfile::~objfile ()
   else
     delete per_bfd;
 
-  /* Remove it from the chain of all objfiles.  */
-
-  unlink_objfile (this);
-
-  if (this == symfile_objfile)
-    symfile_objfile = NULL;
-
   /* Before the symbol table code was redone to make it easier to
      selectively load and remove information particular to a specific
      linkage unit, gdb used to do these things whenever the monolithic
@@ -683,21 +618,6 @@ objfile::~objfile ()
   get_objfile_pspace_data (pspace)->section_map_dirty = 1;
 }
 
-/* Free all the object files at once and clean up their users.  */
-
-void
-free_all_objfiles (void)
-{
-  struct so_list *so;
-
-  /* Any objfile reference would become stale.  */
-  for (so = master_so_list (); so; so = so->next)
-    gdb_assert (so->objfile == NULL);
-
-  for (objfile *objfile : current_program_space->objfiles_safe ())
-    objfile->unlink ();
-  clear_symtab_users (0);
-}
 \f
 /* A helper function for objfile_relocate1 that relocates a single
    symbol.  */
This page took 0.031368 seconds and 4 git commands to generate.