diff options
author | David Carlton <carlton@bactrian.org> | 2002-09-25 00:19:27 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2002-09-25 00:19:27 +0000 |
commit | bab5aa3d9f7fc96bff7c7143ce4e05ae1b6c6e0c (patch) | |
tree | 1b0145678f792ea8ccd738c7df810ced12899a99 /gdb | |
parent | 8bf5bca147c9ce7c0e20d3de1593e9c91620f6d3 (diff) | |
download | gdb-bab5aa3d9f7fc96bff7c7143ce4e05ae1b6c6e0c.tar.gz |
2002-09-24 David Carlton <carlton@math.stanford.edu>
* dictionary.c: Comment out block-specific stuff.
* jv-lang.c (get_java_class_symtab): Allocate GLOBAL_BLOCK on
obstack.
(free_class_block): Don't free GLOBAL_BLOCK.
* dictionary.h: Comment out block-specific stuff.
* symtab.h: Comment out the members of struct block that
BLOCK_DICT obsoletes, and their accessors.
* Makefile.in (buildsym.o): Depend on gdb_assert_h.
* buildsym.c (finish_block): Don't count number of symbols.
(finish_block): Replace BLOCK_SYM reference with use of iterator.
#include "gdb_assert.h"
* symfile.c (free_named_symtabs): Fix calls to dict_empty
(which would seem to be #if'd out; oops...).
* buildsym.c (finish_block): Don't set BLOCK_HASHTABLE.
* jv-lang.c (get_java_class_symtab): Don't set BLOCK_HASHTABLE and
BLOCK_NSYMS.
* mdebugread.c (new_block): Allocate BLOCK_DICT via
dict_create_linear_expandable.
(add_symbol): Add symbol via dict_add_symbol; no need to chase
pointers.
(fixup_sigtramp): Add symbol via dict_add_symbol.
(new_symtab): Add FIXME comment on freeing blocks.
* jv-lang.c (get_java_class_symtab): Allocate GLOBAL_BLOCK's dict
using dict_create_linear_expandable.
(add_class_symtab_symbol): Add symbol using dict_add_symbol.
* dictionary.c (struct dictionary_linear_expandable): New struct.
(struct dictionary): Added member 'linear_expandable'.
(DICT_LINEAR_EXPANDABLE_MAXSYMS): New macro.
New variable dict_block_vtbl. Made all the _vtbl variables static.
Renamed all 'maxsyms' to 'capacity'.
(dict_create_linear_expandable): New function.
(add_symbol_linear_expandable): New function.
(free_linear_expandable): New function.
* jv-lang.c (get_java_class_symtab): Create static block's
dictionary with dict_create_linear.
* buildsym.c (finish_block): Create function blocks' dictionaries
with dict_create_linear.
* dictionary.c (lookup_linear): New function.
(iterator_first_linear): New function.
(iterator_next_linear): New function.
* dictionary.h: Moved comment.
* dictionary.c (struct dictionary_linear): New struct.
(struct dictionary): Added 'linear' member.
(DICT_LINEAR_NSYMS): New macro.
(DICT_LINEAR_SYMS): New macro.
(DICT_LINEAR_SYM): New macro.
New variable dict_linear_vtbl.
(dict_create_linear): New function.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 51 | ||||
-rw-r--r-- | gdb/Makefile.in | 2 | ||||
-rw-r--r-- | gdb/ada-lang.c | 2 | ||||
-rw-r--r-- | gdb/buildsym.c | 35 | ||||
-rw-r--r-- | gdb/dictionary.c | 316 | ||||
-rw-r--r-- | gdb/dictionary.h | 14 | ||||
-rw-r--r-- | gdb/jv-lang.c | 18 | ||||
-rw-r--r-- | gdb/mdebugread.c | 33 | ||||
-rw-r--r-- | gdb/symfile.c | 8 | ||||
-rw-r--r-- | gdb/symtab.h | 13 |
10 files changed, 399 insertions, 93 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c615c5cc3a3..bbe191b07c4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,54 @@ +2002-09-24 David Carlton <carlton@math.stanford.edu> + + * dictionary.c: Comment out block-specific stuff. + * jv-lang.c (get_java_class_symtab): Allocate GLOBAL_BLOCK on + obstack. + (free_class_block): Don't free GLOBAL_BLOCK. + * dictionary.h: Comment out block-specific stuff. + * symtab.h: Comment out the members of struct block that + BLOCK_DICT obsoletes, and their accessors. + * Makefile.in (buildsym.o): Depend on gdb_assert_h. + * buildsym.c (finish_block): Don't count number of symbols. + (finish_block): Replace BLOCK_SYM reference with use of iterator. + #include "gdb_assert.h" + * symfile.c (free_named_symtabs): Fix calls to dict_empty + (which would seem to be #if'd out; oops...). + * buildsym.c (finish_block): Don't set BLOCK_HASHTABLE. + * jv-lang.c (get_java_class_symtab): Don't set BLOCK_HASHTABLE and + BLOCK_NSYMS. + * mdebugread.c (new_block): Allocate BLOCK_DICT via + dict_create_linear_expandable. + (add_symbol): Add symbol via dict_add_symbol; no need to chase + pointers. + (fixup_sigtramp): Add symbol via dict_add_symbol. + (new_symtab): Add FIXME comment on freeing blocks. + * jv-lang.c (get_java_class_symtab): Allocate GLOBAL_BLOCK's dict + using dict_create_linear_expandable. + (add_class_symtab_symbol): Add symbol using dict_add_symbol. + * dictionary.c (struct dictionary_linear_expandable): New struct. + (struct dictionary): Added member 'linear_expandable'. + (DICT_LINEAR_EXPANDABLE_MAXSYMS): New macro. + New variable dict_block_vtbl. Made all the _vtbl variables static. + Renamed all 'maxsyms' to 'capacity'. + (dict_create_linear_expandable): New function. + (add_symbol_linear_expandable): New function. + (free_linear_expandable): New function. + * jv-lang.c (get_java_class_symtab): Create static block's + dictionary with dict_create_linear. + * buildsym.c (finish_block): Create function blocks' dictionaries + with dict_create_linear. + * dictionary.c (lookup_linear): New function. + (iterator_first_linear): New function. + (iterator_next_linear): New function. + * dictionary.h: Moved comment. + * dictionary.c (struct dictionary_linear): New struct. + (struct dictionary): Added 'linear' member. + (DICT_LINEAR_NSYMS): New macro. + (DICT_LINEAR_SYMS): New macro. + (DICT_LINEAR_SYM): New macro. + New variable dict_linear_vtbl. + (dict_create_linear): New function. + 2002-09-23 David Carlton <carlton@math.stanford.edu> * dictionary.c (struct dict_vtbl): 'add_symbol' field. diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 458f1487c5b..980d66f4774 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1557,7 +1557,7 @@ buildsym.o: buildsym.c $(defs_h) $(bfd_h) $(gdb_obstack_h) $(symtab_h) \ $(symfile_h) $(objfiles_h) $(gdbtypes_h) $(complaints_h) \ $(gdb_string_h) $(expression_h) $(language_h) $(bcache_h) \ $(filenames_h) $(macrotab_h) $(demangle_h) $(buildsym_h) \ - $(stabsread_h) $(dictionary_h) + $(stabsread_h) $(dictionary_h) $(gdb_assert_h) builtin-regs.o: builtin-regs.c $(defs_h) $(builtin_regs_h) $(gdbtypes_h) \ $(gdb_string_h) $(gdb_assert_h) c-lang.o: c-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index b38c5deb3ea..c2d491c246d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3948,7 +3948,7 @@ ada_add_block_symbols (struct block *block, const char *name, namespace_enum namespace, struct objfile *objfile, int wild) { - struct dict_iterator; + struct dict_iterator iter; int name_len = strlen (name); /* A matching argument symbol, if any. */ struct symbol *arg_sym; diff --git a/gdb/buildsym.c b/gdb/buildsym.c index ea934f5edc1..bbb1cc23956 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -42,6 +42,7 @@ #include "macrotab.h" #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */ #include "dictionary.h" +#include "gdb_assert.h" /* Ask buildsym.h to define the vars it normally declares `extern'. */ #define EXTERN /**/ @@ -233,33 +234,16 @@ finish_block (struct symbol *symbol, struct pending **listhead, register struct block *block; register struct pending_block *pblock; struct pending_block *opblock; - register int i; register int j; - /* Count the length of the list of symbols. */ - - for (next = *listhead, i = 0; - next; - i += next->nsyms, next = next->next) - { - /* EMPTY */ ; - } - - /* Copy the symbols into the block. */ + /* Initialize the block's dictionary. */ if (symbol) { block = (struct block *) - obstack_alloc (&objfile->symbol_obstack, - (sizeof (struct block) + - ((i - 1) * sizeof (struct symbol *)))); - BLOCK_NSYMS (block) = i; - for (next = *listhead; next; next = next->next) - for (j = next->nsyms - 1; j >= 0; j--) - { - BLOCK_SYM (block, --i) = next->symbol[j]; - } - BLOCK_DICT (block) = dict_create_block (block); + obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); + BLOCK_DICT (block) = dict_create_linear (&objfile->symbol_obstack, + *listhead); } else { @@ -283,7 +267,6 @@ finish_block (struct symbol *symbol, struct pending **listhead, struct type *ftype = SYMBOL_TYPE (symbol); SYMBOL_BLOCK_VALUE (symbol) = block; BLOCK_FUNCTION (block) = symbol; - BLOCK_HASHTABLE (block) = 0; struct dict_iterator iter; if (TYPE_NFIELDS (ftype) <= 0) @@ -328,9 +311,12 @@ finish_block (struct symbol *symbol, struct pending **listhead, TYPE_FIELDS (ftype) = (struct field *) TYPE_ALLOC (ftype, nparams * sizeof (struct field)); - for (i = iparams = 0; iparams < nparams; i++) + for (sym = dict_iterator_first (BLOCK_DICT (block), &iter), + iparams = 0; + iparams < nparams; + sym = dict_iterator_next (&iter)) { - sym = BLOCK_SYM (block, i); + gdb_assert (sym != NULL); switch (SYMBOL_CLASS (sym)) { case LOC_ARG: @@ -366,7 +352,6 @@ finish_block (struct symbol *symbol, struct pending **listhead, else { BLOCK_FUNCTION (block) = NULL; - BLOCK_HASHTABLE (block) = 1; } /* Now "free" the links of the list, and empty the list. */ diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 22a7643f9a9..b1c96f0bacd 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -60,10 +60,13 @@ enum dict_type DICT_LINEAR, /* Symbols are stored in an expandable array. */ DICT_LINEAR_EXPANDABLE, +#if 0 /* Symbols are stored in a fixed-size block. */ DICT_BLOCK, /* Symbols are stored in an expandable block. */ DICT_BLOCK_EXPANDABLE, + +#endif }; /* The virtual function table. */ @@ -98,6 +101,26 @@ struct dictionary_hashed struct symbol **buckets; }; +struct dictionary_linear +{ + int nsyms; + struct symbol **syms; +}; + +/* In this implementation, symbols are stored in an array that grows + as necessary. Note: the entries are ordered so that its initial + segment matches dictionary_linear. */ + +struct dictionary_linear_expandable +{ + /* How many symbols we currently have. */ + int nsyms; + struct symbol **syms; + /* How many symbols we can store before needing to reallocate. */ + int capacity; +}; + +#if 0 struct dictionary_block { struct block *block; @@ -106,8 +129,9 @@ struct dictionary_block struct dictionary_block_expandable { struct block *block; - unsigned int maxsyms; + unsigned int capacity; }; +#endif /* And now, the star of our show. */ @@ -117,8 +141,12 @@ struct dictionary union { struct dictionary_hashed hashed; + struct dictionary_linear linear; + struct dictionary_linear_expandable linear_expandable; +#if 0 struct dictionary_block block; struct dictionary_block_expandable block_expandable; +#endif } data; }; @@ -131,16 +159,32 @@ struct dictionary #define DICT_HASHED_BUCKETS(d) (d)->data.hashed.buckets #define DICT_HASHED_BUCKET(d,i) DICT_HASHED_BUCKETS (d) [i] -/* This can be used for block_expandables, too. */ +/* These can be used for DICT_LINEAR_EXPANDABLEs, too. */ + +#define DICT_LINEAR_NSYMS(d) (d)->data.linear.nsyms +#define DICT_LINEAR_SYMS(d) (d)->data.linear.syms +#define DICT_LINEAR_SYM(d,i) DICT_LINEAR_SYMS (d) [i] + +#define DICT_LINEAR_EXPANDABLE_CAPACITY(d) \ + (d)->data.linear_expandable.capacity + +#if 0 +/* This can be used for DICT_BLOCK_EXPANDABLES, too. */ #define DICT_BLOCK_BLOCK(d) (d)->data.block.block -#define DICT_BLOCK_EXPANDABLE_MAXSYMS(d) (d)->data.block_expandable.maxsyms +#define DICT_BLOCK_EXPANDABLE_CAPACITY(d) (d)->data.block_expandable.capacity -/* The initial size of a DICT_HASHED dictionary. */ +#endif +/* The initial size of a DICT_LINEAR_EXPANDABLE dictionary. */ + +#define DICT_LINEAR_EXPANDABLE_INITIAL_CAPACITY 10 -#define DICT_HASHED_INITIAL_MAXSYMS 10 -#define DICT_BLOCK_EXPANDABLE_INITIAL_MAXSYMS DICT_HASHED_INITIAL_MAXSYMS +#if 0 +#define DICT_BLOCK_EXPANDABLE_INITIAL_CAPACITY \ + DICT_LINEAR_EXPANDABLE_INITIAL_CAPACITY + +#endif /* This calculates the number of buckets we'll use in a hashtable, given the number of symbols that it will contain. */ @@ -165,8 +209,10 @@ struct dictionary static struct symbol *iterator_hashed_advance (struct dict_iterator *iter); +#if 0 static struct symbol *iterator_block_hashed_advance (struct dict_iterator *iter); +#endif /* Declarations of functions for vtbls. */ @@ -189,6 +235,27 @@ static struct symbol *iterator_first_hashed (const struct dictionary *dict, static struct symbol *iterator_next_hashed (struct dict_iterator *iterator); +/* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE + dictionaries. */ + +static struct symbol *lookup_linear (const struct dictionary *dict, + const char *name, + const char *mangled_name, + const namespace_enum namespace); + +static struct symbol *iterator_first_linear (const struct dictionary *dict, + struct dict_iterator *iterator); + +static struct symbol *iterator_next_linear (struct dict_iterator *iterator); + +/* Functions only for DICT_LINEAR_EXPANDABLE. */ + +static void free_linear_expandable (struct dictionary *dict); + +static void add_symbol_linear_expandable (struct dictionary *dict, + struct symbol *sym); + +#if 0 /* Functions for blocks. */ static struct symbol *lookup_block (const struct dictionary *dict, @@ -204,25 +271,42 @@ static struct symbol *iterator_first_block (const struct dictionary *dict, static struct symbol *iterator_next_block (struct dict_iterator *iterator); +#endif + /* Various vtbls that we'll actually use. */ -const struct dict_vtbl dict_hashed_vtbl = +static const struct dict_vtbl dict_hashed_vtbl = { DICT_HASHED, free_obstack, lookup_hashed, iterator_first_hashed, iterator_next_hashed, add_symbol_nonexpandable, }; -const struct dict_vtbl dict_block_vtbl = +static const struct dict_vtbl dict_linear_vtbl = + { + DICT_LINEAR, free_obstack, lookup_linear, iterator_first_linear, + iterator_next_linear, add_symbol_nonexpandable, + }; + +static const struct dict_vtbl dict_linear_expandable_vtbl = + { + DICT_LINEAR_EXPANDABLE, free_linear_expandable, lookup_linear, + iterator_first_linear, iterator_next_linear, + add_symbol_linear_expandable, + }; + +#if 0 +static const struct dict_vtbl dict_block_vtbl = { DICT_BLOCK, free_block, lookup_block, iterator_first_block, iterator_next_block, add_symbol_nonexpandable, }; -const struct dict_vtbl dict_block_expandable_vtbl = +static const struct dict_vtbl dict_block_expandable_vtbl = { DICT_BLOCK_EXPANDABLE, free_block, lookup_block, iterator_first_block, iterator_next_block, add_symbol_nonexpandable, }; +#endif /* The creation functions. */ @@ -276,7 +360,6 @@ dict_create_hashed (struct obstack *obstack, return retval; } -#if 0 /* Create a dictionary implemented via a fixed-size array. All memory it uses is allocated on OBSTACK; the environment is initialized from the SYMBOL_LIST. The symbols are ordered in the same order @@ -285,6 +368,42 @@ dict_create_hashed (struct obstack *obstack, struct dictionary * dict_create_linear (struct obstack *obstack, const struct pending *symbol_list) +{ + struct dictionary *retval; + int nsyms, i, j; + struct symbol **syms; + const struct pending *list_counter; + + retval = obstack_alloc (obstack, sizeof (struct dictionary)); + DICT_VTBL (retval) = &dict_linear_vtbl; + + /* Calculate the number of symbols, and allocate space for them. */ + for (nsyms = 0, list_counter = symbol_list; + list_counter != NULL; + nsyms += list_counter->nsyms, list_counter = list_counter->next) + { + /* EMPTY */ ; + } + DICT_LINEAR_NSYMS (retval) = nsyms; + syms = obstack_alloc (obstack, nsyms * sizeof (struct symbol *)); + DICT_LINEAR_SYMS (retval) = syms; + + /* Now fill in the symbols. Start filling in from the back, so as + to preserve the original order of the symbols. */ + for (list_counter = symbol_list, j = nsyms - 1; + list_counter != NULL; + list_counter = list_counter->next) + { + for (i = list_counter->nsyms - 1; + i >= 0; + --i, --j) + { + syms[j] = list_counter->symbol[i]; + } + } + + return retval; +} /* Create a dictionary implemented via an array that grows as necessary. The dictionary is initially empty; to add symbols to @@ -299,8 +418,22 @@ dict_create_linear (struct obstack *obstack, struct dictionary * dict_create_linear_expandable (void) -#endif +{ + struct dictionary *retval; + + retval = xmalloc (sizeof (struct dictionary)); + DICT_VTBL (retval) = &dict_linear_expandable_vtbl; + DICT_LINEAR_NSYMS (retval) = 0; + DICT_LINEAR_EXPANDABLE_CAPACITY (retval) + = DICT_LINEAR_EXPANDABLE_INITIAL_CAPACITY; + DICT_LINEAR_SYMS (retval) + = xmalloc (DICT_LINEAR_EXPANDABLE_CAPACITY (retval) + * sizeof (struct symbol *)); + return retval; +} + +#if 0 /* Allocate a dictionary in which symbol lookup is implemented via BLOCK. Needs to be freed by dict_free; I won't worry about that, however, since this will go away soon. */ @@ -324,11 +457,13 @@ dict_create_block_expandable (struct block *block) DICT_VTBL (retval) = &dict_block_expandable_vtbl; DICT_BLOCK_BLOCK (retval) = block; /* We'll resize the block the first time we add a symbol to it. */ - DICT_BLOCK_EXPANDABLE_MAXSYMS (retval) = 0; + DICT_BLOCK_EXPANDABLE_CAPACITY (retval) = 0; return retval; } +#endif + /* The functions providing the dictionary interface. */ /* Free the memory used by a dictionary that's not on an obstack. (If @@ -492,6 +627,150 @@ iterator_hashed_advance (struct dict_iterator *iterator) return NULL; } +/* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE. */ + +static struct symbol * +lookup_linear (const struct dictionary *dict, + const char *name, + const char *mangled_name, + const namespace_enum namespace) +{ + /* More or less copied from lookup_block_symbol() in symtab.c, + including the comments. */ + + int i, nsyms = DICT_LINEAR_NSYMS (dict); + struct symbol *sym, *sym_found = NULL; + + for (i = 0; i < nsyms; ++i) + { + sym = DICT_LINEAR_SYM (dict, i); + + /* NOTE: carlton/2002-09-24: I copied the following comment here + from the sorted linear symbol case of lookup_block_symbol. + But Jim Blandy complained, and said it didn't belong in the + non-sorted case. (Understandable, since it refers to + sorting!) I wish I understood exactly what its purpose + had been. */ + + /* If there is more than one symbol with the right name and + namespace, we return the first one; I believe it is now + impossible for us to encounter two symbols with the same name + and namespace here, because blocks containing argument + symbols are no longer sorted. The exception is for C++, + where multiple functions (cloned constructors / destructors, + in particular) can have the same demangled name. So if we + have a particular mangled name to match, try to do so. */ + if (SYMBOL_NAMESPACE (sym) == namespace + && (mangled_name + ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0 + : SYMBOL_MATCHES_NAME (sym, name))) + { + +#if 0 + /* FIXME: carlton/2002-09-11: According to + <http://sources.redhat.com/ml/gdb/2002-03/msg00232.html>, + the SYMBOL_ALIASES stuff is unused, and it makes the code + messier, so I'm #if'ing it out here. */ + + /* If SYM has aliases, then use any alias that is active at + the current PC. If no alias is active at the current PC, + then use the main symbol. + + ?!? Is checking the current pc correct? Is this routine + ever called to look up a symbol from another context? + + FIXME: No, it's not correct. If someone sets a + conditional breakpoint at an address, then the + breakpoint's `struct expression' should refer to the + `struct symbol' appropriate for the breakpoint's address, + which may not be the PC. + + Even if it were never called from another context, it's + totally bizarre for lookup_symbol's behavior to depend on + the value of the inferior's current PC. We should pass + in the appropriate PC as well as the block. The + interface to lookup_symbol should change to require the + caller to provide a PC. */ + + if (SYMBOL_ALIASES (sym)) + sym = find_active_alias (sym, read_pc ()); +#endif /* 0 */ + /* NOTE: carlton/2002-09-11: I wish I understood exactly the + situations where this next bit is important. Sigh. */ + + /* Note that parameter symbols do not always show up last in + the list; this loop makes sure to take anything else + other than parameter symbols first; it only uses + parameter symbols as a last resort. Note that this only + takes up extra computation time on a match. */ + + sym_found = sym; + if (SYMBOL_CLASS (sym) != LOC_ARG && + SYMBOL_CLASS (sym) != LOC_LOCAL_ARG && + SYMBOL_CLASS (sym) != LOC_REF_ARG && + SYMBOL_CLASS (sym) != LOC_REGPARM && + SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR && + SYMBOL_CLASS (sym) != LOC_BASEREG_ARG) + { + break; + } + } + } + + return (sym_found); /* Will be NULL if not found. */ +} + +static struct symbol * +iterator_first_linear (const struct dictionary *dict, + struct dict_iterator *iterator) +{ + DICT_ITERATOR_DICT (iterator) = dict; + DICT_ITERATOR_INDEX (iterator) = 0; + return DICT_LINEAR_NSYMS (dict) ? DICT_LINEAR_SYM (dict, 0) : NULL; +} + +static struct symbol * +iterator_next_linear (struct dict_iterator *iterator) +{ + const struct dictionary *dict = DICT_ITERATOR_DICT (iterator); + + if (++DICT_ITERATOR_INDEX (iterator) >= DICT_LINEAR_NSYMS (dict)) + return NULL; + else + return DICT_LINEAR_SYM (dict, DICT_ITERATOR_INDEX (iterator)); +} + +/* Functions only for DICT_LINEAR_EXPANDABLE. */ + +static void +free_linear_expandable (struct dictionary *dict) +{ + xfree (DICT_LINEAR_SYMS (dict)); + xfree (dict); +} + + +static void +add_symbol_linear_expandable (struct dictionary *dict, + struct symbol *sym) +{ + int nsyms = ++DICT_LINEAR_NSYMS (dict); + + /* Do we have enough room? If not, grow it. */ + if (nsyms > DICT_LINEAR_EXPANDABLE_CAPACITY (dict)) { + DICT_LINEAR_EXPANDABLE_CAPACITY (dict) *= 2; + DICT_LINEAR_SYMS (dict) + = xrealloc (DICT_LINEAR_SYMS (dict), + DICT_LINEAR_EXPANDABLE_CAPACITY (dict) + * sizeof (struct symbol *)); + } + + DICT_LINEAR_SYM (dict, nsyms - 1) = sym; +} + + +#if 0 + /* Functions for DICT_BLOCK and DICT_BLOCK_EXPANDABLE. */ static void @@ -685,17 +964,17 @@ dict_add_symbol_block (struct dictionary *dict, struct symbol *sym) struct block *block = DICT_BLOCK_BLOCK (dict); - if (++BLOCK_NSYMS (block) > DICT_BLOCK_EXPANDABLE_MAXSYMS (dict)) + if (++BLOCK_NSYMS (block) > DICT_BLOCK_EXPANDABLE_CAPACITY (dict)) { - if (DICT_BLOCK_EXPANDABLE_MAXSYMS (dict)) - DICT_BLOCK_EXPANDABLE_MAXSYMS (dict) *= 2; + if (DICT_BLOCK_EXPANDABLE_CAPACITY (dict)) + DICT_BLOCK_EXPANDABLE_CAPACITY (dict) *= 2; else - DICT_BLOCK_EXPANDABLE_MAXSYMS (dict) - = DICT_BLOCK_EXPANDABLE_INITIAL_MAXSYMS; + DICT_BLOCK_EXPANDABLE_CAPACITY (dict) + = DICT_BLOCK_EXPANDABLE_INITIAL_CAPACITY; block = xrealloc (block, sizeof (struct block) - + ((DICT_BLOCK_EXPANDABLE_MAXSYMS (dict) -1) + + ((DICT_BLOCK_EXPANDABLE_CAPACITY (dict) -1) * sizeof (struct symbol))); DICT_BLOCK_BLOCK (dict) = block; } @@ -704,3 +983,4 @@ dict_add_symbol_block (struct dictionary *dict, struct symbol *sym) return block; } +#endif diff --git a/gdb/dictionary.h b/gdb/dictionary.h index 082e528bc15..c944c2f187c 100644 --- a/gdb/dictionary.h +++ b/gdb/dictionary.h @@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* FIXME: carlton/2002-09-24: because of namespace_enum, you have to + include symtab.h before including this file. But I'm leaving in + opaque declarations as if that weren't true. */ + /* An opaque type for dictionaries; only dictionary.c should know about its innards. */ @@ -67,6 +71,8 @@ extern struct dictionary *dict_create_linear (struct obstack *obstack, extern struct dictionary *dict_create_linear_expandable (void); +#if 0 + /* Create a DICT_BLOCK dictionary pointing BLOCK. */ extern struct dictionary * @@ -77,6 +83,8 @@ dict_create_block (struct block *block); extern struct dictionary * dict_create_block_expandable (struct block *block); +#endif + /* The functions providing the interface to dictionaries. */ @@ -86,9 +94,6 @@ dict_create_block_expandable (struct block *block); particular mangled name. */ -/* FIXME: carlton/2002-09-23: namespace_enum is a typedef in - symtab.h... */ - extern struct symbol *dict_lookup (const struct dictionary *dict, const char *name, const char *mangled_name, @@ -107,11 +112,14 @@ extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym); extern int dict_empty (struct dictionary *dict); +#if 0 + /* Special case. */ extern struct block *dict_add_symbol_block (struct dictionary *dict, struct symbol *sym); +#endif /* A type containing data that is used when iterating over all symbols in a dictionary. */ diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c index d352ec85e58..2035f1a60e2 100644 --- a/gdb/jv-lang.c +++ b/gdb/jv-lang.c @@ -110,20 +110,20 @@ get_java_class_symtab (void) /* Allocate dummy STATIC_BLOCK. */ bl = (struct block *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); - BLOCK_NSYMS (bl) = 0; - BLOCK_HASHTABLE (bl) = 0; BLOCK_START (bl) = 0; BLOCK_END (bl) = 0; BLOCK_FUNCTION (bl) = NULL; BLOCK_SUPERBLOCK (bl) = NULL; - BLOCK_DICT (bl) = dict_create_block (bl); + BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack, + NULL); BLOCK_GCC_COMPILED (bl) = 0; BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl; - /* Allocate GLOBAL_BLOCK. This has to be relocatable. */ - bl = xmalloc (sizeof (struct block)); + /* Allocate GLOBAL_BLOCK. */ + bl = (struct block *) + obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); - BLOCK_DICT (bl) = dict_create_block_expandable (bl); + BLOCK_DICT (bl) = dict_create_linear_expandable (); BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; class_symtab->free_func = free_class_block; } @@ -135,10 +135,7 @@ add_class_symtab_symbol (struct symbol *sym) { struct symtab *symtab = get_java_class_symtab (); struct blockvector *bv = BLOCKVECTOR (symtab); - BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) - = dict_add_symbol_block (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, - GLOBAL_BLOCK)), - sym); + dict_add_symbol (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)), sym); } static struct symbol *add_class_symbol (struct type *type, CORE_ADDR addr); @@ -168,7 +165,6 @@ free_class_block (struct symtab *symtab) struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); dict_free (BLOCK_DICT (bl)); - xfree (bl); } #endif diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 8f440f49d7e..d817e93e3ac 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -4421,32 +4421,7 @@ add_symbol (struct symbol *s, struct block *b) struct block *newb; struct parse_stack *stackp; - newb = dict_add_symbol_block (BLOCK_DICT (b), s); - - /* Update all the pointers to b that we can find. */ - if (newb != b) - { - int i; - struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); - - if (BLOCK_FUNCTION (newb) - && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (newb)) == b) - SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (newb)) = newb; - for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++) - if (BLOCKVECTOR_BLOCK (bv, i) == b) - BLOCKVECTOR_BLOCK (bv, i) = newb; - else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b) - BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = newb; - /* Now run through the stack replacing pointers to the - original block. */ - for (stackp = top_stack; stackp; stackp = stackp->next) - { - if (stackp->cur_block == b) - { - stackp->cur_block = newb; - } - } - } + dict_add_symbol (BLOCK_DICT (b), s); } /* Add a new block B to a symtab S */ @@ -4588,6 +4563,8 @@ new_symtab (char *name, int maxlines, struct objfile *objfile) BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = static_block; BLOCK_SUPERBLOCK (static_block) = global_block; + /* FIXME: carlton/2002-09-24: But how do the blocks get freed? + Oy. */ s->free_code = free_linetable; s->debugformat = obsavestring ("ECOFF", 5, &objfile->symbol_obstack); @@ -4674,7 +4651,7 @@ static struct block * new_block (void) { struct block *retval = xzalloc (sizeof (struct block)); - BLOCK_DICT (retval) = dict_create_block_expandable (retval); + BLOCK_DICT (retval) = dict_create_linear_expandable (); return retval; } @@ -4845,7 +4822,7 @@ fixup_sigtramp (void) current_objfile = NULL; } - b = dict_add_symbol_block (BLOCK_DICT (b), s); + dict_add_symbol (BLOCK_DICT (b), s); add_block (b, st); sort_blocks (st); } diff --git a/gdb/symfile.c b/gdb/symfile.c index b03f0b0b9aa..3387b770328 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2255,10 +2255,10 @@ again2: bv = BLOCKVECTOR (s); if (BLOCKVECTOR_NBLOCKS (bv) > 2 - || ! dict_empty (BLOCK_DICT (BLOCK_NSYMS (BLOCKVECTOR_BLOCK - (bv, GLOBAL_BLOCK)))) - || ! dict_empty (BLOCK_DICT (BLOCK_NSYMS (BLOCKVECTOR_BLOCK - (bv, STATIC_BLOCK))))) + || ! dict_empty (BLOCK_DICT (BLOCKVECTOR_BLOCK + (bv, GLOBAL_BLOCK))) + || ! dict_empty (BLOCK_DICT (BLOCKVECTOR_BLOCK + (bv, STATIC_BLOCK)))) { complaint (&symfile_complaints, "Replacing old symbols for `%s'", name); diff --git a/gdb/symtab.h b/gdb/symtab.h index d09d5ff8b5a..b9f4879c4b5 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -405,6 +405,10 @@ struct block The table is laid out in NSYMS/5 buckets and symbols are chained via their hash_next field. */ +#if 0 + /* NOTE: carlton/2002-09-24: The rest of the members have been + obsoleted by DICT. */ + /* If this is really a hashtable of the symbols, this flag is 1. */ unsigned char hashtable; @@ -417,6 +421,7 @@ struct block in the order in which we would like to print them. */ struct symbol *sym[1]; +#endif /* 0 */ }; #define BLOCK_START(bl) (bl)->startaddr @@ -425,6 +430,11 @@ struct block #define BLOCK_SUPERBLOCK(bl) (bl)->superblock #define BLOCK_DICT(bl) (bl)->dict #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag + +#if 0 + +/* NOTE: carlton/2002-09-24: These have been obsoleted by dictionary + stuff. */ #define BLOCK_HASHTABLE(bl) (bl)->hashtable /* For blocks without a hashtable (BLOCK_HASHTABLE (bl) == 0) only. */ @@ -439,7 +449,6 @@ struct block /* Macro used to set the size of a hashtable for N symbols. */ #define BLOCK_HASHTABLE_SIZE(n) ((n)/5 + 1) -#if 0 /* Macro to loop through all symbols in a block BL, in no particular order. i counts which bucket we are in, and sym points to the current symbol. */ @@ -447,7 +456,7 @@ struct block for ((i) = 0; (i) < BLOCK_BUCKETS ((bl)); (i)++) \ for ((sym) = BLOCK_BUCKET ((bl), (i)); (sym); \ (sym) = (sym)->hash_next) -#endif +#endif /* 0 */ |