From 592553c46959c98bf5981ad245d0fbb97f373d2a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 24 Nov 2018 09:00:42 -0700 Subject: [PATCH] Remove ALL_OBJFILE_COMPUNITS This removes ALL_OBJFILE_COMPUNITS, replacing its uses with ranged for loops. Because ALL_COMPUNITS is also updated, in some places a declaration must be deleted to avoid shadowing. gdb/ChangeLog 2019-01-09 Tom Tromey * source.c (select_source_symtab) (forget_cached_source_info_for_objfile): Remove declaration. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove declaration. * maint.c (count_symtabs_and_blocks): Remove declaration. * cp-support.c (add_symbol_overload_list_qualified): Remove declaration. * coffread.c (coff_symtab_read): Remove declaration. * symtab.c (lookup_symbol_in_objfile_symtabs) (basic_lookup_transparent_type_1): Use objfile_compunits. (lookup_objfile_from_block, find_pc_sect_compunit_symtab) (info_sources_command, search_symbols) (default_collect_symbol_completion_matches_break_on) (make_source_files_completion_list): Remove declaration. * ada-lang.c (add_nonlocal_symbols): Use objfile_compunits. (ada_collect_symbol_completion_matches) (ada_add_global_exceptions): Remove declaration. * linespec.c (iterate_over_all_matching_symtabs): Use objfile_compunits. * objfiles.h (ALL_OBJFILE_COMPUNITS): Remove. (class objfile_compunits): New. (ALL_COMPUNITS): Use objfile_compunits. * symmisc.c (print_objfile_statistics, maintenance_info_symtabs) (maintenance_check_symtabs, maintenance_info_line_tables): Use objfile_compunits. * objfiles.c (objfile_relocate1): Use objfile_compunits. --- gdb/ChangeLog | 29 ++++++++++++++++++++++ gdb/ada-lang.c | 5 +--- gdb/coffread.c | 1 - gdb/cp-support.c | 1 - gdb/linespec.c | 4 +--- gdb/maint.c | 1 - gdb/mi/mi-cmd-file.c | 1 - gdb/objfiles.c | 68 ++++++++++++++++++++++++++-------------------------- gdb/objfiles.h | 18 ++++++++++---- gdb/source.c | 2 -- gdb/symmisc.c | 19 +++++---------- gdb/symtab.c | 14 ++--------- 12 files changed, 86 insertions(+), 77 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 08a80d8..13dca51 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,34 @@ 2019-01-09 Tom Tromey + * source.c (select_source_symtab) + (forget_cached_source_info_for_objfile): Remove declaration. + * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove + declaration. + * maint.c (count_symtabs_and_blocks): Remove declaration. + * cp-support.c (add_symbol_overload_list_qualified): Remove + declaration. + * coffread.c (coff_symtab_read): Remove declaration. + * symtab.c (lookup_symbol_in_objfile_symtabs) + (basic_lookup_transparent_type_1): Use objfile_compunits. + (lookup_objfile_from_block, find_pc_sect_compunit_symtab) + (info_sources_command, search_symbols) + (default_collect_symbol_completion_matches_break_on) + (make_source_files_completion_list): Remove declaration. + * ada-lang.c (add_nonlocal_symbols): Use objfile_compunits. + (ada_collect_symbol_completion_matches) + (ada_add_global_exceptions): Remove declaration. + * linespec.c (iterate_over_all_matching_symtabs): Use + objfile_compunits. + * objfiles.h (ALL_OBJFILE_COMPUNITS): Remove. + (class objfile_compunits): New. + (ALL_COMPUNITS): Use objfile_compunits. + * symmisc.c (print_objfile_statistics, maintenance_info_symtabs) + (maintenance_check_symtabs, maintenance_info_line_tables): Use + objfile_compunits. + * objfiles.c (objfile_relocate1): Use objfile_compunits. + +2019-01-09 Tom Tromey + * symtab.c (search_symbols) (default_collect_symbol_completion_matches_break_on): Use objfile_msymbols. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e23a6fa..69c368a 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5605,7 +5605,6 @@ add_nonlocal_symbols (struct obstack *obstackp, const lookup_name_info &lookup_name, domain_enum domain, int global) { - struct compunit_symtab *cu; struct match_data data; memset (&data, 0, sizeof data); @@ -5630,7 +5629,7 @@ add_nonlocal_symbols (struct obstack *obstackp, symbol_name_match_type::FULL, compare_names); - ALL_OBJFILE_COMPUNITS (objfile, cu) + for (compunit_symtab *cu : objfile_compunits (objfile)) { const struct block *global_block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu), GLOBAL_BLOCK); @@ -6391,7 +6390,6 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker, enum type_code code) { struct symbol *sym; - struct compunit_symtab *s; const struct block *b, *surrounding_static_block = 0; struct block_iterator iter; @@ -13551,7 +13549,6 @@ ada_add_global_exceptions (compiled_regex *preg, std::vector *exceptions) { struct objfile *objfile; - struct compunit_symtab *s; /* In Ada, the symbol "search name" is a linkage name, whereas the regular expression used to do the matching refers to the natural diff --git a/gdb/coffread.c b/gdb/coffread.c index e6ca7ed..2a86489 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1203,7 +1203,6 @@ coff_symtab_read (minimal_symbol_reader &reader, /* Patch up any opaque types (references to types that are not defined in the file where they are referenced, e.g. "struct foo *bar"). */ { - struct compunit_symtab *cu; struct symtab *s; ALL_OBJFILE_FILETABS (objfile, cu, s) diff --git a/gdb/cp-support.c b/gdb/cp-support.c index a5349ed..7906702 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1373,7 +1373,6 @@ static void add_symbol_overload_list_qualified (const char *func_name, std::vector *overload_list) { - struct compunit_symtab *cust; const struct block *b, *surrounding_static_block = 0; /* Look through the partial symtabs for all symbols which begin by diff --git a/gdb/linespec.c b/gdb/linespec.c index 0d08bbe..964697b 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1143,8 +1143,6 @@ iterate_over_all_matching_symtabs for (objfile *objfile : all_objfiles (current_program_space)) { - struct compunit_symtab *cu; - if (objfile->sf) objfile->sf->qf->expand_symtabs_matching (objfile, NULL, @@ -1152,7 +1150,7 @@ iterate_over_all_matching_symtabs NULL, NULL, search_domain); - ALL_OBJFILE_COMPUNITS (objfile, cu) + for (compunit_symtab *cu : objfile_compunits (objfile)) { struct symtab *symtab = COMPUNIT_FILETABS (cu); diff --git a/gdb/maint.c b/gdb/maint.c index 01d04df..a4241cd 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -763,7 +763,6 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, int *nr_blocks_ptr) { struct objfile *o; - struct compunit_symtab *cu; struct symtab *s; int nr_symtabs = 0; int nr_compunit_symtabs = 0; diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c index 580dd90..dbd535b 100644 --- a/gdb/mi/mi-cmd-file.c +++ b/gdb/mi/mi-cmd-file.c @@ -84,7 +84,6 @@ void mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc) { struct ui_out *uiout = current_uiout; - struct compunit_symtab *cu; struct symtab *s; struct objfile *objfile; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 5d46e69..dc94322 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -788,7 +788,6 @@ objfile_relocate1 (struct objfile *objfile, /* OK, get all the symtabs. */ { - struct compunit_symtab *cust; struct symtab *s; ALL_OBJFILE_FILETABS (objfile, cust, s) @@ -806,41 +805,42 @@ objfile_relocate1 (struct objfile *objfile, } } - ALL_OBJFILE_COMPUNITS (objfile, cust) - { - const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (cust); - int block_line_section = COMPUNIT_BLOCK_LINE_SECTION (cust); - - if (BLOCKVECTOR_MAP (bv)) - addrmap_relocate (BLOCKVECTOR_MAP (bv), - ANOFFSET (delta, block_line_section)); - - for (int i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i) - { - struct block *b; - struct symbol *sym; - struct dict_iterator iter; - - b = BLOCKVECTOR_BLOCK (bv, i); - BLOCK_START (b) += ANOFFSET (delta, block_line_section); - BLOCK_END (b) += ANOFFSET (delta, block_line_section); - - if (BLOCK_RANGES (b) != nullptr) - for (int j = 0; j < BLOCK_NRANGES (b); j++) + for (compunit_symtab *cust : objfile_compunits (objfile)) + { + const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (cust); + int block_line_section = COMPUNIT_BLOCK_LINE_SECTION (cust); + + if (BLOCKVECTOR_MAP (bv)) + addrmap_relocate (BLOCKVECTOR_MAP (bv), + ANOFFSET (delta, block_line_section)); + + for (int i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i) + { + struct block *b; + struct symbol *sym; + struct dict_iterator iter; + + b = BLOCKVECTOR_BLOCK (bv, i); + BLOCK_START (b) += ANOFFSET (delta, block_line_section); + BLOCK_END (b) += ANOFFSET (delta, block_line_section); + + if (BLOCK_RANGES (b) != nullptr) + for (int j = 0; j < BLOCK_NRANGES (b); j++) + { + BLOCK_RANGE_START (b, j) + += ANOFFSET (delta, block_line_section); + BLOCK_RANGE_END (b, j) += ANOFFSET (delta, + block_line_section); + } + + /* We only want to iterate over the local symbols, not any + symbols in included symtabs. */ + ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym) { - BLOCK_RANGE_START (b, j) - += ANOFFSET (delta, block_line_section); - BLOCK_RANGE_END (b, j) += ANOFFSET (delta, block_line_section); + relocate_one_symbol (sym, objfile, delta); } - - /* 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); - } - } - } + } + } } /* This stores relocated addresses and so must be cleared. This diff --git a/gdb/objfiles.h b/gdb/objfiles.h index a3b0e92..ba6be2d 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -615,13 +615,21 @@ public: /* Traverse all symtabs in one objfile. */ #define ALL_OBJFILE_FILETABS(objfile, cu, s) \ - ALL_OBJFILE_COMPUNITS (objfile, cu) \ + for (compunit_symtab *cu : objfile_compunits (objfile)) \ ALL_COMPUNIT_FILETABS (cu, s) -/* Traverse all compunits in one objfile. */ +/* A range adapter that makes it possible to iterate over all + compunits in one objfile. */ + +class objfile_compunits : public next_adapter +{ +public: -#define ALL_OBJFILE_COMPUNITS(objfile, cu) \ - for ((cu) = (objfile) -> compunit_symtabs; (cu) != NULL; (cu) = (cu) -> next) + explicit objfile_compunits (struct objfile *objfile) + : next_adapter (objfile->compunit_symtabs) + { + } +}; /* A range adapter that makes it possible to iterate over all minimal symbols of an objfile. */ @@ -714,7 +722,7 @@ private: #define ALL_COMPUNITS(objfile, cu) \ ALL_OBJFILES (objfile) \ - ALL_OBJFILE_COMPUNITS (objfile, cu) + for (compunit_symtab *cu : objfile_compunits (objfile)) #define ALL_OBJFILE_OSECTIONS(objfile, osect) \ for (osect = objfile->sections; osect < objfile->sections_end; osect++) \ diff --git a/gdb/source.c b/gdb/source.c index 74c895c..3fc4ad5 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -239,7 +239,6 @@ void select_source_symtab (struct symtab *s) { struct objfile *ofp; - struct compunit_symtab *cu; if (s) { @@ -350,7 +349,6 @@ show_directories_command (struct ui_file *file, int from_tty, void forget_cached_source_info_for_objfile (struct objfile *objfile) { - struct compunit_symtab *cu; struct symtab *s; ALL_OBJFILE_FILETABS (objfile, cu, s) diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 24f9176..afe9d04 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -82,7 +82,6 @@ void print_objfile_statistics (void) { struct program_space *pspace; - struct compunit_symtab *cu; struct symtab *s; int i, linetables, blockvectors; @@ -108,15 +107,15 @@ print_objfile_statistics (void) OBJSTAT (objfile, n_types)); if (objfile->sf) objfile->sf->qf->print_stats (objfile); - i = linetables = blockvectors = 0; + i = linetables = 0; ALL_OBJFILE_FILETABS (objfile, cu, s) { i++; if (SYMTAB_LINETABLE (s) != NULL) linetables++; } - ALL_OBJFILE_COMPUNITS (objfile, cu) - blockvectors++; + blockvectors = std::distance (objfile_compunits (objfile).begin (), + objfile_compunits (objfile).end ()); printf_filtered (_(" Number of symbol tables: %d\n"), i); printf_filtered (_(" Number of symbol tables with line tables: %d\n"), linetables); @@ -145,7 +144,6 @@ print_objfile_statistics (void) static void dump_objfile (struct objfile *objfile) { - struct compunit_symtab *cust; struct symtab *symtab; printf_filtered ("\nObject file %s: ", objfile_name (objfile)); @@ -469,7 +467,6 @@ maintenance_print_symbols (const char *args, int from_tty) } else { - struct compunit_symtab *cu; struct symtab *s; int found = 0; @@ -775,14 +772,13 @@ maintenance_info_symtabs (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (objfile *objfile : all_objfiles (pspace)) { - struct compunit_symtab *cust; struct symtab *symtab; /* We don't want to print anything for this objfile until we actually find a symtab whose name matches. */ int printed_objfile_start = 0; - ALL_OBJFILE_COMPUNITS (objfile, cust) + for (compunit_symtab *cust : objfile_compunits (objfile)) { int printed_compunit_symtab_start = 0; @@ -863,13 +859,11 @@ maintenance_check_symtabs (const char *ignore, int from_tty) ALL_PSPACES (pspace) for (objfile *objfile : all_objfiles (pspace)) { - struct compunit_symtab *cust; - /* We don't want to print anything for this objfile until we actually find something worth printing. */ int printed_objfile_start = 0; - ALL_OBJFILE_COMPUNITS (objfile, cust) + for (compunit_symtab *cust : objfile_compunits (objfile)) { int found_something = 0; struct symtab *symtab = compunit_primary_filetab (cust); @@ -1032,10 +1026,9 @@ maintenance_info_line_tables (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (objfile *objfile : all_objfiles (pspace)) { - struct compunit_symtab *cust; struct symtab *symtab; - ALL_OBJFILE_COMPUNITS (objfile, cust) + for (compunit_symtab *cust : objfile_compunits (objfile)) { ALL_COMPUNIT_FILETABS (cust, symtab) { diff --git a/gdb/symtab.c b/gdb/symtab.c index 8bd91bc..0cd5119 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2167,7 +2167,6 @@ struct objfile * lookup_objfile_from_block (const struct block *block) { struct objfile *obj; - struct compunit_symtab *cust; if (block == NULL) return NULL; @@ -2255,8 +2254,6 @@ static struct block_symbol lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, const char *name, const domain_enum domain) { - struct compunit_symtab *cust; - gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK); if (symbol_lookup_debug > 1) @@ -2269,7 +2266,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, name, domain_name (domain)); } - ALL_OBJFILE_COMPUNITS (objfile, cust) + for (compunit_symtab *cust : objfile_compunits (objfile)) { const struct blockvector *bv; const struct block *block; @@ -2763,12 +2760,11 @@ static struct type * basic_lookup_transparent_type_1 (struct objfile *objfile, int block_index, const char *name) { - const struct compunit_symtab *cust; const struct blockvector *bv; const struct block *block; const struct symbol *sym; - ALL_OBJFILE_COMPUNITS (objfile, cust) + for (compunit_symtab *cust : objfile_compunits (objfile)) { bv = COMPUNIT_BLOCKVECTOR (cust); block = BLOCKVECTOR_BLOCK (bv, block_index); @@ -2874,7 +2870,6 @@ iterate_over_symbols (const struct block *block, struct compunit_symtab * find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) { - struct compunit_symtab *cust; struct compunit_symtab *best_cust = NULL; struct objfile *obj_file; CORE_ADDR distance = 0; @@ -3349,7 +3344,6 @@ find_line_symtab (struct symtab *symtab, int line, BEST_INDEX and BEST_LINETABLE identify the item for it. */ int best; - struct compunit_symtab *cu; struct symtab *s; if (best_index >= 0) @@ -4185,7 +4179,6 @@ output_partial_symbol_filename (const char *filename, const char *fullname, static void info_sources_command (const char *ignore, int from_tty) { - struct compunit_symtab *cu; struct symtab *s; struct objfile *objfile; struct output_source_filename_data data; @@ -4338,7 +4331,6 @@ search_symbols (const char *regexp, enum search_domain kind, const char *t_regexp, int nfiles, const char *files[]) { - struct compunit_symtab *cust; const struct blockvector *bv; struct block *b; int i = 0; @@ -5202,7 +5194,6 @@ default_collect_symbol_completion_matches_break_on won't be that many. */ struct symbol *sym; - struct compunit_symtab *cust; const struct block *b; const struct block *surrounding_static_block, *surrounding_global_block; struct block_iterator iter; @@ -5588,7 +5579,6 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname, completion_list make_source_files_completion_list (const char *text, const char *word) { - struct compunit_symtab *cu; struct symtab *s; struct objfile *objfile; size_t text_len = strlen (text); -- 2.7.4