Introduce program_space::add_objfile
authorTom Tromey <tom@tromey.com>
Fri, 1 Nov 2019 22:31:28 +0000 (16:31 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 12 Dec 2019 22:50:52 +0000 (15:50 -0700)
This introduces a new method, program_space::add_objfile, that adds an
objfile to the program space's list of objfiles.  It also changes the
obfile's constructor so that linking an objfile into this list is not
done here.

The former is an improvement because it makes more sense to treat the
program space as a container holding objfiles -- so manipulation of
the list belongs there.

The latter is not strictly needed, but seemed better both because it
is removing a global side effect from a constructor, and for symmetry
reasons, as a subsequent patch will remove unlinking from the
destructor.

gdb/ChangeLog
2019-12-12  Tom Tromey  <tom@tromey.com>

* progspace.h (struct program_space) <add_objfile>: Declare
method.
* progspace.c (program_space::add_objfile): New method.
* objfiles.c (~objfile): Don't unlink objfile.
(put_objfile_before): Remove.
(add_separate_debug_objfile): Don't call put_objfile_before.
(objfile::make): Call add_objfile.  Set new_objfiles_available on
the per-program-space data.

Change-Id: I93e8525dda631cb89dcc2046a5c51c7c9f34ccfd

gdb/ChangeLog
gdb/objfiles.c
gdb/progspace.c
gdb/progspace.h

index 07d679b0edc86848cfcbde7536e631e8f75063ce..01636119d99f6e7980c379ecb88585dd3bbadaca 100644 (file)
@@ -1,3 +1,14 @@
+2019-12-12  Tom Tromey  <tom@tromey.com>
+
+       * progspace.h (struct program_space) <add_objfile>: Declare
+       method.
+       * progspace.c (program_space::add_objfile): New method.
+       * objfiles.c (~objfile): Don't unlink objfile.
+       (put_objfile_before): Remove.
+       (add_separate_debug_objfile): Don't call put_objfile_before.
+       (objfile::make): Call add_objfile.  Set new_objfiles_available on
+       the per-program-space data.
+
 2019-12-12  Tom Tromey  <tom@tromey.com>
 
        * symfile.c (syms_from_objfile_1): Use objfile_up.
index a635f7783e6e9e545ae141bb3292592040bc1306..b4fb6f2d18c4ec49ddfe6d0018e0d1905fb8ba34 100644 (file)
@@ -371,23 +371,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.  */
@@ -494,30 +477,6 @@ unlink_objfile (struct objfile *objfile)
                  _("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 +494,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 +505,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;
 }
 
index 366de546bb569c6745a7a2d9a852b349cd7dd204..5aa7a3d177e488a24c218e8ba617dbf78b84df62 100644 (file)
@@ -153,6 +153,28 @@ program_space::~program_space ()
   program_space_free_data (this);
 }
 
+/* See progspace.h.  */
+
+void
+program_space::add_objfile (struct objfile *objfile, struct objfile *before)
+{
+  for (struct objfile **objp = &objfiles_head;
+       *objp != NULL;
+       objp = &((*objp)->next))
+    {
+      if (*objp == before)
+       {
+         objfile->next = *objp;
+         *objp = objfile;
+         return;
+       }
+    }
+
+  internal_error (__FILE__, __LINE__,
+                 _("put_objfile_before: before objfile not in list"));
+
+}
+
 /* Copies program space SRC to DEST.  Copies the main executable file,
    and the main symbol file.  Returns DEST.  */
 
index c281648b99bff35a98f0c3e10224a6e34ee99357..bb10c4bbd26c74dd001258ddea5804642e0f60cf 100644 (file)
@@ -165,6 +165,12 @@ struct program_space
     return objfiles_safe_range (objfiles_head);
   }
 
+  /* Add OBJFILE to the list of objfiles, putting it just before
+     BEFORE.  If BEFORE is nullptr, it will go at the end of the
+     list.  */
+  void add_objfile (struct objfile *objfile, struct objfile *before);
+
+
   /* Pointer to next in linked list.  */
   struct program_space *next = NULL;
 
This page took 0.033252 seconds and 4 git commands to generate.