OSDN Git Service

* bcache.h: Update copyright.
authorcagney <cagney>
Fri, 12 Jul 2002 15:23:09 +0000 (15:23 +0000)
committercagney <cagney>
Fri, 12 Jul 2002 15:23:09 +0000 (15:23 +0000)
(struct bstring, struct bcache): Move definition to "bcache.c".
Replaced by opaque declaration.
(bcache_xfree): Replace free_bcache.
(bcache_xmalloc, bcache_memory_used): Declare.

* bcache.c: Update copyright.
(struct bstring, struct bcache): Moved to here from "bcache.h".
Update comments.
(bcache_xmalloc, bcache_memory_used): New functions.
(bcache_xfree): Replace function free_bcache.

* Makefile.in (objfiles.o): Add $(bcache_h).
(objfiles_h): Remove $(bcache_h).
(symfile.o): Add $(bcache_h).

* symmisc.c: Update copyright.
(print_symbol_bcache_statistics): Pass psymbol_cache by value.
(print_objfile_statistics): Use bcache_memory_used.

* symfile.c: Include "bcache.h".
(reread_symbols): Use bcache_xfree.
(reread_symbols): Use bcache_xmalloc and bcache_xfree.
(add_psymbol_to_list): Pass psymbol_cache by value.
(add_psymbol_with_dem_name_to_list): Ditto.

* objfiles.h: Update copyright.
(struct bcache): Declare opaque.  Do not include "bcache.h".
(struct objfile): Change psymbol_cache and macro_cache to ``struct
bcache'' pointers.
* dwarf2read.c (macro_start_file): Pass macro_cache by value.

* objfiles.c: Include "bcache.h".  Update copyright.
(allocate_objfile): Use bcache_xmalloc to create psymbol_cache and
macro_cache.
(free_objfile): Use bcache_xfree.

gdb/ChangeLog
gdb/Makefile.in
gdb/bcache.c
gdb/bcache.h
gdb/dwarf2read.c
gdb/objfiles.c
gdb/objfiles.h
gdb/symfile.c
gdb/symmisc.c

index 977f96c..a1a599c 100644 (file)
@@ -1,3 +1,42 @@
+2002-07-12  Andrew Cagney  <ac131313@redhat.com>
+
+       * bcache.h: Update copyright.
+       (struct bstring, struct bcache): Move definition to "bcache.c".
+       Replaced by opaque declaration.
+       (bcache_xfree): Replace free_bcache.
+       (bcache_xmalloc, bcache_memory_used): Declare.
+       
+       * bcache.c: Update copyright.
+       (struct bstring, struct bcache): Moved to here from "bcache.h".
+       Update comments.
+       (bcache_xmalloc, bcache_memory_used): New functions.
+       (bcache_xfree): Replace function free_bcache.
+       
+       * Makefile.in (objfiles.o): Add $(bcache_h).
+       (objfiles_h): Remove $(bcache_h).
+       (symfile.o): Add $(bcache_h).
+
+       * symmisc.c: Update copyright.
+       (print_symbol_bcache_statistics): Pass psymbol_cache by value.
+       (print_objfile_statistics): Use bcache_memory_used.
+
+       * symfile.c: Include "bcache.h".
+       (reread_symbols): Use bcache_xfree.
+       (reread_symbols): Use bcache_xmalloc and bcache_xfree.
+       (add_psymbol_to_list): Pass psymbol_cache by value.
+       (add_psymbol_with_dem_name_to_list): Ditto.
+
+       * objfiles.h: Update copyright.
+       (struct bcache): Declare opaque.  Do not include "bcache.h".
+       (struct objfile): Change psymbol_cache and macro_cache to ``struct
+       bcache'' pointers.
+       * dwarf2read.c (macro_start_file): Pass macro_cache by value.
+
+       * objfiles.c: Include "bcache.h".  Update copyright.
+       (allocate_objfile): Use bcache_xmalloc to create psymbol_cache and
+       macro_cache.
+       (free_objfile): Use bcache_xfree.
+
 2002-07-11  Grace Sainsbury  <graces@redhat.com>
 
        * monitor.c (monitor_fetch_register): Make name a constant.
index 99538e2..1919ee5 100644 (file)
@@ -641,7 +641,7 @@ macrotab_h =    macrotab.h
 macroscope_h =  macroscope.h $(macrotab_h) $(symtab_h)
 memattr_h =     memattr.h
 monitor_h =    monitor.h
-objfiles_h =   objfiles.h $(bcache_h)
+objfiles_h =   objfiles.h
 parser_defs_h =        parser-defs.h $(doublest_h)
 ppc_tdep_h =   ppc-tdep.h osabi.h
 regcache_h =   regcache.h
@@ -1871,7 +1871,7 @@ nindy-tdep.o: nindy-tdep.c $(defs_h) $(frame_h) $(symtab_h)  $(gdbcore_h)
 ns32k-tdep.o: ns32k-tdep.c $(bfd_h) $(dis_asm_h) $(defs_h)
 
 objfiles.o: objfiles.c $(bfd_h) $(defs_h) $(objfiles_h) $(symfile_h) \
-       $(symtab_h) $(gdb_string_h) $(breakpoint_h)
+       $(symtab_h) $(gdb_string_h) $(breakpoint_h) $(bcache_h)
 
 solib-osf.o: solib-osf.c $(defs_h) $(inferior_h) $(symtab_h) $(objfiles_h) \
        $(symfile_h) $(target_h) $(gdb_string_h) $(solist_h)
@@ -2167,7 +2167,7 @@ sun3-nat.o: sun3-nat.c $(defs_h) $(gdbcore_h) $(inferior_h) $(regcache_h)
 symfile.o: symfile.c $(breakpoint_h) $(complaints_h) $(defs_h) \
        $(expression_h) $(gdb_stabs_h) $(gdbcmd_h) $(gdbcore_h) \
        $(gdbtypes_h) $(language_h) $(objfiles_h) $(symfile_h) $(symtab_h) \
-       $(target_h) $(gdb_string_h) $(completer_h)
+       $(target_h) $(gdb_string_h) $(completer_h) $(bcache_h)
 
 symm-tdep.o: symm-tdep.c $(defs_h) $(gdbcore_h) $(inferior_h)
 
index 73b86e8..c5173e1 100644 (file)
 #include <stddef.h>
 #include <stdlib.h>
 
+/* The type used to hold a single bcache string.  The user data is
+   stored in d.data.  Since it can be any type, it needs to have the
+   same alignment as the most strict alignment of any type on the host
+   machine.  I don't know of any really correct way to do this in
+   stock ANSI C, so just do it the same way obstack.h does.  */
+
+struct bstring
+{
+  struct bstring *next;
+  size_t length;
+
+  union
+  {
+    char data[1];
+    double dummy;
+  }
+  d;
+};
+
+
+/* The structure for a bcache itself.  The bcache is initialized, in
+   bcache_xmalloc(), by filling it with zeros and then setting the
+   corresponding obstack's malloc() and free() methods.  */
+
+struct bcache
+{
+  /* All the bstrings are allocated here.  */
+  struct obstack cache;
+
+  /* How many hash buckets we're using.  */
+  unsigned int num_buckets;
+  
+  /* Hash buckets.  This table is allocated using malloc, so when we
+     grow the table we can return the old table to the system.  */
+  struct bstring **bucket;
+
+  /* Statistics.  */
+  unsigned long unique_count;  /* number of unique strings */
+  long total_count;    /* total number of strings cached, including dups */
+  long unique_size;    /* size of unique strings, in bytes */
+  long total_size;      /* total number of bytes cached, including dups */
+  long structure_size; /* total size of bcache, including infrastructure */
+};
+
 /* The old hash function was stolen from SDBM. This is what DB 3.0 uses now,
  * and is better than the old one. 
  */
@@ -166,19 +210,26 @@ bcache (const void *addr, int length, struct bcache *bcache)
 }
 
 \f
-/* Freeing bcaches.  */
+/* Allocating and freeing bcaches.  */
+
+struct bcache *
+bcache_xmalloc (void)
+{
+  /* Allocate the bcache pre-zeroed.  */
+  struct bcache *b = XCALLOC (1, struct bcache);
+  obstack_specify_allocation (&b->cache, 0, 0, xmalloc, xfree);
+  return b;
+}
 
 /* Free all the storage associated with BCACHE.  */
 void
-free_bcache (struct bcache *bcache)
+bcache_xfree (struct bcache *bcache)
 {
+  if (bcache == NULL)
+    return;
   obstack_free (&bcache->cache, 0);
-  if (bcache->bucket)
-    xfree (bcache->bucket);
-
-  /* This isn't necessary, but at least the bcache is always in a
-     consistent state.  */
-  memset (bcache, 0, sizeof (*bcache));
+  xfree (bcache->bucket);
+  xfree (bcache);
 }
 
 
@@ -291,3 +342,9 @@ print_bcache_statistics (struct bcache *c, char *type)
   printf_filtered ("    Maximum hash chain length: %3d\n", max_chain_length);
   printf_filtered ("\n");
 }
+
+int
+bcache_memory_used (struct bcache *bcache)
+{
+  return obstack_memory_used (&bcache->cache);
+}
index 2b03ead..61fbbe6 100644 (file)
@@ -1,7 +1,8 @@
 /* Include file cached obstack implementation.
    Written by Fred Fish <fnf@cygnus.com>
    Rewritten by Jim Blandy <jimb@cygnus.com>
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+
+   Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
      any chance of sharing its space with future duplicates.  */
 
 
-/* The type used to hold a single bcache string.  The user data is
-   stored in d.data.  Since it can be any type, it needs to have the
-   same alignment as the most strict alignment of any type on the host
-   machine.  I don't know of any really correct way to do this in
-   stock ANSI C, so just do it the same way obstack.h does.
-
-   It would be nicer to have this stuff hidden away in bcache.c, but
-   struct objstack contains a struct bcache directly --- not a pointer
-   to one --- and then the memory-mapped stuff makes this a real pain.
-   We don't strictly need to expose struct bstring, but it's better to
-   have it all in one place.  */
-
-struct bstring {
-  struct bstring *next;
-  size_t length;
-
-  union
-  {
-    char data[1];
-    double dummy;
-  }
-  d;
-};
-
-
-/* The structure for a bcache itself.
-   To initialize a bcache, just fill it with zeros.  */
-struct bcache {
-  /* All the bstrings are allocated here.  */
-  struct obstack cache;
-
-  /* How many hash buckets we're using.  */
-  unsigned int num_buckets;
-  
-  /* Hash buckets.  This table is allocated using malloc, so when we
-     grow the table we can return the old table to the system.  */
-  struct bstring **bucket;
-
-  /* Statistics.  */
-  unsigned long unique_count;  /* number of unique strings */
-  long total_count;    /* total number of strings cached, including dups */
-  long unique_size;    /* size of unique strings, in bytes */
-  long total_size;      /* total number of bytes cached, including dups */
-  long structure_size; /* total size of bcache, including infrastructure */
-};
-
+struct bcache;
 
 /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
    never seen those bytes before, add a copy of them to BCACHE.  In
    either case, return a pointer to BCACHE's copy of that string.  */
 extern void *bcache (const void *addr, int length, struct bcache *bcache);
 
-/* Free all the storage that BCACHE refers to.  The result is a valid,
-   but empty, bcache.  This does not free BCACHE itself, since that
-   might be part of some larger object.  */
-extern void free_bcache (struct bcache *bcache);
+/* Free all the storage used by BCACHE.  */
+extern void bcache_xfree (struct bcache *bcache);
+
+/* Create a new bcache object.  */
+extern struct bcache *bcache_xmalloc (void);
 
 /* Print statistics on BCACHE's memory usage and efficacity at
    eliminating duplication.  TYPE should be a string describing the
    kind of data BCACHE holds.  Statistics are printed using
    `printf_filtered' and its ilk.  */
 extern void print_bcache_statistics (struct bcache *bcache, char *type);
+extern int bcache_memory_used (struct bcache *bcache);
+
 /* The hash function */
 extern unsigned long hash(const void *addr, int length);
+
 #endif /* BCACHE_H */
index 484561c..fde7d3b 100644 (file)
@@ -6476,7 +6476,7 @@ macro_start_file (int file, int line,
      at all until we actually get a filename.  */
   if (! pending_macros)
     pending_macros = new_macro_table (&objfile->symbol_obstack,
-                                      &objfile->macro_cache);
+                                      objfile->macro_cache);
 
   if (! current_file)
     /* If we have no current file, then this must be the start_file
index 32bda87..ba55bbb 100644 (file)
@@ -1,6 +1,8 @@
 /* GDB routines for manipulating objfiles.
-   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   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.
@@ -30,6 +32,7 @@
 #include "objfiles.h"
 #include "gdb-stabs.h"
 #include "target.h"
+#include "bcache.h"
 
 #include <sys/types.h>
 #include "gdb_stat.h"
@@ -269,10 +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);
-      obstack_specify_allocation (&objfile->macro_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,
@@ -483,8 +484,8 @@ free_objfile (struct objfile *objfile)
       if (objfile->static_psymbols.list)
        xmfree (objfile->md, objfile->static_psymbols.list);
       /* Free the obstacks for non-reusable objfiles */
-      free_bcache (&objfile->psymbol_cache);
-      free_bcache (&objfile->macro_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);
index b04abc1..8e2c81b 100644 (file)
@@ -1,6 +1,7 @@
 /* Definitions for symbol file management in GDB.
-   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -22,7 +23,7 @@
 #if !defined (OBJFILES_H)
 #define OBJFILES_H
 
-#include "bcache.h"
+struct bcache;
 
 /* This structure maintains information on a per-objfile basis about the
    "entry point" of the objfile, and the scope within which the entry point
@@ -278,8 +279,8 @@ struct objfile
     /* A byte cache where we can stash arbitrary "chunks" of bytes that
        will not change. */
 
-    struct bcache psymbol_cache;       /* Byte cache for partial syms */
-    struct bcache macro_cache;          /* Byte cache for macros */
+    struct bcache *psymbol_cache;      /* Byte cache for partial syms */
+    struct bcache *macro_cache;          /* Byte cache for macros */
 
     /* Vectors of all partial symbols read in from file.  The actual data
        is stored in the psymbol_obstack. */
index d087b1f..2a68201 100644 (file)
@@ -40,6 +40,7 @@
 #include "gdb-stabs.h"
 #include "obstack.h"
 #include "completer.h"
+#include "bcache.h"
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -1740,8 +1741,10 @@ reread_symbols (void)
                      sizeof (objfile->static_psymbols));
 
              /* Free the obstacks for non-reusable objfiles */
-             free_bcache (&objfile->psymbol_cache);
-             free_bcache (&objfile->macro_cache);
+             bcache_xfree (objfile->psymbol_cache);
+             objfile->psymbol_cache = bcache_xmalloc ();
+             bcache_xfree (objfile->macro_cache);
+             objfile->macro_cache = bcache_xmalloc ();
              obstack_free (&objfile->psymbol_obstack, 0);
              obstack_free (&objfile->symbol_obstack, 0);
              obstack_free (&objfile->type_obstack, 0);
@@ -1765,10 +1768,8 @@ reread_symbols (void)
              objfile->md = NULL;
              /* obstack_specify_allocation also initializes the obstack so
                 it is empty.  */
-             obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-                                         xmalloc, xfree);
-             obstack_specify_allocation (&objfile->macro_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,
@@ -2377,7 +2378,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace,
   /* Create local copy of the partial symbol */
   memcpy (buf, name, namelength);
   buf[namelength] = '\0';
-  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
   /* val and coreaddr are mutually exclusive, one of them *will* be zero */
   if (val != 0)
     {
@@ -2394,7 +2395,7 @@ add_psymbol_to_list (char *name, int namelength, namespace_enum namespace,
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
 
   /* Stash the partial symbol away in the cache */
-  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
 
   /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
@@ -2429,7 +2430,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
 
   memcpy (buf, name, namelength);
   buf[namelength] = '\0';
-  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
 
   buf = alloca (dem_namelength + 1);
   memcpy (buf, dem_name, dem_namelength);
@@ -2440,11 +2441,11 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
     case language_c:
     case language_cplus:
       SYMBOL_CPLUS_DEMANGLED_NAME (&psymbol) =
-       bcache (buf, dem_namelength + 1, &objfile->psymbol_cache);
+       bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
       break;
     case language_chill:
       SYMBOL_CHILL_DEMANGLED_NAME (&psymbol) =
-       bcache (buf, dem_namelength + 1, &objfile->psymbol_cache);
+       bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
 
       /* FIXME What should be done for the default case? Ignoring for now. */
     }
@@ -2465,7 +2466,7 @@ add_psymbol_with_dem_name_to_list (char *name, int namelength, char *dem_name,
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
 
   /* Stash the partial symbol away in the cache */
-  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
 
   /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
index 370b76e..55f6926 100644 (file)
@@ -1,6 +1,8 @@
 /* Do various things to symbol tables (other than lookup), for GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+   1995, 1996, 1997, 1998, 1999, 2000, 2002 Free Software Foundation,
+   Inc.
 
    This file is part of GDB.
 
@@ -167,7 +169,7 @@ print_symbol_bcache_statistics (void)
   ALL_OBJFILES (objfile)
   {
     printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
-    print_bcache_statistics (&objfile->psymbol_cache, "partial symbol cache");
+    print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
   }
   immediate_quit--;
 }
@@ -202,9 +204,9 @@ print_objfile_statistics (void)
     printf_filtered ("  Total memory used for psymbol obstack: %d\n",
                     obstack_memory_used (&objfile->psymbol_obstack));
     printf_filtered ("  Total memory used for psymbol cache: %d\n",
-                    obstack_memory_used (&objfile->psymbol_cache.cache));
+                    bcache_memory_used (objfile->psymbol_cache));
     printf_filtered ("  Total memory used for macro cache: %d\n",
-                    obstack_memory_used (&objfile->macro_cache.cache));
+                    bcache_memory_used (objfile->macro_cache));
     printf_filtered ("  Total memory used for symbol obstack: %d\n",
                     obstack_memory_used (&objfile->symbol_obstack));
     printf_filtered ("  Total memory used for type obstack: %d\n",