diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 060395e864..f62a45fb80 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,37 @@ +2012-05-10 Tom Tromey + + * tracepoint.c (scope_info): Update. + * symtab.c (lookup_block_symbol, iterate_over_symbols) + (find_pc_sect_symtab, search_symbols) + (default_make_symbol_completion_list_break_on) + (make_file_symbol_completion_list): Update. + * symmisc.c (dump_symtab_1): Update. + * stack.c (print_frame_args, iterate_over_block_locals) + (print_frame_labels, iterate_over_block_arg_vars): Update. + * python/py-block.c (block_object) : Remove. + : New field. + : Change type. + (blpy_iter): Update. + (blpy_block_syms_iternext): Update. + * psymtab.c (map_block): Use block iterators. + * objfiles.c (objfile_relocate1): Use ALL_DICT_SYMBOLS. + * mi/mi-cmd-stack.c (list_args_or_locals): Update. + * mdebugread.c (parse_symbol, mylookup_symbol): Update. + * infrun.c (check_exception_resume): Update. + * cp-support.c (make_symbol_overload_list_block): Update. + * coffread.c (patch_opaque_types): Update. + * buildsym.c (finish_block, end_symtab): Use ALL_DICT_SYMBOLS. + * block.h (struct block_iterator): New. + (block_iterator_first, block_iterator_next, block_iter_name_first) + (block_iter_name_next, block_iter_match_first) + (block_iter_match_next): Declare. + (ALL_BLOCK_SYMBOLS): Redefine. + * block.c (block_iterator_first, block_iterator_next) + (block_iter_name_first, block_iter_name_next) + (block_iter_match_first, block_iter_match_next): New functions. + * ada-lang.c (ada_add_block_symbols) + (ada_make_symbol_completion_list): Use block iterator. + 2012-05-10 Tom Tromey * psymtab.c (PSYMTAB_TO_SYMTAB): Remove. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 180fadb774..ad17cb41c0 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5515,7 +5515,7 @@ ada_add_block_symbols (struct obstack *obstackp, domain_enum domain, struct objfile *objfile, int wild) { - struct dict_iterator iter; + struct block_iterator iter; int name_len = strlen (name); /* A matching argument symbol, if any. */ struct symbol *arg_sym; @@ -5527,9 +5527,8 @@ ada_add_block_symbols (struct obstack *obstackp, found_sym = 0; if (wild) { - for (sym = dict_iter_match_first (BLOCK_DICT (block), name, - wild_match, &iter); - sym != NULL; sym = dict_iter_match_next (name, wild_match, &iter)) + for (sym = block_iter_match_first (block, name, wild_match, &iter); + sym != NULL; sym = block_iter_match_next (name, wild_match, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain) @@ -5551,9 +5550,8 @@ ada_add_block_symbols (struct obstack *obstackp, } else { - for (sym = dict_iter_match_first (BLOCK_DICT (block), name, - full_match, &iter); - sym != NULL; sym = dict_iter_match_next (name, full_match, &iter)) + for (sym = block_iter_match_first (block, name, full_match, &iter); + sym != NULL; sym = block_iter_match_next (name, full_match, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) @@ -5816,7 +5814,7 @@ ada_make_symbol_completion_list (char *text0, char *word) struct objfile *objfile; struct block *b, *surrounding_static_block = 0; int i; - struct dict_iterator iter; + struct block_iterator iter; if (text0[0] == '<') { diff --git a/gdb/block.c b/gdb/block.c index 57ab4c2024..3318cb4377 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -369,3 +369,62 @@ allocate_block (struct obstack *obstack) return bl; } + + + +/* See block.h. */ + +struct symbol * +block_iterator_first (const struct block *block, + struct block_iterator *iterator) +{ + return dict_iterator_first (block->dict, &iterator->dict_iter); +} + +/* See block.h. */ + +struct symbol * +block_iterator_next (struct block_iterator *iterator) +{ + return dict_iterator_next (&iterator->dict_iter); +} + +/* See block.h. */ + +struct symbol * +block_iter_name_first (const struct block *block, + const char *name, + struct block_iterator *iterator) +{ + return dict_iter_name_first (block->dict, name, &iterator->dict_iter); +} + +/* See block.h. */ + +struct symbol * +block_iter_name_next (const char *name, struct block_iterator *iterator) +{ + return dict_iter_name_next (name, &iterator->dict_iter); +} + +/* See block.h. */ + +struct symbol * +block_iter_match_first (const struct block *block, + const char *name, + symbol_compare_ftype *compare, + struct block_iterator *iterator) +{ + return dict_iter_match_first (block->dict, name, compare, + &iterator->dict_iter); +} + +/* See block.h. */ + +struct symbol * +block_iter_match_next (const char *name, + symbol_compare_ftype *compare, + struct block_iterator *iterator) +{ + return dict_iter_match_next (name, compare, &iterator->dict_iter); +} diff --git a/gdb/block.h b/gdb/block.h index 2cbcc1b847..2eec346b39 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -20,6 +20,8 @@ #ifndef BLOCK_H #define BLOCK_H +#include "dictionary.h" + /* Opaque declarations. */ struct symbol; @@ -27,7 +29,6 @@ struct symtab; struct block_namespace_info; struct using_direct; struct obstack; -struct dictionary; struct addrmap; /* All of the name-scope contours of the program @@ -105,13 +106,6 @@ struct block #define BLOCK_DICT(bl) (bl)->dict #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace -/* Macro to loop through all symbols in a block BL, in no particular - order. ITER helps keep track of the iteration, and should be a - struct dict_iterator. SYM points to the current symbol. */ - -#define ALL_BLOCK_SYMBOLS(block, iter, sym) \ - ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) - struct blockvector { /* Number of blocks in the list. */ @@ -167,4 +161,80 @@ extern const struct block *block_global_block (const struct block *block); extern struct block *allocate_block (struct obstack *obstack); + +/* A block iterator. This structure should be treated as though it + were opaque; it is only defined here because we want to support + stack allocation of iterators. */ + +struct block_iterator +{ + /* The underlying dictionary iterator. */ + + struct dict_iterator dict_iter; +}; + +/* Initialize ITERATOR to point at the first symbol in BLOCK, and + return that first symbol, or NULL if BLOCK is empty. */ + +extern struct symbol *block_iterator_first (const struct block *block, + struct block_iterator *iterator); + +/* Advance ITERATOR, and return the next symbol, or NULL if there are + no more symbols. Don't call this if you've previously received + NULL from block_iterator_first or block_iterator_next on this + iteration. */ + +extern struct symbol *block_iterator_next (struct block_iterator *iterator); + +/* Initialize ITERATOR to point at the first symbol in BLOCK whose + SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return + that first symbol, or NULL if there are no such symbols. */ + +extern struct symbol *block_iter_name_first (const struct block *block, + const char *name, + struct block_iterator *iterator); + +/* Advance ITERATOR to point at the next symbol in BLOCK whose + SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if + there are no more such symbols. Don't call this if you've + previously received NULL from block_iterator_first or + block_iterator_next on this iteration. And don't call it unless + ITERATOR was created by a previous call to block_iter_name_first + with the same NAME. */ + +extern struct symbol *block_iter_name_next (const char *name, + struct block_iterator *iterator); + +/* Initialize ITERATOR to point at the first symbol in BLOCK whose + SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use + the same conventions as strcmp_iw and be compatible with any + block hashing function), and return that first symbol, or NULL + if there are no such symbols. */ + +extern struct symbol *block_iter_match_first (const struct block *block, + const char *name, + symbol_compare_ftype *compare, + struct block_iterator *iterator); + +/* Advance ITERATOR to point at the next symbol in BLOCK whose + SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see + block_iter_match_first), or NULL if there are no more such symbols. + Don't call this if you've previously received NULL from + block_iterator_match_first or block_iterator_match_next on this + iteration. And don't call it unless ITERATOR was created by a + previous call to block_iter_match_first with the same NAME and COMPARE. */ + +extern struct symbol *block_iter_match_next (const char *name, + symbol_compare_ftype *compare, + struct block_iterator *iterator); + +/* Macro to loop through all symbols in a block BL, in no particular + order. ITER helps keep track of the iteration, and should be a + struct block_iterator. SYM points to the current symbol. */ + +#define ALL_BLOCK_SYMBOLS(block, iter, sym) \ + for ((sym) = block_iterator_first ((block), &(iter)); \ + (sym); \ + (sym) = block_iterator_next (&(iter))) + #endif /* BLOCK_H */ diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 36b1395f3b..58c2693e11 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -261,7 +261,10 @@ finish_block (struct symbol *symbol, struct pending **listhead, parameter symbols. */ int nparams = 0, iparams; struct symbol *sym; - ALL_BLOCK_SYMBOLS (block, iter, sym) + + /* Here we want to directly access the dictionary, because + we haven't fully initialized the block yet. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) { if (SYMBOL_IS_ARGUMENT (sym)) nparams++; @@ -273,7 +276,9 @@ finish_block (struct symbol *symbol, struct pending **listhead, TYPE_ALLOC (ftype, nparams * sizeof (struct field)); iparams = 0; - ALL_BLOCK_SYMBOLS (block, iter, sym) + /* Here we want to directly access the dictionary, because + we haven't fully initialized the block yet. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) { if (iparams == nparams) break; @@ -1173,9 +1178,9 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section) if (SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) == NULL) SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) = symtab; - for (sym = dict_iterator_first (BLOCK_DICT (block), &iter); - sym != NULL; - sym = dict_iterator_next (&iter)) + /* Note that we only want to fix up symbols from the local + blocks, not blocks coming from included symtabs. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) if (SYMBOL_SYMTAB (sym) == NULL) SYMBOL_SYMTAB (sym) = symtab; } diff --git a/gdb/coffread.c b/gdb/coffread.c index 2a8ee424fe..ec6f7d72d6 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1471,7 +1471,7 @@ static void patch_opaque_types (struct symtab *s) { struct block *b; - struct dict_iterator iter; + struct block_iterator iter; struct symbol *real_sym; /* Go through the per-file symbols only. */ diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 025b4de31f..8419a19854 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1140,14 +1140,12 @@ static void make_symbol_overload_list_block (const char *name, const struct block *block) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; - const struct dictionary *dict = BLOCK_DICT (block); - - for (sym = dict_iter_name_first (dict, name, &iter); + for (sym = block_iter_name_first (block, name, &iter); sym != NULL; - sym = dict_iter_name_next (name, &iter)) + sym = block_iter_name_next (name, &iter)) overload_list_add_symbol (sym, name); } diff --git a/gdb/infrun.c b/gdb/infrun.c index c3074d5cd9..81b6f5cb4a 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5620,7 +5620,7 @@ check_exception_resume (struct execution_control_state *ecs, TRY_CATCH (e, RETURN_MASK_ERROR) { struct block *b; - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; int argno = 0; diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index a20f9533ba..d1b9177908 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1184,7 +1184,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, if (nparams > 0) { - struct dict_iterator iter; + struct block_iterator iter; TYPE_NFIELDS (ftype) = nparams; TYPE_FIELDS (ftype) = (struct field *) @@ -4607,7 +4607,7 @@ static struct symbol * mylookup_symbol (char *name, struct block *block, domain_enum domain, enum address_class class) { - struct dict_iterator iter; + struct block_iterator iter; int inc; struct symbol *sym; diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index f537dd6cd2..fe3e0bf2bc 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -328,7 +328,7 @@ list_args_or_locals (enum what_to_list what, enum print_values values, { struct block *block; struct symbol *sym; - struct dict_iterator iter; + struct block_iterator iter; struct cleanup *cleanup_list; struct type *type; char *name_of_result; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 1f4913a982..8d9f8a5484 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -730,7 +730,9 @@ objfile_relocate1 (struct objfile *objfile, BLOCK_START (b) += ANOFFSET (delta, s->block_line_section); BLOCK_END (b) += ANOFFSET (delta, s->block_line_section); - ALL_BLOCK_SYMBOLS (b, iter, sym) + /* We only want to iterate over the local symbols, not any + symbols in included symtabs. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym) { relocate_one_symbol (sym, objfile, delta); } diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 5fb8ad4887..9620de8bd3 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1182,11 +1182,11 @@ map_block (const char *name, domain_enum namespace, struct objfile *objfile, int (*callback) (struct block *, struct symbol *, void *), void *data, symbol_compare_ftype *match) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; - for (sym = dict_iter_match_first (BLOCK_DICT (block), name, match, &iter); - sym != NULL; sym = dict_iter_match_next (name, match, &iter)) + for (sym = block_iter_match_first (block, name, match, &iter); + sym != NULL; sym = block_iter_match_next (name, match, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), namespace)) diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index ac48193121..68d0a1595c 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -41,10 +41,10 @@ typedef struct blpy_block_object { typedef struct { PyObject_HEAD - /* The block dictionary of symbols. */ - struct dictionary *dict; - /* The iterator for that dictionary. */ - struct dict_iterator iter; + /* The block. */ + const struct block *block; + /* The iterator for that block. */ + struct block_iterator iter; /* Has the iterator been initialized flag. */ int initialized_p; /* Pointer back to the original source block object. Needed to @@ -94,7 +94,7 @@ blpy_iter (PyObject *self) if (block_iter_obj == NULL) return NULL; - block_iter_obj->dict = BLOCK_DICT (block); + block_iter_obj->block = block; block_iter_obj->initialized_p = 0; Py_INCREF (self); block_iter_obj->source = (block_object *) self; @@ -311,11 +311,11 @@ blpy_block_syms_iternext (PyObject *self) if (!iter_obj->initialized_p) { - sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter)); + sym = block_iterator_first (iter_obj->block, &(iter_obj->iter)); iter_obj->initialized_p = 1; } else - sym = dict_iterator_next (&(iter_obj->iter)); + sym = block_iterator_next (&(iter_obj->iter)); if (sym == NULL) { diff --git a/gdb/stack.c b/gdb/stack.c index bbd6b7fe32..2c2797e81b 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -512,7 +512,7 @@ print_frame_args (struct symbol *func, struct frame_info *frame, if (func) { struct block *b = SYMBOL_BLOCK_VALUE (func); - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; ALL_BLOCK_SYMBOLS (b, iter, sym) @@ -1821,7 +1821,7 @@ iterate_over_block_locals (struct block *b, iterate_over_block_arg_local_vars_cb cb, void *cb_data) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; ALL_BLOCK_SYMBOLS (b, iter, sym) @@ -1858,7 +1858,7 @@ static int print_block_frame_labels (struct gdbarch *gdbarch, struct block *b, int *have_default, struct ui_file *stream) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; int values_printed = 0; @@ -1990,7 +1990,7 @@ iterate_over_block_arg_vars (struct block *b, iterate_over_block_arg_local_vars_cb cb, void *cb_data) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym, *sym2; ALL_BLOCK_SYMBOLS (b, iter, sym) diff --git a/gdb/symmisc.c b/gdb/symmisc.c index b0ab29b6c7..d5a737b049 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -353,8 +353,9 @@ dump_symtab_1 (struct objfile *objfile, struct symtab *symtab, } fprintf_filtered (outfile, "\n"); /* Now print each symbol in this block (in no particular order, if - we're using a hashtable). */ - ALL_BLOCK_SYMBOLS (b, iter, sym) + we're using a hashtable). Note that we only want this + block, not any blocks from included symtabs. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym) { struct print_symbol_args s; diff --git a/gdb/symtab.c b/gdb/symtab.c index 3fce349a3b..d4555d9d65 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1924,14 +1924,14 @@ struct symbol * lookup_block_symbol (const struct block *block, const char *name, const domain_enum domain) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; if (!BLOCK_FUNCTION (block)) { - for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter); + for (sym = block_iter_name_first (block, name, &iter); sym != NULL; - sym = dict_iter_name_next (name, &iter)) + sym = block_iter_name_next (name, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) @@ -1949,9 +1949,9 @@ lookup_block_symbol (const struct block *block, const char *name, struct symbol *sym_found = NULL; - for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter); + for (sym = block_iter_name_first (block, name, &iter); sym != NULL; - sym = dict_iter_name_next (name, &iter)) + sym = block_iter_name_next (name, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) @@ -1986,12 +1986,12 @@ iterate_over_symbols (const struct block *block, const char *name, { while (block) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; - for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter); + for (sym = block_iter_name_first (block, name, &iter); sym != NULL; - sym = dict_iter_name_next (name, &iter)) + sym = block_iter_name_next (name, &iter)) { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) @@ -2081,7 +2081,7 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section) } if (section != 0) { - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym = NULL; ALL_BLOCK_SYMBOLS (b, iter, sym) @@ -3329,7 +3329,7 @@ search_symbols (char *regexp, enum search_domain kind, struct blockvector *bv; struct block *b; int i = 0; - struct dict_iterator iter; + struct block_iterator iter; struct symbol *sym; struct objfile *objfile; struct minimal_symbol *msymbol; @@ -4131,7 +4131,7 @@ default_make_symbol_completion_list_break_on (char *text, char *word, struct objfile *objfile; struct block *b; const struct block *surrounding_static_block, *surrounding_global_block; - struct dict_iterator iter; + struct block_iterator iter; /* The symbol we are completing on. Points in same buffer as text. */ char *sym_text; /* Length of sym_text. */ @@ -4363,7 +4363,7 @@ make_file_symbol_completion_list (char *text, char *word, char *srcfile) struct symbol *sym; struct symtab *s; struct block *b; - struct dict_iterator iter; + struct block_iterator iter; /* The symbol we are completing on. Points in same buffer as text. */ char *sym_text; /* Length of sym_text. */ diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 6e47a0a7de..88fd01cbbf 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -2612,7 +2612,7 @@ scope_info (char *args, int from_tty) struct block *block; const char *symname; char *save_args = args; - struct dict_iterator iter; + struct block_iterator iter; int j, count = 0; struct gdbarch *gdbarch; int regno;