+2002-09-20 David Carlton <carlton@math.stanford.edu>
+
+ * jv-lang.c (get_java_class_symtab): Use xmalloc to allocate
+ GLOBAL_BLOCK rather than xmmalloc.
+ (free_class_block): Use xfree rather than xmfree.
+ * mdebugread.c: #include "dictionary.h"
+ (new_block): Remove argument. Initialize BLOCK_DICT.
+ (parse_symbol): Update call to new_block.
+ (new_symtab): Ditto.
+ (fixup_sigtramp): Ditto.
+ Delete MAXSYMS member of struct parse_stack.
+ (psymtab_to_symtab_1): Don't set maxsyms.
+ (new_symtab): Remove maxsyms argument.
+ (psymtab_to_symtab_1): Update call to new_symtab.
+ (shrink_block): Delete function.
+ (add_symbol): Add symbols via dict_add_symbol_block.
+ * jv-lang.c (add_class_symtab_symbol): Add symbols via
+ dict_add_symbol_block.
+ Delete variable class_symtab_space.
+ * Makefile.in (jv-lang.o): Add dictionary_h.
+ * jv-lang.c: #include "dictionary.h"
+ * symmisc.c (free_symtab): Call free_func rather than freeing free_ptr.
+ * jv-lang.c (get_java_class_symtab): Initialize free_func rather
+ than free_ptr.
+ (free_class_block): New function.
+ (add_class_symtab_symbol): Delete reference to free_ptr.
+ * buildsym.c (end_symtab): Initialize free_func rather than free_ptr.
+ * symtab.h (struct symtab): Replace free_ptr by free_func.
+ * jv-lang.c (get_java_class_symtab): Add DICT_BLOCK assignments.
+ * Makefile.in (buildsym.o): Add dictionary_h.
+ * buildsym.c (finish_block): Initialize BLOCK_DICT (block).
+ #include "dictionary.h"
+ * symtab.h (struct block): Add 'dict' member.
+ (BLOCK_DICT): New macro.
+ * dictionary.c: New file.
+ * dictionary.h: New file.
+ * Makefile.in (SFILES): Add dictionary.c
+ (dictionary_h): New variable.
+ (COMMON_OBS): Add dictionary.o.
+ (dictionary.o): New rule.
+ (carlton): New rule.
+
2002-09-18 David Carlton <carlton@math.stanford.edu>
* symtab.h: Delete BLOCK_SHOULD_SORT.
buildsym.c c-exp.y c-lang.c c-typeprint.c c-valprint.c \
coffread.c \
complaints.c completer.c corefile.c cp-valprint.c dbxread.c \
- demangle.c dwarfread.c dwarf2read.c elfread.c environ.c eval.c \
+ demangle.c dictionary.c dwarfread.c \
+ dwarf2read.c elfread.c environ.c eval.c \
event-loop.c event-top.c \
expprint.c f-exp.y f-lang.c f-typeprint.c f-valprint.c \
findvar.c regcache.c gdbarch.c arch-utils.c gdbtypes.c osabi.c \
defs_h = defs.h $(config_h) $(gdb_locale_h) $(gdb_signals_h) $(ansidecl_h) \
$(libiberty_h) $(progress_h) $(bfd_h) $(tui_h) $(ui_file_h) $(xm_h) \
$(nm_h) $(tm_h) $(fopen_same_h) $(gdbarch_h) $(arch_utils_h)
+dictionary_h = dictionary.h
doublest_h = doublest.h $(floatformat_h)
dst_h = dst.h
dwarf2cfi_h = dwarf2cfi.h
TAGFILES_WITH_SRCDIR = $(HFILES_WITH_SRCDIR)
COMMON_OBS = version.o blockframe.o breakpoint.o findvar.o regcache.o \
- charset.o \
+ charset.o dictionary.o \
source.o values.o eval.o valops.o valarith.o valprint.o printcmd.o \
symtab.o symfile.o symmisc.o linespec.o infcmd.o infrun.o \
expprint.o environ.o stack.o thread.o \
$(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)
+ $(stabsread_h) $(dictionary_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) \
delta68-nat.o: delta68-nat.c $(defs_h)
demangle.o: demangle.c $(defs_h) $(command_h) $(gdbcmd_h) $(demangle_h) \
$(gdb_string_h)
+dictionary.o: dictionary.c $(defs_h) $(dictionary_h) $(gdb_obstack_h) \
+ $(symtab_h) $(buildsym_h) $(gdb_assert_h)
dink32-rom.o: dink32-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \
$(serial_h) $(symfile_h) $(inferior_h) $(regcache_h)
doublest.o: doublest.c $(defs_h) $(doublest_h) $(floatformat_h) \
jv-lang.o: jv-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
$(parser_defs_h) $(language_h) $(gdbtypes_h) $(symtab_h) \
$(symfile_h) $(objfiles_h) $(gdb_string_h) $(value_h) $(c_lang_h) \
- $(jv_lang_h) $(gdbcore_h)
+ $(jv_lang_h) $(gdbcore_h) $(dictionary_h)
jv-typeprint.o: jv-typeprint.c $(defs_h) $(symtab_h) $(gdbtypes_h) \
$(value_h) $(demangle_h) $(jv_lang_h) $(gdb_string_h) $(typeprint_h) \
$(c_lang_h) $(cp_abi_h)
$(stabsread_h) $(complaints_h) $(demangle_h) $(gdb_assert_h) \
$(coff_sym_h) $(coff_symconst_h) $(gdb_stat_h) $(gdb_string_h) \
$(bfd_h) $(coff_ecoff_h) $(libaout_h) $(aout_aout64_h) \
- $(aout_stab_gnu_h) $(expression_h) $(language_h)
+ $(aout_stab_gnu_h) $(expression_h) $(language_h) $(dictionary_h)
mem-break.o: mem-break.c $(defs_h) $(symtab_h) $(breakpoint_h) $(inferior_h) \
$(target_h)
memattr.o: memattr.c $(defs_h) $(command_h) $(gdbcmd_h) $(memattr_h) \
vx-share/vxWorks.h vx-share/xdr_rdb.h
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/vx-share/xdr_rdb.c
+
+# Compiles and then runs a subset of the tests.
+carlton: all
+ cd testsuite; ./carlton_runtest
+
### end of the gdb Makefile.in.
#include "filenames.h" /* For DOSish file names */
#include "macrotab.h"
#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
+#include "dictionary.h"
/* Ask buildsym.h to define the vars it normally declares `extern'. */
#define EXTERN
/**/
BLOCK_END (block) = end;
/* Superblock filled in when containing block is made */
BLOCK_SUPERBLOCK (block) = NULL;
+ BLOCK_DICT (block) = dict_create_block (block);
BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
symtab->dirname = NULL;
}
symtab->free_code = free_linetable;
- symtab->free_ptr = NULL;
+ symtab->free_func = NULL;
/* Use whatever language we have been using for this
subfile, not the one that was deduced in allocate_symtab
--- /dev/null
+/* Routines for name->symbol lookups in GDB.
+
+ Copyright 2002 Free Software Foundation, Inc.
+
+ Contributed by David Carlton <carlton@bactrian.org>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "defs.h"
+#include "dictionary.h"
+#include "gdb_obstack.h"
+#include "symtab.h"
+#include "buildsym.h"
+#include "gdb_assert.h"
+
+/* This file implements dictionaries, which are tables that associate
+ symbols to names. They are represented by an opaque type 'struct
+ dictionary'. That type has various internal implementations, which
+ you can choose between depending on what properties you need
+ (e.g. fast lookup, order-preserving, expandable).
+
+ Each dictionary starts with a 'virtual function table' that
+ contains the functions that actually implement the various
+ operations that dictionaries provide. */
+
+/* NOTE: carlton/2002-09-20: Originally, I'd had each dictionary start
+ with a dict_type member, and had implemented the various functions
+ via big switch statements. But that led to some really large
+ functions, and might cause problems in the future (e.g. if I were
+ to provide two different allocators for a single type that either
+ allocate using obstacks or using xfree(), then we'd have to expand
+ the number of dict_types to get dict_free() to work), so I'm going
+ with dict_vtbl instead. I left the dict_type in the dict_vtbl,
+ but it's never used: it's just there to make debugging a bit
+ easier. */
+
+/* An enum representing the various implementations of dictionaries.
+ Used only for debugging. */
+
+enum dict_type
+ {
+ /* Symbols are stored in a (fixed-size) hash table. */
+ DICT_HASHED,
+ /* Symbols are stored in a (fixed-size) array. */
+ DICT_LINEAR,
+ /* Symbols are stored in an expandable array. */
+ DICT_LINEAR_EXPANDABLE,
+ /* Symbols are stored in a fixed-size block. */
+ DICT_BLOCK,
+ /* Symbols are stored in an expandable block. */
+ DICT_BLOCK_EXPANDABLE,
+ };
+
+/* The virtual function table. */
+
+struct dict_vtbl
+{
+ /* The type of the dictionary. This is only here to make debugging
+ a bit easier; it's not actually used. */
+ enum dict_type type;
+ /* The function to free a dictionary. */
+ void (*free)(struct dictionary *);
+};
+
+/* Now comes the structs used to store the data for different
+ implementations. If two implementations have data in common, put
+ the common data at the top of their structs, ordered in the same
+ way. */
+
+struct dictionary_block
+{
+ struct block *block;
+};
+
+struct dictionary_block_expandable
+{
+ struct block *block;
+ unsigned int maxsyms;
+};
+
+/* And now, the star of our show. */
+
+struct dictionary
+{
+ const struct dict_vtbl *vtbl;
+ union
+ {
+ struct dictionary_block block;
+ struct dictionary_block_expandable block_expandable;
+ }
+ data;
+};
+
+/* Accessor macros. */
+
+#define DICT_VTBL(d) (d)->vtbl
+
+/* This can be used for 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_INITIAL_MAXSYMS 10
+
+/* Declarations of functions for vtbls. */
+
+static void dict_free_block(struct dictionary *dict);
+
+/* Various vtbls that we'll actually use. */
+
+const struct dict_vtbl dict_block_vtbl =
+ {
+ DICT_BLOCK, dict_free_block,
+ };
+
+const struct dict_vtbl dict_block_expandable_vtbl =
+ {
+ DICT_BLOCK_EXPANDABLE, dict_free_block,
+ };
+
+/* The creation functions. */
+
+/* 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. */
+struct dictionary *
+dict_create_block (struct block *block)
+{
+ struct dictionary *retval = xmalloc (sizeof (struct dictionary));
+
+ DICT_VTBL (retval) = &dict_block_vtbl;
+ DICT_BLOCK_BLOCK (retval) = block;
+
+ return retval;
+}
+
+struct dictionary *
+dict_create_block_expandable (struct block *block)
+{
+ struct dictionary *retval = xmalloc (sizeof (struct dictionary));
+
+ 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;
+
+ return retval;
+}
+
+/* The functions providing the dictionary interface. */
+
+void
+dict_free (struct dictionary *dict)
+{
+ (DICT_VTBL (dict))->free (dict);
+}
+
+/* The functions implementing the dictionary interface. */
+
+/* First, for DICT_BLOCK and DICT_BLOCK_EXPANDABLE. */
+
+static void
+dict_free_block (struct dictionary *dict)
+{
+ xfree (dict);
+}
+
+/* A special-case function for DICT_BLOCK_EXPANDABLE. */
+
+/* FIXME: carlton/2002-09-20: But some callers use xmmalloc!!!
+ Crap. */
+
+struct block *
+dict_add_symbol_block (struct dictionary *dict, struct symbol *sym)
+{
+ gdb_assert ((DICT_VTBL (dict))->type == DICT_BLOCK_EXPANDABLE);
+
+ struct block *block = DICT_BLOCK_BLOCK (dict);
+
+ if (++BLOCK_NSYMS (block) > DICT_BLOCK_EXPANDABLE_MAXSYMS (dict))
+ {
+ if (DICT_BLOCK_EXPANDABLE_MAXSYMS (dict))
+ DICT_BLOCK_EXPANDABLE_MAXSYMS (dict) *= 2;
+ else
+ DICT_BLOCK_EXPANDABLE_MAXSYMS (dict)
+ = DICT_BLOCK_EXPANDABLE_INITIAL_MAXSYMS;
+
+ block = xrealloc (block,
+ sizeof (struct block)
+ + ((DICT_BLOCK_EXPANDABLE_MAXSYMS (dict) -1)
+ * sizeof (struct symbol)));
+ DICT_BLOCK_BLOCK (dict) = block;
+ }
+
+ BLOCK_SYM (block, BLOCK_NSYMS (block) - 1) = sym;
+
+ return block;
+}
--- /dev/null
+/* Routines for name->symbol lookups in GDB.
+
+ Copyright 2002 Free Software Foundation, Inc.
+
+ Contributed by David Carlton <carlton@bactrian.org>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* An opaque type for dictionaries; only dictionary.c should know
+ about its innards. */
+
+struct dictionary;
+
+/* Other types needed for declarations. */
+
+struct symbol;
+struct obstack;
+struct pending;
+struct block;
+
+
+/* The creation functions for various implementations of
+ dictionaries. */
+
+/* Create a DICT_BLOCK dictionary pointing at the given block. */
+
+extern struct dictionary *
+dict_create_block (struct block *block);
+
+/* Create a DICT_BLOCK_EXPANDABLE dictionary pointing at the given block. */
+extern struct dictionary *
+dict_create_block_expandable (struct block *block);
+
+
+/* The functions providing the interface to dictionaries. */
+
+/* Free the memory used by a dictionary that's not on an obstack. (If
+ any.) */
+extern void dict_free (struct dictionary *dict);
+
+/* Special case. */
+
+extern struct block *dict_add_symbol_block (struct dictionary *dict,
+ struct symbol *sym);
#include "c-lang.h"
#include "jv-lang.h"
#include "gdbcore.h"
+#include "dictionary.h"
#include <ctype.h>
struct type *java_int_type;
static struct symtab *class_symtab = NULL;
-/* Maximum number of class in class_symtab before relocation is needed. */
-
-static int class_symtab_space;
+static void free_class_block (struct symtab *symtab);
static struct symtab *
get_java_class_symtab (void)
BLOCK_END (bl) = 0;
BLOCK_FUNCTION (bl) = NULL;
BLOCK_SUPERBLOCK (bl) = NULL;
+ BLOCK_DICT (bl) = dict_create_block (bl);
BLOCK_GCC_COMPILED (bl) = 0;
BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
/* Allocate GLOBAL_BLOCK. This has to be relocatable. */
- class_symtab_space = 128;
- bl = xmmalloc (objfile->md,
- sizeof (struct block)
- + ((class_symtab_space - 1) * sizeof (struct symbol *)));
+ bl = xmalloc (sizeof (struct block));
*bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+ BLOCK_DICT (bl) = dict_create_block_expandable (bl);
BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
- class_symtab->free_ptr = (char *) bl;
+ class_symtab->free_func = free_class_block;
}
return class_symtab;
}
{
struct symtab *symtab = get_java_class_symtab ();
struct blockvector *bv = BLOCKVECTOR (symtab);
- struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
- if (BLOCK_NSYMS (bl) >= class_symtab_space)
- {
- /* Need to re-allocate. */
- class_symtab_space *= 2;
- bl = xmrealloc (symtab->objfile->md, bl,
- sizeof (struct block)
- + ((class_symtab_space - 1) * sizeof (struct symbol *)));
- class_symtab->free_ptr = (char *) bl;
- BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
- }
-
- BLOCK_SYM (bl, BLOCK_NSYMS (bl)) = sym;
- BLOCK_NSYMS (bl) = BLOCK_NSYMS (bl) + 1;
+ BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)
+ = dict_add_symbol_block (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv,
+ GLOBAL_BLOCK)),
+ sym);
}
static struct symbol *add_class_symbol (struct type *type, CORE_ADDR addr);
SYMBOL_VALUE_ADDRESS (sym) = addr;
return sym;
}
+
+/* Free the dynamic symbols block. */
+static void
+free_class_block (struct symtab *symtab)
+{
+ struct blockvector *bv = BLOCKVECTOR (symtab);
+ struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+
+ dict_free (BLOCK_DICT (bl));
+ xfree (bl);
+}
#endif
struct type *
#include "complaints.h"
#include "demangle.h"
#include "gdb_assert.h"
+#include "dictionary.h"
/* These are needed if the tm.h file does not contain the necessary
mips specific definitions. */
static struct type *new_type (char *);
-static struct block *new_block (int);
+static struct block *new_block (void);
-static struct symtab *new_symtab (char *, int, int, struct objfile *);
+static struct symtab *new_symtab (char *, int, struct objfile *);
static struct linetable *new_linetable (int);
static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
enum address_class);
-static struct block *shrink_block (struct block *, struct symtab *);
-
static void sort_blocks (struct symtab *);
static struct partial_symtab *new_psymtab (char *, struct objfile *);
int blocktype;
- int maxsyms; /* Max symbols in this block. */
struct type *cur_type; /* Type we parse fields for. */
int cur_field; /* Field number in cur_type. */
CORE_ADDR procadr; /* Start addres of this procedure */
SYMBOL_TYPE (s) = lookup_function_type (t);
/* Create and enter a new lexical context */
- b = new_block (top_stack->maxsyms);
+ b = new_block ();
SYMBOL_BLOCK_VALUE (s) = b;
BLOCK_FUNCTION (b) = s;
BLOCK_START (b) = BLOCK_END (b) = sh->value;
}
top_stack->blocktype = stBlock;
- b = new_block (top_stack->maxsyms);
+ b = new_block ();
BLOCK_START (b) = sh->value + top_stack->procadr;
BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
top_stack->cur_block = b;
/* Finished with procedure */
struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
struct mips_extra_func_info *e;
- struct block *b;
+ struct block *b = top_stack->cur_block;
struct type *ftype = top_stack->cur_type;
int i;
e->pdr.framereg = -1;
add_symbol (s, top_stack->cur_block);
- /* Reallocate symbols, saving memory */
- b = shrink_block (top_stack->cur_block, top_stack->cur_st);
-
/* f77 emits proc-level with address bounds==[0,0],
So look for such child blocks, and patch them. */
for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
displacement from the procedure`s start address of the
end of this block. */
BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
- shrink_block (top_stack->cur_block, top_stack->cur_st);
}
else if (sh->sc == scText && top_stack->blocktype == stNil)
{
SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int);
add_symbol (s, top_stack->cur_block);
/* Wont have symbols for this one */
- b = new_block (2);
+ b = new_block ();
SYMBOL_BLOCK_VALUE (s) = b;
BLOCK_FUNCTION (b) = s;
BLOCK_START (b) = pr->adr;
/* How many symbols will we need */
/* FIXME, this does not count enum values. */
- f_max = pst->n_global_syms + pst->n_static_syms;
if (fh == 0)
{
maxlines = 0;
- st = new_symtab ("unknown", f_max, 0, pst->objfile);
+ st = new_symtab ("unknown", 0, pst->objfile);
}
else
{
- f_max += fh->csym + fh->cpd;
maxlines = 2 * fh->cline;
- st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
+ st = new_symtab (pst->filename, maxlines, pst->objfile);
/* The proper language was already determined when building
the psymtab, use it. */
BLOCK_START (top_stack->cur_block) = pst->textlow;
BLOCK_END (top_stack->cur_block) = 0;
top_stack->blocktype = stFile;
- top_stack->maxsyms = 2 * f_max;
top_stack->cur_type = 0;
top_stack->procadr = 0;
top_stack->numargs = 0;
top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
GLOBAL_BLOCK);
top_stack->blocktype = stFile;
- top_stack->maxsyms
- = (debug_info->symbolic_header.isymMax
- + debug_info->symbolic_header.ipdMax
- + debug_info->symbolic_header.iextMax);
ext_ptr = PST_PRIVATE (pst)->extern_tab;
for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
}
-/* Add a new symbol S to a block B.
- Infrequently, we will need to reallocate the block to make it bigger.
- We only detect this case when adding to top_stack->cur_block, since
- that's the only time we know how big the block is. FIXME. */
+/* Add a new symbol S to a block B. */
static void
add_symbol (struct symbol *s, struct block *b)
{
int nsyms = BLOCK_NSYMS (b)++;
- struct block *origb;
+ struct block *newb;
struct parse_stack *stackp;
- if (b == top_stack->cur_block &&
- nsyms >= top_stack->maxsyms)
- {
- complain (&block_overflow_complaint, SYMBOL_NAME (s));
- /* In this case shrink_block is actually grow_block, since
- BLOCK_NSYMS(b) is larger than its current size. */
- origb = b;
- b = shrink_block (top_stack->cur_block, top_stack->cur_st);
+ 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. shrink_block has already done this
- for the blockvector and BLOCK_FUNCTION. */
+ original block. */
for (stackp = top_stack; stackp; stackp = stackp->next)
{
- if (stackp->cur_block == origb)
+ if (stackp->cur_block == b)
{
- stackp->cur_block = b;
- stackp->maxsyms = BLOCK_NSYMS (b);
+ stackp->cur_block = newb;
}
}
}
- BLOCK_SYM (b, nsyms) = s;
}
/* Add a new block B to a symtab S */
/* Constructor/restructor/destructor procedures */
/* Allocate a new symtab for NAME. Needs an estimate of how many symbols
- MAXSYMS and linenumbers MAXLINES we'll put in it */
+ and linenumbers MAXLINES we'll put in it */
static struct symtab *
-new_symtab (char *name, int maxsyms, int maxlines, struct objfile *objfile)
+new_symtab (char *name, int maxlines, struct objfile *objfile)
{
struct symtab *s = allocate_symtab (name, objfile);
+ struct block *global_block;
+ struct block *static_block;
LINETABLE (s) = new_linetable (maxlines);
/* All symtabs must have at least two blocks */
BLOCKVECTOR (s) = new_bvect (2);
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
- BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
- BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
+ global_block = new_block ();
+ static_block = new_block ();
+ BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = global_block;
+ BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = static_block;
+ BLOCK_SUPERBLOCK (static_block) = global_block;
s->free_code = free_linetable;
s->debugformat = obsavestring ("ECOFF", 5,
return bv;
}
-/* Allocate and zero a new block of MAXSYMS symbols */
-
-static struct block *
-new_block (int maxsyms)
-{
- int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
-
- return (struct block *) xzalloc (size);
-}
-
-/* Ooops, too big. Shrink block B in symtab S to its minimal size.
- Shrink_block can also be used by add_symbol to grow a block. */
+/* Allocate and zero a new block. Set its BLOCK_DICT. */
static struct block *
-shrink_block (struct block *b, struct symtab *s)
+new_block (void)
{
- struct block *new;
- struct blockvector *bv = BLOCKVECTOR (s);
- int i;
+ struct block *retval = xzalloc (sizeof (struct block));
+ BLOCK_DICT (retval) = dict_create_block_expandable (retval);
- /* Just reallocate it and fix references to the old one */
-
- new = (struct block *) xrealloc ((void *) b,
- (sizeof (struct block)
- + ((BLOCK_NSYMS (b) - 1)
- * sizeof (struct symbol *))));
-
- /* FIXME: Not worth hashing this block as it's built. */
- /* All callers should have created the block with new_block (), which
- would mean it was not previously hashed. Make sure. */
- gdb_assert (BLOCK_HASHTABLE (new) == 0);
-
- /* Should chase pointers to old one. Fortunately, that`s just
- the block`s function and inferior blocks */
- if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
- SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
- for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
- if (BLOCKVECTOR_BLOCK (bv, i) == b)
- BLOCKVECTOR_BLOCK (bv, i) = new;
- else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
- BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
- return new;
+ return retval;
}
/* Create a new symbol with printname NAME */
TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void;
/* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
- b = new_block (1);
+ b = new_block ();
SYMBOL_BLOCK_VALUE (s) = b;
BLOCK_START (b) = sigtramp_address;
BLOCK_END (b) = sigtramp_end;
symtab->blockvector
symtab->dirname
symtab->free_code
- symtab->free_ptr
+ symtab->free_func
possibly free_named_symtabs (symtab->filename);
*/
/* Also free the linetable. */
case free_linetable:
- /* Everything will be freed either by our `free_ptr'
+ /* Everything will be freed either by our `free_func'
or by some other symtab, except for our linetable.
Free that now. */
if (LINETABLE (s))
break;
}
- /* If there is a single block of memory to free, free it. */
- if (s->free_ptr != NULL)
- xmfree (s->objfile->md, s->free_ptr);
+ /* If there is other memory to free, free it. */
+ if (s->free_func != NULL)
+ s->free_func (s);
/* Free source-related stuff */
if (s->line_charpos != NULL)
/* Opaque declarations. */
struct obstack;
+struct dictionary;
/* Don't do this; it means that if some .o's are compiled with GNU C
and some are not (easy to do accidentally the way we configure
struct block *superblock;
+ /* This is used to store the symbols in the block. */
+
+ struct dictionary *dict;
+
/* Version of GCC used to compile the function corresponding
to this block, or 0 if not compiled with GCC. When possible,
GCC should be compatible with the native compiler, or if that
#define BLOCK_END(bl) (bl)->endaddr
#define BLOCK_FUNCTION(bl) (bl)->function
#define BLOCK_SUPERBLOCK(bl) (bl)->superblock
+#define BLOCK_DICT(bl) (bl)->dict
#define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag
#define BLOCK_HASHTABLE(bl) (bl)->hashtable
}
free_code;
- /* Pointer to one block of storage to be freed, if nonzero. */
- /* This is IN ADDITION to the action indicated by free_code. */
+ /* A function to call to free space, if necessary. This is IN
+ ADDITION to the action indicated by free_code. */
+
+ /* NOTE: carlton/2002-09-20: This is currently only used by
+ jv-lang.c. */
- char *free_ptr;
+ void (*free_func)(struct symtab *symtab);
/* Total number of lines found in source file. */