This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [patch/rfc[ Opaque bcache
On Wed, Jul 10, 2002 at 06:15:47PM -0400, Andrew Cagney wrote:
Hello,
This makes the bcache object opaque. Testing so far hasn't shown problems. I'll look to commit it in a few days.
comments? Hmm, did I remember to update the makefile ....
Nope to updating the Makefile, and nope to comments:
:-)
+/* 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. */
That's not accurate any more. Other than that, this looks great; and
it removes a lot of &'s we used to need when accessing a bcache, which
I quite like.
Hmm, yes, I should clean up the comments I simply cut/paste.
I've checked in the attached. The differences are very minor.
Andrew
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.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.218
diff -u -r1.218 Makefile.in
--- Makefile.in 3 Jul 2002 20:36:54 -0000 1.218
+++ Makefile.in 12 Jul 2002 15:12:33 -0000
@@ -641,7 +641,7 @@
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 @@
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 @@
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: bcache.c
===================================================================
RCS file: /cvs/src/src/gdb/bcache.c,v
retrieving revision 1.8
diff -u -r1.8 bcache.c
--- bcache.c 15 Apr 2002 05:23:01 -0000 1.8
+++ bcache.c 12 Jul 2002 15:12:33 -0000
@@ -29,6 +29,50 @@
#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 @@
}
-/* 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);
}
@@ -290,4 +341,10 @@
printf_filtered ("(not applicable)\n");
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: bcache.h
===================================================================
RCS file: /cvs/src/src/gdb/bcache.h,v
retrieving revision 1.5
diff -u -r1.5 bcache.h
--- bcache.h 23 Feb 2002 03:57:26 -0000 1.5
+++ bcache.h 12 Jul 2002 15:12:34 -0000
@@ -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.
@@ -63,68 +64,27 @@
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: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.60
diff -u -r1.60 dwarf2read.c
--- dwarf2read.c 22 Jun 2002 00:05:59 -0000 1.60
+++ dwarf2read.c 12 Jul 2002 15:12:37 -0000
@@ -6476,7 +6476,7 @@
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: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.20
diff -u -r1.20 objfiles.c
--- objfiles.c 15 May 2002 21:19:18 -0000 1.20
+++ objfiles.c 12 Jul 2002 15:12:38 -0000
@@ -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 @@
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 @@
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: objfiles.h
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.h,v
retrieving revision 1.12
diff -u -r1.12 objfiles.h
--- objfiles.h 28 Jun 2002 22:09:11 -0000 1.12
+++ objfiles.h 12 Jul 2002 15:12:39 -0000
@@ -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 @@
/* 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: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.62
diff -u -r1.62 symfile.c
--- symfile.c 15 May 2002 21:19:20 -0000 1.62
+++ symfile.c 12 Jul 2002 15:12:41 -0000
@@ -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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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: symmisc.c
===================================================================
RCS file: /cvs/src/src/gdb/symmisc.c,v
retrieving revision 1.10
diff -u -r1.10 symmisc.c
--- symmisc.c 11 Jul 2002 20:46:19 -0000 1.10
+++ symmisc.c 12 Jul 2002 15:12:41 -0000
@@ -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 @@
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 @@
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",