* corelow.c, exec.c, inftarg.c, m3-nat.c, op50-rom.c, procfs.c,
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index 530e19b054b58a85a49e81eb25425fbac813221d..891531d3d89c0990ee7c9cbffe6384049c6980a7 100644 (file)
@@ -123,6 +123,7 @@ allocate_objfile (abfd, mapped)
      int mapped;
 {
   struct objfile *objfile = NULL;
+  struct objfile *last_one = NULL;
 
   mapped |= mapped_symbol_files;
 
@@ -257,14 +258,42 @@ allocate_objfile (abfd, mapped)
             objfile -> name, bfd_errmsg (bfd_get_error ()));
     }
 
-  /* Push this file onto the head of the linked list of other such files. */
-
-  objfile -> next = object_files;
-  object_files = objfile;
+  /* Add this file onto the tail of the linked list of other such files. */
 
+  objfile -> next = NULL;
+  if (object_files == NULL)
+    object_files = objfile;
+  else
+    {
+      for (last_one = object_files;
+          last_one -> next;
+          last_one = last_one -> next);
+      last_one -> next = objfile;
+    }
   return (objfile);
 }
 
+/* Put OBJFILE at the front of the list.  */
+
+void
+objfile_to_front (objfile)
+     struct objfile *objfile;
+{
+  struct objfile **objp;
+  for (objp = &object_files; *objp != NULL; objp = &((*objp)->next))
+    {
+      if (*objp == objfile)
+       {
+         /* Unhook it from where it is.  */
+         *objp = objfile->next;
+         /* Put it in the front.  */
+         objfile->next = object_files;
+         object_files = objfile;
+         break;
+       }
+    }
+}
+
 /* Unlink OBJFILE from the list of known objfiles, if it is found in the
    list.
 
@@ -333,7 +362,9 @@ free_objfile (objfile)
   if (objfile -> obfd != NULL)
     {
       char *name = bfd_get_filename (objfile->obfd);
-      bfd_close (objfile -> obfd);
+      if (!bfd_close (objfile -> obfd))
+       warning ("cannot close \"%s\": %s",
+                name, bfd_errmsg (bfd_get_error ()));
       free (name);
     }
 
@@ -541,6 +572,9 @@ objfile_relocate (objfile, new_offsets)
       if (SYMBOL_SECTION (msym) >= 0)
        SYMBOL_VALUE_ADDRESS (msym) += ANOFFSET (delta, SYMBOL_SECTION (msym));
   }
+  /* Relocating different sections by different amounts may cause the symbols
+     to be out of order.  */
+  msymbols_sort (objfile);
 
   {
     int i;
@@ -552,10 +586,10 @@ objfile_relocate (objfile, new_offsets)
     struct obj_section *s;
     bfd *abfd;
 
-    abfd = symfile_objfile->obfd;
+    abfd = objfile->obfd;
 
-    for (s = symfile_objfile->sections;
-        s < symfile_objfile->sections_end; ++s)
+    for (s = objfile->sections;
+        s < objfile->sections_end; ++s)
       {
        flagword flags;
 
@@ -578,6 +612,27 @@ objfile_relocate (objfile, new_offsets)
          }
       }
   }
+
+  if (objfile->ei.entry_point != ~0)
+    objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT);
+
+  if (objfile->ei.entry_func_lowpc != INVALID_ENTRY_LOWPC)
+    {
+      objfile->ei.entry_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+      objfile->ei.entry_func_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+    }
+
+  if (objfile->ei.entry_file_lowpc != INVALID_ENTRY_LOWPC)
+    {
+      objfile->ei.entry_file_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+      objfile->ei.entry_file_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+    }
+
+  if (objfile->ei.main_func_lowpc != INVALID_ENTRY_LOWPC)
+    {
+      objfile->ei.main_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT);
+      objfile->ei.main_func_highpc += ANOFFSET (delta, SECT_OFF_TEXT);
+    }
 }
 \f
 /* Many places in gdb want to test just to see if we have any partial
This page took 0.025095 seconds and 4 git commands to generate.