* gdbserver/low-hppabsd.c (read_inferior_memory): Add explicit
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index 5cdfb983bc64086835425e453f1469b1e836fe54..e86270964e0fcca3e70ae0c3e5ac9bdfe542b18e 100644 (file)
@@ -1,5 +1,6 @@
 /* GDB routines for manipulating objfiles.
-   Copyright 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -262,13 +263,13 @@ allocate_objfile (bfd *abfd, int flags)
       memset (objfile, 0, sizeof (struct objfile));
       objfile->md = NULL;
       obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-                                 xmalloc, free);
+                                 xmalloc, xfree);
       obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0, xmalloc,
-                                 free);
+                                 xfree);
       obstack_specify_allocation (&objfile->symbol_obstack, 0, 0, xmalloc,
-                                 free);
+                                 xfree);
       obstack_specify_allocation (&objfile->type_obstack, 0, 0, xmalloc,
-                                 free);
+                                 xfree);
       flags &= ~OBJF_MAPPED;
     }
 
@@ -370,7 +371,8 @@ unlink_objfile (struct objfile *objfile)
        }
     }
 
-  internal_error ("objfiles.c (unlink_objfile): objfile already unlinked");
+  internal_error (__FILE__, __LINE__,
+                 "unlink_objfile: objfile already unlinked");
 }
 
 
@@ -413,7 +415,7 @@ free_objfile (struct objfile *objfile)
       if (!bfd_close (objfile->obfd))
        warning ("cannot close \"%s\": %s",
                 name, bfd_errmsg (bfd_get_error ()));
-      free (name);
+      xfree (name);
     }
 
   /* Remove it from the chain of all objfiles. */
@@ -520,7 +522,7 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
     int something_changed = 0;
     for (i = 0; i < objfile->num_sections; ++i)
       {
-       ANOFFSET (delta, i) =
+       delta->offsets[i] =
          ANOFFSET (new_offsets, i) - ANOFFSET (objfile->section_offsets, i);
        if (ANOFFSET (delta, i) != 0)
          something_changed = 1;
@@ -564,6 +566,9 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
          for (j = 0; j < BLOCK_NSYMS (b); ++j)
            {
              struct symbol *sym = BLOCK_SYM (b, j);
+
+             fixup_symbol_section (sym, objfile);
+
              /* The RS6000 code from which this was taken skipped
                 any symbols in STRUCT_NAMESPACE or UNDEF_NAMESPACE.
                 But I'm leaving out that test, on the theory that
@@ -581,7 +586,7 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
 
              else if (SYMBOL_CLASS (sym) == LOC_CONST
                       && SYMBOL_NAMESPACE (sym) == LABEL_NAMESPACE
-                  && STRCMP (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
+                      && strcmp (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
                ecoff_relocate_efi (sym, ANOFFSET (delta,
                                                   s->block_line_section));
 #endif
@@ -606,15 +611,21 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
     for (psym = objfile->global_psymbols.list;
         psym < objfile->global_psymbols.next;
         psym++)
-      if (SYMBOL_SECTION (*psym) >= 0)
-       SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
-                                                 SYMBOL_SECTION (*psym));
+      {
+       fixup_psymbol_section (*psym, objfile);
+       if (SYMBOL_SECTION (*psym) >= 0)
+         SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
+                                                   SYMBOL_SECTION (*psym));
+      }
     for (psym = objfile->static_psymbols.list;
         psym < objfile->static_psymbols.next;
         psym++)
-      if (SYMBOL_SECTION (*psym) >= 0)
-       SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
-                                                 SYMBOL_SECTION (*psym));
+      {
+       fixup_psymbol_section (*psym, objfile);
+       if (SYMBOL_SECTION (*psym) >= 0)
+         SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
+                                                   SYMBOL_SECTION (*psym));
+      }
   }
 
   {
@@ -630,9 +641,21 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
   {
     int i;
     for (i = 0; i < objfile->num_sections; ++i)
-      ANOFFSET (objfile->section_offsets, i) = ANOFFSET (new_offsets, i);
+      (objfile->section_offsets)->offsets[i] = ANOFFSET (new_offsets, i);
   }
 
+  if (objfile->ei.entry_point != ~(CORE_ADDR) 0)
+    {
+      /* Relocate ei.entry_point with its section offset, use SECT_OFF_TEXT
+        only as a fallback.  */
+      struct obj_section *s;
+      s = find_pc_section (objfile->ei.entry_point);
+      if (s)
+        objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index);
+      else
+        objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
+    }
+
   {
     struct obj_section *s;
     bfd *abfd;
@@ -641,31 +664,13 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
 
     ALL_OBJFILE_OSECTIONS (objfile, s)
       {
-       flagword flags;
-
-       flags = bfd_get_section_flags (abfd, s->the_bfd_section);
-
-       if (flags & SEC_CODE)
-         {
-           s->addr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-           s->endaddr += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-         }
-       else if (flags & (SEC_DATA | SEC_LOAD))
-         {
-           s->addr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
-           s->endaddr += ANOFFSET (delta, SECT_OFF_DATA (objfile));
-         }
-       else if (flags & SEC_ALLOC)
-         {
-           s->addr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
-           s->endaddr += ANOFFSET (delta, SECT_OFF_BSS (objfile));
-         }
+       int idx = s->the_bfd_section->index;
+       
+       s->addr += ANOFFSET (delta, idx);
+       s->endaddr += ANOFFSET (delta, idx);
       }
   }
 
-  if (objfile->ei.entry_point != ~(CORE_ADDR) 0)
-    objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-
   if (objfile->ei.entry_func_lowpc != INVALID_ENTRY_LOWPC)
     {
       objfile->ei.entry_func_lowpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
@@ -852,7 +857,7 @@ open_mapped_file (char *filename, long mtime, int flags)
   symsfilename = concat ("./", basename (filename), ".syms", (char *) NULL);
   if ((fd = open_existing_mapped_file (symsfilename, mtime, flags)) < 0)
     {
-      free (symsfilename);
+      xfree (symsfilename);
       symsfilename = concat (filename, ".syms", (char *) NULL);
       fd = open_existing_mapped_file (symsfilename, mtime, flags);
     }
@@ -868,7 +873,7 @@ open_mapped_file (char *filename, long mtime, int flags)
 
   if ((fd < 0) && (flags & OBJF_MAPPED))
     {
-      free (symsfilename);
+      xfree (symsfilename);
       symsfilename = concat ("./", basename (filename), ".syms",
                             (char *) NULL);
       if ((fd = open (symsfilename, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
@@ -881,7 +886,7 @@ open_mapped_file (char *filename, long mtime, int flags)
        }
     }
 
-  free (symsfilename);
+  xfree (symsfilename);
   return (fd);
 }
 
This page took 0.025803 seconds and 4 git commands to generate.