From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Jacobowitz To: Elena Zannoni Cc: gdb-patches@sources.redhat.com Subject: Re: [rfa] symbol hashing, part 2/n - ALL_BLOCK_SYMBOLS Date: Fri, 12 Oct 2001 11:59:00 -0000 Message-id: <20011012145834.B16180@nevyn.them.org> References: <20011009123457.A28534@nevyn.them.org> <15302.12121.778853.77938@krustylu.cygnus.com> <20011011195450.A22256@nevyn.them.org> <15303.4807.801121.915108@krustylu.cygnus.com> X-SW-Source: 2001-10/msg00174.html On Fri, Oct 12, 2001 at 11:56:55AM -0400, Elena Zannoni wrote: > No need to resubmit. Just check it in as 2 patches instead of 1. So > that I can do cvs diffs between versions of the file later, if there > is an issue. Gotcha. > Yes, I would prefer to change this too. Included now. > How about this other one? in symtab.c ~line 1254 > > top = BLOCK_NSYMS (block); > while (bot < top) > { > sym = BLOCK_SYM (block, bot); > if (SYMBOL_NAMESPACE (sym) == namespace && > SYMBOL_MATCHES_NAME (sym, name)) > { > return sym; > } > bot++; > } Can't. Bot is not 0; this doesn't search all symbols. Also, ALL_BLOCK_SYMBOLS logically doesn't imply an ordered search, which this demands. This'll be clarified in the hashing patch. > > > Another one is in mi/mi-stack-cmd.c. > > > There are some also in gdbtk/generic/gdbtk-cmds.c and gdbtk-stack.c. > > > > These I missed; I didn't think to check further down than the top > > level. I'll get them when I repost this, which it looks like I'll need > > to do. > > > > No, just post the new changes only. Got this bunch also. Do I need someone else's approval to check in changes to gdbtk/generic/? I don't think so, since these are obvious. I'm actually just attaching the whole patch; it's relatively short now, and I've tweaked it in a couple of places. > > > Some tricky ones are left, for a second pass. In mdebugread.c: it is > > > actually a while loop, in mylookup_symbol, similarly in coffread.c: > > > patch_opaque_types(), the for loop is reversed. > > > (Were these in your original patch? I don't remember). > > > > The one in coffread worries me; I can not tell from the comments if it > > is order-sensitive or not. The one in mdebugread does not, because > > mdebugread does dastardly things to blocks. I deliberately left those > > unhashed. > > Hmmm, maybe we should leave the coffread one alone. I'd actually appreciate it if you, or someone else with a little experience with coffread (any takers?), would look at this. It absolutely has to be changed eventually; I didn't include it in this patch only because it wasn't obvious. > But I think we should use the macro in mdebugread.c. Sure. Here's what I've got now. I'll commit it later today unless someone sees a problem with it. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer 2001-10-01 Daniel Jacobowitz * symtab.h (struct block): (ALL_BLOCK_SYMBOLS): New macro. * symtab.c (find_pc_sect_symtab): Use ALL_BLOCK_SYMBOLS. (make_symbol_completion_list): Likewise. (make_symbol_overload_list): Likewise. * buildsym.c (finish_block): Likewise. * breakpoint.c (get_catch_sals): Likewise. * mdebugread.c (mylookup_symbol): Likewise. * objfiles.c (objfile_relocate): Likewise. * printcmd.c (print_frame_args): Likewise. * stack.c (print_block_frame_locals): Likewise. (print_block_frame_labels): Likewise. (print_frame_arg_vars): Likewise. * symmisc.c (dump_symtab): Likewise. * tracepoint.c (add_local_symbols): Likewise. (scope_info): Likewise. 2001-10-12 Daniel Jacobowitz * mi-cmd-stack.c (list_args_or_locals): Use ALL_BLOCK_SYMBOLS. 2001-10-12 Daniel Jacobowitz * generic/gdbtk-cmds.c (gdb_listfuncs): Use ALL_BLOCK_SYMBOLS. * generic/gdbtk-stack.c (gdb_block_vars): Likewise. (gdb_get_blocks): Likewise. (gdb_get_vars_command): Likewise. Index: gdb/breakpoint.c =================================================================== RCS file: /cvs/src/src/gdb/breakpoint.c,v retrieving revision 1.53 diff -u -p -r1.53 breakpoint.c --- gdb/breakpoint.c 2001/09/18 05:00:48 1.53 +++ gdb/breakpoint.c 2001/10/12 18:34:49 @@ -5871,15 +5871,11 @@ get_catch_sals (int this_level_only) if (blocks_searched[index] == 0) { struct block *b = BLOCKVECTOR_BLOCK (bl, index); - int nsyms; register int i; register struct symbol *sym; - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); if (STREQ (SYMBOL_NAME (sym), "default")) { if (have_default) Index: gdb/buildsym.c =================================================================== RCS file: /cvs/src/src/gdb/buildsym.c,v retrieving revision 1.11 diff -u -p -r1.11 buildsym.c --- gdb/buildsym.c 2001/04/30 10:30:27 1.11 +++ gdb/buildsym.c 2001/10/12 18:34:49 @@ -275,9 +275,8 @@ finish_block (struct symbol *symbol, str parameter symbols. */ int nparams = 0, iparams; struct symbol *sym; - for (i = 0; i < BLOCK_NSYMS (block); i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { case LOC_ARG: Index: gdb/mdebugread.c =================================================================== RCS file: /cvs/src/src/gdb/mdebugread.c,v retrieving revision 1.15 diff -u -p -r1.15 mdebugread.c --- gdb/mdebugread.c 2001/09/05 02:54:15 1.15 +++ gdb/mdebugread.c 2001/10/12 18:34:50 @@ -3853,22 +3853,19 @@ static struct symbol * mylookup_symbol (char *name, register struct block *block, namespace_enum namespace, enum address_class class) { - register int bot, top, inc; - register struct symbol *sym; + int i, inc; + struct symbol *sym; - bot = 0; - top = BLOCK_NSYMS (block); inc = name[0]; - while (bot < top) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, bot); if (SYMBOL_NAME (sym)[0] == inc && SYMBOL_NAMESPACE (sym) == namespace && SYMBOL_CLASS (sym) == class && strcmp (SYMBOL_NAME (sym), name) == 0) return sym; - bot++; } + block = BLOCK_SUPERBLOCK (block); if (block) return mylookup_symbol (name, block, namespace, class); Index: gdb/objfiles.c =================================================================== RCS file: /cvs/src/src/gdb/objfiles.c,v retrieving revision 1.16 diff -u -p -r1.16 objfiles.c --- gdb/objfiles.c 2001/07/05 21:32:39 1.16 +++ gdb/objfiles.c 2001/10/12 18:34:50 @@ -557,16 +557,15 @@ objfile_relocate (struct objfile *objfil for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i) { struct block *b; + struct symbol *sym; int j; b = BLOCKVECTOR_BLOCK (bv, i); BLOCK_START (b) += ANOFFSET (delta, s->block_line_section); BLOCK_END (b) += ANOFFSET (delta, s->block_line_section); - for (j = 0; j < BLOCK_NSYMS (b); ++j) + ALL_BLOCK_SYMBOLS (b, j, sym) { - struct symbol *sym = BLOCK_SYM (b, j); - fixup_symbol_section (sym, objfile); /* The RS6000 code from which this was taken skipped Index: gdb/printcmd.c =================================================================== RCS file: /cvs/src/src/gdb/printcmd.c,v retrieving revision 1.28 diff -u -p -r1.28 printcmd.c --- gdb/printcmd.c 2001/10/12 17:15:34 1.28 +++ gdb/printcmd.c 2001/10/12 18:34:50 @@ -1783,7 +1783,6 @@ print_frame_args (struct symbol *func, s struct ui_file *stream) { struct block *b = NULL; - int nsyms = 0; int first = 1; register int i; register struct symbol *sym; @@ -1806,12 +1805,9 @@ print_frame_args (struct symbol *func, s if (func) { b = SYMBOL_BLOCK_VALUE (func); - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { QUIT; - sym = BLOCK_SYM (b, i); /* Keep track of the highest stack argument offset seen, and skip over any kinds of symbols we don't care about. */ Index: gdb/stack.c =================================================================== RCS file: /cvs/src/src/gdb/stack.c,v retrieving revision 1.22 diff -u -p -r1.22 stack.c --- gdb/stack.c 2001/07/14 18:59:07 1.22 +++ gdb/stack.c 2001/10/12 18:34:50 @@ -1207,16 +1207,12 @@ static int print_block_frame_locals (struct block *b, register struct frame_info *fi, int num_tabs, register struct ui_file *stream) { - int nsyms; register int i, j; register struct symbol *sym; register int values_printed = 0; - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); switch (SYMBOL_CLASS (sym)) { case LOC_LOCAL: @@ -1246,16 +1242,12 @@ static int print_block_frame_labels (struct block *b, int *have_default, register struct ui_file *stream) { - int nsyms; register int i; register struct symbol *sym; register int values_printed = 0; - - nsyms = BLOCK_NSYMS (b); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); if (STREQ (SYMBOL_NAME (sym), "default")) { if (*have_default) @@ -1432,7 +1424,6 @@ print_frame_arg_vars (register struct fr { struct symbol *func = get_frame_function (fi); register struct block *b; - int nsyms; register int i; register struct symbol *sym, *sym2; register int values_printed = 0; @@ -1444,11 +1435,8 @@ print_frame_arg_vars (register struct fr } b = SYMBOL_BLOCK_VALUE (func); - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); switch (SYMBOL_CLASS (sym)) { case LOC_ARG: @@ -1483,7 +1471,6 @@ print_frame_arg_vars (register struct fr break; } } - if (!values_printed) { fprintf_filtered (stream, "No arguments.\n"); Index: gdb/symmisc.c =================================================================== RCS file: /cvs/src/src/gdb/symmisc.c,v retrieving revision 1.5 diff -u -p -r1.5 symmisc.c --- gdb/symmisc.c 2001/03/06 08:21:17 1.5 +++ gdb/symmisc.c 2001/10/12 18:34:50 @@ -410,6 +410,7 @@ dump_symtab (struct objfile *objfile, st int len, blen; register struct linetable *l; struct blockvector *bv; + struct symbol *sym; register struct block *b; int depth; @@ -471,11 +472,12 @@ dump_symtab (struct objfile *objfile, st if (BLOCK_GCC_COMPILED (b)) fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b)); fprintf_filtered (outfile, "\n"); - /* Now print each symbol in this block */ - for (j = 0; j < blen; j++) + /* Now print each symbol in this block. */ + /* FIXMED: Sort? */ + ALL_BLOCK_SYMBOLS (b, j, sym) { struct print_symbol_args s; - s.symbol = BLOCK_SYM (b, j); + s.symbol = sym; s.depth = depth + 1; s.outfile = outfile; catch_errors (print_symbol, &s, "Error printing symbol:\n", Index: gdb/symtab.c =================================================================== RCS file: /cvs/src/src/gdb/symtab.c,v retrieving revision 1.43 diff -u -p -r1.43 symtab.c --- gdb/symtab.c 2001/10/12 03:38:12 1.43 +++ gdb/symtab.c 2001/10/12 18:34:50 @@ -2992,9 +2992,8 @@ make_symbol_completion_list (char *text, /* Also catch fields of types defined in this places which match our text string. Only complete on types visible from current context. */ - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) { @@ -3023,9 +3022,8 @@ make_symbol_completion_list (char *text, { QUIT; b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); } } @@ -3037,9 +3035,8 @@ make_symbol_completion_list (char *text, /* Don't do this block twice. */ if (b == surrounding_static_block) continue; - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); } } @@ -3143,16 +3140,14 @@ make_file_symbol_completion_list (char * symbols which match. */ b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); } b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); } @@ -3530,9 +3525,8 @@ make_symbol_overload_list (struct symbol /* Also catch fields of types defined in this places which match our text string. Only complete on types visible from current context. */ - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); overload_list_add_symbol (sym, oload_name); } } @@ -3544,9 +3538,8 @@ make_symbol_overload_list (struct symbol { QUIT; b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); overload_list_add_symbol (sym, oload_name); } } @@ -3558,9 +3551,8 @@ make_symbol_overload_list (struct symbol /* Don't do this block twice. */ if (b == surrounding_static_block) continue; - for (i = 0; i < BLOCK_NSYMS (b); i++) + ALL_BLOCK_SYMBOLS (b, i, sym) { - sym = BLOCK_SYM (b, i); overload_list_add_symbol (sym, oload_name); } } Index: gdb/symtab.h =================================================================== RCS file: /cvs/src/src/gdb/symtab.h,v retrieving revision 1.24 diff -u -p -r1.24 symtab.h --- gdb/symtab.h 2001/07/07 17:19:50 1.24 +++ gdb/symtab.h 2001/10/12 18:34:50 @@ -467,6 +467,14 @@ struct block #define BLOCK_SUPERBLOCK(bl) (bl)->superblock #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag +/* Macro to loop through all symbols in a block BL. + i counts which symbol we are looking at, and sym points to the current + symbol. */ +#define ALL_BLOCK_SYMBOLS(bl, i, sym) \ + for ((i) = 0, (sym) = BLOCK_SYM ((bl), (i)); \ + (i) < BLOCK_NSYMS ((bl)); \ + ++(i), (sym) = BLOCK_SYM ((bl), (i))) + /* Nonzero if symbols of block BL should be sorted alphabetically. Don't sort a block which corresponds to a function. If we did the sorting would have to preserve the order of the symbols for the Index: gdb/tracepoint.c =================================================================== RCS file: /cvs/src/src/gdb/tracepoint.c,v retrieving revision 1.26 diff -u -p -r1.26 tracepoint.c --- gdb/tracepoint.c 2001/08/23 20:31:36 1.26 +++ gdb/tracepoint.c 2001/10/12 18:34:50 @@ -1296,16 +1296,14 @@ add_local_symbols (struct collection_lis { struct symbol *sym; struct block *block; - int i, nsyms, count = 0; + int i, count = 0; block = block_for_pc (pc); while (block != 0) { QUIT; /* allow user to bail out with ^C */ - nsyms = BLOCK_NSYMS (block); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { default: @@ -2335,7 +2333,7 @@ scope_info (char *args, int from_tty) struct minimal_symbol *msym; struct block *block; char **canonical, *symname, *save_args = args; - int i, j, nsyms, count = 0; + int i, j, count = 0; if (args == 0 || *args == 0) error ("requires an argument (function, line or *addr) to define a scope"); @@ -2351,14 +2349,13 @@ scope_info (char *args, int from_tty) while (block != 0) { QUIT; /* allow user to bail out with ^C */ - nsyms = BLOCK_NSYMS (block); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { QUIT; /* allow user to bail out with ^C */ if (count == 0) printf_filtered ("Scope for %s:\n", save_args); count++; - sym = BLOCK_SYM (block, i); + symname = SYMBOL_NAME (sym); if (symname == NULL || *symname == '\0') continue; /* probably botched, certainly useless */ Index: gdb/gdbtk/generic/gdbtk-cmds.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v retrieving revision 1.39 diff -u -p -r1.39 gdbtk-cmds.c --- gdb/gdbtk/generic/gdbtk-cmds.c 2001/08/28 22:22:56 1.39 +++ gdb/gdbtk/generic/gdbtk-cmds.c 2001/10/12 18:34:50 @@ -1498,9 +1498,8 @@ gdb_listfuncs (clientData, interp, objc, /* Skip the sort if this block is always sorted. */ if (!BLOCK_SHOULD_SORT (b)) sort_block_syms (b); - for (j = 0; j < BLOCK_NSYMS (b); j++) + ALL_BLOCK_SYMBOLS (b, j, sym) { - sym = BLOCK_SYM (b, j); if (SYMBOL_CLASS (sym) == LOC_BLOCK) { Index: gdb/gdbtk/generic/gdbtk-stack.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-stack.c,v retrieving revision 1.2 diff -u -p -r1.2 gdbtk-stack.c --- gdb/gdbtk/generic/gdbtk-stack.c 2001/06/11 20:07:46 1.2 +++ gdb/gdbtk/generic/gdbtk-stack.c 2001/10/12 18:34:50 @@ -19,6 +19,7 @@ Boston, MA 02111-1307, USA. */ #include "defs.h" +#include "symtab.h" #include "frame.h" #include "value.h" #include "target.h" @@ -93,7 +94,7 @@ gdb_block_vars (clientData, interp, objc Tcl_Obj *CONST objv[]; { struct block *block; - int nsyms, i; + int i; struct symbol *sym; CORE_ADDR start, end; @@ -117,10 +118,8 @@ gdb_block_vars (clientData, interp, objc { if (BLOCK_START (block) == start && BLOCK_END (block) == end) { - nsyms = BLOCK_NSYMS (block); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { case LOC_ARG: /* argument */ @@ -172,7 +171,7 @@ gdb_get_blocks (clientData, interp, objc Tcl_Obj *CONST objv[]; { struct block *block; - int nsyms, i, junk; + int i, junk; struct symbol *sym; CORE_ADDR pc; @@ -184,11 +183,9 @@ gdb_get_blocks (clientData, interp, objc pc = get_frame_pc (selected_frame); while (block != 0) { - nsyms = BLOCK_NSYMS (block); junk = 0; - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { default: @@ -301,7 +298,7 @@ gdb_get_vars_command (clientData, interp struct symbol *sym; struct block *block; char **canonical, *args; - int i, nsyms, arguments; + int i, arguments; if (objc > 2) { @@ -344,10 +341,8 @@ gdb_get_vars_command (clientData, interp while (block != 0) { - nsyms = BLOCK_NSYMS (block); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { default: Index: gdb/mi/mi-cmd-stack.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v retrieving revision 1.7 diff -u -p -r1.7 mi-cmd-stack.c --- gdb/mi/mi-cmd-stack.c 2001/06/26 18:50:51 1.7 +++ gdb/mi/mi-cmd-stack.c 2001/10/12 18:34:50 @@ -25,6 +25,7 @@ #include "value.h" #include "mi-cmds.h" #include "ui-out.h" +#include "symtab.h" #ifdef UI_OUT /* FIXME: these should go in some .h file but stack.c doesn't have a @@ -226,10 +227,8 @@ list_args_or_locals (int locals, int val while (block != 0) { - nsyms = BLOCK_NSYMS (block); - for (i = 0; i < nsyms; i++) + ALL_BLOCK_SYMBOLS (block, i, sym) { - sym = BLOCK_SYM (block, i); switch (SYMBOL_CLASS (sym)) { default: