diff options
author | Andrew Cagney <cagney@redhat.com> | 2002-07-12 15:23:10 +0000 |
---|---|---|
committer | Andrew Cagney <cagney@redhat.com> | 2002-07-12 15:23:10 +0000 |
commit | e4e062773b4a9b62871e0ac9834c6c8b570d1977 (patch) | |
tree | 34459c4cda1b1cf122299b7c08b1c7c6dd3e9cba /gdb/bcache.c | |
parent | 2fa988ed7f6c346fd403046dc57617a4b1d5fc19 (diff) | |
download | gdb-e4e062773b4a9b62871e0ac9834c6c8b570d1977.tar.gz |
* 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.
Diffstat (limited to 'gdb/bcache.c')
-rw-r--r-- | gdb/bcache.c | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/gdb/bcache.c b/gdb/bcache.c index 73b86e8cf53..c5173e1bc8b 100644 --- a/gdb/bcache.c +++ b/gdb/bcache.c @@ -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 @@ bcache (const void *addr, int length, struct bcache *bcache) } -/* 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); +} |