From 5accd1a07e080c386918da413e0f9e90c4cab58a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 24 Nov 2018 09:49:24 -0700 Subject: [PATCH] Remove ALL_COMPUNIT_FILETABS This removes ALL_COMPUNIT_FILETABS, replacing its uses with ranged for loops. Because this is still used in the ALL_OBJFILE_FILETABS macro, in some places a declaration had to be removed or renamed to avoid shadowing. gdb/ChangeLog 2019-01-09 Tom Tromey * symtab.h (ALL_COMPUNIT_FILETABS): Remove. (compunit_filetabs): New. * symtab.c (iterate_over_some_symtabs, find_pc_sect_line): Use compunit_filetabs. (info_sources_command, make_source_files_completion_list): Remove declaration. * symmisc.c (print_objfile_statistics, dump_objfile) (maintenance_print_symbols): Remove declaration. (maintenance_info_symtabs): Use compunit_filetabs. (maintenance_info_line_tables): Likewise. * source.c (select_source_symtab): Change local variable name. (forget_cached_source_info_for_objfile): Remove declaration. * objfiles.h (ALL_OBJFILE_FILETABS): Use compunit_filetabs. * objfiles.c (objfile_relocate1): Remove declaration. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove declaration. * maint.c (count_symtabs_and_blocks): Use compunit_filetabs. * coffread.c (coff_symtab_read): Remove declaration. * buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use compunit_filetabs. --- gdb/ChangeLog | 23 +++++++++++++++++++++++ gdb/buildsym.c | 7 +++---- gdb/coffread.c | 2 -- gdb/maint.c | 5 ++--- gdb/mi/mi-cmd-file.c | 1 - gdb/objfiles.c | 2 -- gdb/objfiles.h | 2 +- gdb/source.c | 8 +++----- gdb/symmisc.c | 12 ++---------- gdb/symtab.c | 22 ++++++++-------------- gdb/symtab.h | 13 ++++++++++--- 11 files changed, 52 insertions(+), 45 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 70c84979f9..eb6c3a8330 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,26 @@ +2019-01-09 Tom Tromey + + * symtab.h (ALL_COMPUNIT_FILETABS): Remove. + (compunit_filetabs): New. + * symtab.c (iterate_over_some_symtabs, find_pc_sect_line): Use + compunit_filetabs. + (info_sources_command, make_source_files_completion_list): Remove + declaration. + * symmisc.c (print_objfile_statistics, dump_objfile) + (maintenance_print_symbols): Remove declaration. + (maintenance_info_symtabs): Use compunit_filetabs. + (maintenance_info_line_tables): Likewise. + * source.c (select_source_symtab): Change local variable name. + (forget_cached_source_info_for_objfile): Remove declaration. + * objfiles.h (ALL_OBJFILE_FILETABS): Use compunit_filetabs. + * objfiles.c (objfile_relocate1): Remove declaration. + * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove + declaration. + * maint.c (count_symtabs_and_blocks): Use compunit_filetabs. + * coffread.c (coff_symtab_read): Remove declaration. + * buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use + compunit_filetabs. + 2019-01-09 Tom Tromey * symtab.c (lookup_objfile_from_block) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 2e30162fd5..1afff3d12e 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -927,7 +927,6 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block, int section, int expandable) { struct compunit_symtab *cu = m_compunit_symtab; - struct symtab *symtab; struct blockvector *blockvector; struct subfile *subfile; CORE_ADDR end_addr; @@ -979,7 +978,7 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block, /* Allocate a symbol table if necessary. */ if (subfile->symtab == NULL) subfile->symtab = allocate_symtab (cu, subfile->name); - symtab = subfile->symtab; + struct symtab *symtab = subfile->symtab; /* Fill in its components. */ @@ -1011,7 +1010,7 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block, main_symtab = m_main_subfile->symtab; prev_symtab = NULL; - ALL_COMPUNIT_FILETABS (cu, symtab) + for (symtab *symtab : compunit_filetabs (cu)) { if (symtab == main_symtab) { @@ -1061,7 +1060,7 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block, int block_i; /* The main source file's symtab. */ - symtab = COMPUNIT_FILETABS (cu); + struct symtab *symtab = COMPUNIT_FILETABS (cu); for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++) { diff --git a/gdb/coffread.c b/gdb/coffread.c index 2a864892ed..611febe8e5 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1203,8 +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 symtab *s; - ALL_OBJFILE_FILETABS (objfile, cu, s) patch_opaque_types (s); } diff --git a/gdb/maint.c b/gdb/maint.c index d969e79e4f..04b4473e31 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -762,7 +762,6 @@ static void count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, int *nr_blocks_ptr) { - struct symtab *s; int nr_symtabs = 0; int nr_compunit_symtabs = 0; int nr_blocks = 0; @@ -778,8 +777,8 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, { ++nr_compunit_symtabs; nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu)); - ALL_COMPUNIT_FILETABS (cu, s) - ++nr_symtabs; + nr_symtabs += std::distance (compunit_filetabs (cu).begin (), + compunit_filetabs (cu).end ()); } } } diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c index dbd535b176..d645e5a0c3 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 symtab *s; struct objfile *objfile; if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv)) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index dc94322baf..659998a565 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -788,8 +788,6 @@ objfile_relocate1 (struct objfile *objfile, /* OK, get all the symtabs. */ { - struct symtab *s; - ALL_OBJFILE_FILETABS (objfile, cust, s) { struct linetable *l; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index ae6a779491..d6a7064c5e 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -616,7 +616,7 @@ public: #define ALL_OBJFILE_FILETABS(objfile, cu, s) \ for (compunit_symtab *cu : objfile_compunits (objfile)) \ - ALL_COMPUNIT_FILETABS (cu, s) + for (symtab *s : compunit_filetabs (cu)) /* A range adapter that makes it possible to iterate over all compunits in one objfile. */ diff --git a/gdb/source.c b/gdb/source.c index 3fc4ad5d2b..ed0ff4c510 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -271,16 +271,16 @@ select_source_symtab (struct symtab *s) current_source_line = 1; - ALL_FILETABS (ofp, cu, s) + ALL_FILETABS (ofp, cu, symtab) { - const char *name = s->filename; + const char *name = symtab->filename; int len = strlen (name); if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0 || strcmp (name, "<>") == 0))) { current_source_pspace = current_program_space; - current_source_symtab = s; + current_source_symtab = symtab; } } @@ -349,8 +349,6 @@ show_directories_command (struct ui_file *file, int from_tty, void forget_cached_source_info_for_objfile (struct objfile *objfile) { - struct symtab *s; - ALL_OBJFILE_FILETABS (objfile, cu, s) { if (s->line_charpos != NULL) diff --git a/gdb/symmisc.c b/gdb/symmisc.c index afe9d04573..f067292f9d 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -82,7 +82,6 @@ void print_objfile_statistics (void) { struct program_space *pspace; - struct symtab *s; int i, linetables, blockvectors; ALL_PSPACES (pspace) @@ -144,8 +143,6 @@ print_objfile_statistics (void) static void dump_objfile (struct objfile *objfile) { - struct symtab *symtab; - printf_filtered ("\nObject file %s: ", objfile_name (objfile)); printf_filtered ("Objfile at "); gdb_print_host_address (objfile, gdb_stdout); @@ -467,7 +464,6 @@ maintenance_print_symbols (const char *args, int from_tty) } else { - struct symtab *s; int found = 0; for (objfile *objfile : all_objfiles (current_program_space)) @@ -772,8 +768,6 @@ maintenance_info_symtabs (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (objfile *objfile : all_objfiles (pspace)) { - 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; @@ -782,7 +776,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty) { int printed_compunit_symtab_start = 0; - ALL_COMPUNIT_FILETABS (cust, symtab) + for (symtab *symtab : compunit_filetabs (cust)) { QUIT; @@ -1026,11 +1020,9 @@ maintenance_info_line_tables (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (objfile *objfile : all_objfiles (pspace)) { - struct symtab *symtab; - for (compunit_symtab *cust : objfile_compunits (objfile)) { - ALL_COMPUNIT_FILETABS (cust, symtab) + for (symtab *symtab : compunit_filetabs (cust)) { QUIT; diff --git a/gdb/symtab.c b/gdb/symtab.c index e6e001bcd2..b32eca18fa 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -405,12 +405,11 @@ iterate_over_some_symtabs (const char *name, gdb::function_view callback) { struct compunit_symtab *cust; - struct symtab *s; const char* base_name = lbasename (name); for (cust = first; cust != NULL && cust != after_last; cust = cust->next) { - ALL_COMPUNIT_FILETABS (cust, s) + for (symtab *s : compunit_filetabs (cust)) { if (compare_filenames_for_search (s->filename, name)) { @@ -3050,7 +3049,6 @@ struct symtab_and_line find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) { struct compunit_symtab *cust; - struct symtab *iter_s; struct linetable *l; int len; struct linetable_entry *item; @@ -3187,7 +3185,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) They all have the same apriori range, that we found was right; but they have different line tables. */ - ALL_COMPUNIT_FILETABS (cust, iter_s) + for (symtab *iter_s : compunit_filetabs (cust)) { /* Find the best line in this symtab. */ l = SYMTAB_LINETABLE (iter_s); @@ -3319,7 +3317,7 @@ find_pc_line_symtab (CORE_ADDR pc) If not found, return NULL. */ struct symtab * -find_line_symtab (struct symtab *symtab, int line, +find_line_symtab (struct symtab *sym_tab, int line, int *index, int *exact_match) { int exact = 0; /* Initialized here to avoid a compiler warning. */ @@ -3332,8 +3330,8 @@ find_line_symtab (struct symtab *symtab, int line, struct symtab *best_symtab; /* First try looking it up in the given symtab. */ - best_linetable = SYMTAB_LINETABLE (symtab); - best_symtab = symtab; + best_linetable = SYMTAB_LINETABLE (sym_tab); + best_symtab = sym_tab; best_index = find_line_common (best_linetable, line, &exact, 0); if (best_index < 0 || !exact) { @@ -3349,8 +3347,6 @@ find_line_symtab (struct symtab *symtab, int line, BEST_INDEX and BEST_LINETABLE identify the item for it. */ int best; - struct symtab *s; - if (best_index >= 0) best = best_linetable->item[best_index].line; else @@ -3360,7 +3356,7 @@ find_line_symtab (struct symtab *symtab, int line, { if (objfile->sf) objfile->sf->qf->expand_symtabs_with_fullname - (objfile, symtab_to_fullname (symtab)); + (objfile, symtab_to_fullname (sym_tab)); } struct objfile *objfile; @@ -3369,9 +3365,9 @@ find_line_symtab (struct symtab *symtab, int line, struct linetable *l; int ind; - if (FILENAME_CMP (symtab->filename, s->filename) != 0) + if (FILENAME_CMP (sym_tab->filename, s->filename) != 0) continue; - if (FILENAME_CMP (symtab_to_fullname (symtab), + if (FILENAME_CMP (symtab_to_fullname (sym_tab), symtab_to_fullname (s)) != 0) continue; l = SYMTAB_LINETABLE (s); @@ -4184,7 +4180,6 @@ output_partial_symbol_filename (const char *filename, const char *fullname, static void info_sources_command (const char *ignore, int from_tty) { - struct symtab *s; struct objfile *objfile; struct output_source_filename_data data; @@ -5586,7 +5581,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 symtab *s; struct objfile *objfile; size_t text_len = strlen (text); completion_list list; diff --git a/gdb/symtab.h b/gdb/symtab.h index c2d8a69cf9..7d97372de6 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -29,6 +29,7 @@ #include "common/enum-flags.h" #include "common/function-view.h" #include "common/gdb_optional.h" +#include "common/next-iterator.h" #include "completer.h" /* Opaque declarations. */ @@ -1485,10 +1486,16 @@ struct compunit_symtab #define COMPUNIT_CALL_SITE_HTAB(cust) ((cust)->call_site_htab) #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table) -/* Iterate over all file tables (struct symtab) within a compunit. */ +/* A range adapter to allowing iterating over all the file tables + within a compunit. */ -#define ALL_COMPUNIT_FILETABS(cu, s) \ - for ((s) = (cu) -> filetabs; (s) != NULL; (s) = (s) -> next) +struct compunit_filetabs : public next_adapter +{ + compunit_filetabs (struct compunit_symtab *cu) + : next_adapter (cu->filetabs) + { + } +}; /* Return the primary symtab of CUST. */ -- 2.34.1