2002-12-20 David Carlton <carlton@math.stanford.edu>
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index d84770c0d522a0f8abee9931b568d05d640c82e0..9c5e49fde608a42ff6ec62d7efeb4f361892a9ac 100644 (file)
@@ -1,5 +1,8 @@
 /* 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, 2002 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
 #include "objfiles.h"
 #include "gdb-stabs.h"
 #include "target.h"
+#include "bcache.h"
 
 #include <sys/types.h>
 #include "gdb_stat.h"
 #include <fcntl.h>
-#include "obstack.h"
+#include "gdb_obstack.h"
 #include "gdb_string.h"
 
 #include "breakpoint.h"
@@ -42,6 +46,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 +192,15 @@ 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->macro_cache.cache, xmmalloc);
+             obstack_freefun (&objfile->macro_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 +223,19 @@ 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->macro_cache.cache,
+                                                  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);
            }
        }
@@ -261,8 +272,8 @@ allocate_objfile (bfd *abfd, int flags)
       objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
       memset (objfile, 0, sizeof (struct objfile));
       objfile->md = NULL;
-      obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-                                 xmalloc, xfree);
+      objfile->psymbol_cache = bcache_xmalloc ();
+      objfile->macro_cache = bcache_xmalloc ();
       obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0, xmalloc,
                                  xfree);
       obstack_specify_allocation (&objfile->symbol_obstack, 0, 0, xmalloc,
@@ -279,7 +290,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 +381,8 @@ unlink_objfile (struct objfile *objfile)
        }
     }
 
-  internal_error ("objfiles.c (unlink_objfile): objfile already unlinked");
+  internal_error (__FILE__, __LINE__,
+                 "unlink_objfile: objfile already unlinked");
 }
 
 
@@ -438,9 +450,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 +477,19 @@ 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);
+      bcache_xfree (objfile->psymbol_cache);
+      bcache_xfree (objfile->macro_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 +568,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
@@ -852,7 +864,7 @@ 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)
     {
       xfree (symsfilename);
@@ -872,7 +884,7 @@ open_mapped_file (char *filename, long mtime, int flags)
   if ((fd < 0) && (flags & OBJF_MAPPED))
     {
       xfree (symsfilename);
-      symsfilename = concat ("./", basename (filename), ".syms",
+      symsfilename = concat ("./", lbasename (filename), ".syms",
                             (char *) NULL);
       if ((fd = open (symsfilename, O_RDWR | O_CREAT | O_TRUNC, 0666)) < 0)
        {
This page took 0.042021 seconds and 4 git commands to generate.