Contribute sh64-elf.
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index e0228f55c99047b5d7b51bf2ee1f900b9c5a9dc0..e2a6f8505546c311271ceabbd5faa01c94c5321c 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.
@@ -42,6 +43,8 @@
 
 #if defined(USE_MMALLOC) && defined(HAVE_MMAP)
 
+#include "mmalloc.h"
+
 static int open_existing_mapped_file (char *, long, int);
 
 static int open_mapped_file (char *filename, long mtime, int flags);
@@ -186,13 +189,13 @@ allocate_objfile (bfd *abfd, int flags)
              objfile->mmfd = fd;
              /* Update pointers to functions to *our* copies */
              obstack_chunkfun (&objfile->psymbol_cache.cache, xmmalloc);
-             obstack_freefun (&objfile->psymbol_cache.cache, mfree);
+             obstack_freefun (&objfile->psymbol_cache.cache, xmfree);
              obstack_chunkfun (&objfile->psymbol_obstack, xmmalloc);
-             obstack_freefun (&objfile->psymbol_obstack, mfree);
+             obstack_freefun (&objfile->psymbol_obstack, xmfree);
              obstack_chunkfun (&objfile->symbol_obstack, xmmalloc);
-             obstack_freefun (&objfile->symbol_obstack, mfree);
+             obstack_freefun (&objfile->symbol_obstack, xmfree);
              obstack_chunkfun (&objfile->type_obstack, xmmalloc);
-             obstack_freefun (&objfile->type_obstack, mfree);
+             obstack_freefun (&objfile->type_obstack, xmfree);
              /* If already in objfile list, unlink it. */
              unlink_objfile (objfile);
              /* Forget things specific to a particular gdb, may have changed. */
@@ -215,16 +218,16 @@ allocate_objfile (bfd *abfd, int flags)
              objfile->flags |= OBJF_MAPPED;
              mmalloc_setkey (objfile->md, 0, objfile);
              obstack_specify_allocation_with_arg (&objfile->psymbol_cache.cache,
-                                                  0, 0, xmmalloc, mfree,
+                                                  0, 0, xmmalloc, xmfree,
                                                   objfile->md);
              obstack_specify_allocation_with_arg (&objfile->psymbol_obstack,
-                                                  0, 0, xmmalloc, mfree,
+                                                  0, 0, xmmalloc, xmfree,
                                                   objfile->md);
              obstack_specify_allocation_with_arg (&objfile->symbol_obstack,
-                                                  0, 0, xmmalloc, mfree,
+                                                  0, 0, xmmalloc, xmfree,
                                                   objfile->md);
              obstack_specify_allocation_with_arg (&objfile->type_obstack,
-                                                  0, 0, xmmalloc, mfree,
+                                                  0, 0, xmmalloc, xmfree,
                                                   objfile->md);
            }
        }
@@ -262,13 +265,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;
     }
 
@@ -279,7 +282,7 @@ allocate_objfile (bfd *abfd, int flags)
   objfile->obfd = abfd;
   if (objfile->name != NULL)
     {
-      mfree (objfile->md, objfile->name);
+      xmfree (objfile->md, objfile->name);
     }
   if (abfd != NULL)
     {
@@ -370,7 +373,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 +417,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. */
@@ -438,9 +442,9 @@ free_objfile (struct objfile *objfile)
   clear_pc_function_cache ();
 
   /* The last thing we do is free the objfile struct itself for the
-     non-reusable case, or detach from the mapped file for the reusable
-     case.  Note that the mmalloc_detach or the mfree is the last thing
-     we can do with this objfile. */
+     non-reusable case, or detach from the mapped file for the
+     reusable case.  Note that the mmalloc_detach or the xmfree() is
+     the last thing we can do with this objfile. */
 
 #if defined(USE_MMALLOC) && defined(HAVE_MMAP)
 
@@ -465,18 +469,18 @@ free_objfile (struct objfile *objfile)
     {
       if (objfile->name != NULL)
        {
-         mfree (objfile->md, objfile->name);
+         xmfree (objfile->md, objfile->name);
        }
       if (objfile->global_psymbols.list)
-       mfree (objfile->md, objfile->global_psymbols.list);
+       xmfree (objfile->md, objfile->global_psymbols.list);
       if (objfile->static_psymbols.list)
-       mfree (objfile->md, objfile->static_psymbols.list);
+       xmfree (objfile->md, objfile->static_psymbols.list);
       /* Free the obstacks for non-reusable objfiles */
       free_bcache (&objfile->psymbol_cache);
       obstack_free (&objfile->psymbol_obstack, 0);
       obstack_free (&objfile->symbol_obstack, 0);
       obstack_free (&objfile->type_obstack, 0);
-      mfree (objfile->md, objfile);
+      xmfree (objfile->md, objfile);
       objfile = NULL;
     }
 }
@@ -555,16 +559,15 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
       for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
        {
          struct block *b;
+         struct symbol *sym;
          int j;
 
          b = BLOCKVECTOR_BLOCK (bv, i);
          BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
          BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
 
-         for (j = 0; j < BLOCK_NSYMS (b); ++j)
+         ALL_BLOCK_SYMBOLS (b, j, sym)
            {
-             struct symbol *sym = BLOCK_SYM (b, j);
-
              fixup_symbol_section (sym, objfile);
 
              /* The RS6000 code from which this was taken skipped
@@ -584,7 +587,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
@@ -642,6 +645,18 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
       (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;
@@ -650,31 +665,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));
@@ -858,10 +855,10 @@ open_mapped_file (char *filename, long mtime, int flags)
   /* First try to open an existing file in the current directory, and
      then try the directory where the symbol file is located. */
 
-  symsfilename = concat ("./", basename (filename), ".syms", (char *) NULL);
+  symsfilename = concat ("./", lbasename (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);
     }
@@ -877,8 +874,8 @@ open_mapped_file (char *filename, long mtime, int flags)
 
   if ((fd < 0) && (flags & OBJF_MAPPED))
     {
-      free (symsfilename);
-      symsfilename = concat ("./", basename (filename), ".syms",
+      xfree (symsfilename);
+      symsfilename = concat ("./", lbasename (filename), ".syms",
                             (char *) NULL);
       if ((fd = open (symsfilename, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
        {
@@ -890,7 +887,7 @@ open_mapped_file (char *filename, long mtime, int flags)
        }
     }
 
-  free (symsfilename);
+  xfree (symsfilename);
   return (fd);
 }
 
This page took 0.026946 seconds and 4 git commands to generate.