From patchwork Sun Nov 25 16:54:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30283 Received: (qmail 92945 invoked by alias); 25 Nov 2018 16:54:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92759 invoked by uid 89); 25 Nov 2018 16:54:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Find, opaque, source.c, UD:source.c X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.119) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 25 Nov 2018 16:54:46 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 48E5C14A94 for ; Sun, 25 Nov 2018 10:54:45 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id QxgDgkMvOkBj6QxgDghD0I; Sun, 25 Nov 2018 10:54:45 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VbH4I2HJOcR7p4PNFNOTAIroDoYGkKWfQ/MEVOSI8iM=; b=eQwAe4D8+PeYrnnGGarr4B+rzX xoWcIfJFkm3Voj1bTHf3A9ircFkFVEeC8SzxcDA08PpjvjKh2La4ixNV4SdE5Igitl+BNQQ/fE9ne 5ZUU2p4Fdn0n+Ji/llyMOzojs; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:51592 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gQxgD-0013GF-1U; Sun, 25 Nov 2018 10:54:45 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 08/12] Remove ALL_COMPUNIT_FILETABS Date: Sun, 25 Nov 2018 09:54:35 -0700 Message-Id: <20181125165439.13773-9-tom@tromey.com> In-Reply-To: <20181125165439.13773-1-tom@tromey.com> References: <20181125165439.13773-1-tom@tromey.com> 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 2018-11-25 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 | 10 ++-------- gdb/symtab.h | 13 ++++++++++--- 11 files changed, 46 insertions(+), 39 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index a9d2698584..5de2883f4e 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 (struct 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 81d00b5248..82e6767ae1 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1201,8 +1201,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 5cd5b01936..df4bf444ff 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; @@ -777,8 +776,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 bbf3ed30ac..a74846e21b 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 abfe425358..3429fdc9d8 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 165a6e3cf1..4bbe7ea613 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -616,7 +616,7 @@ public: #define ALL_OBJFILE_FILETABS(objfile, cu, s) \ for (struct compunit_symtab *cu : objfile_compunits (objfile)) \ - ALL_COMPUNIT_FILETABS (cu, s) + for (struct 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 81be5f5f60..65b9bf554d 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -276,16 +276,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; } } @@ -355,8 +355,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 60aef3c8bb..e9ab1c95b8 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 (struct objfile *objfile : all_objfiles (current_program_space)) @@ -772,8 +768,6 @@ maintenance_info_symtabs (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (struct 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 (struct symtab *symtab : compunit_filetabs (cust)) { QUIT; @@ -1026,11 +1020,9 @@ maintenance_info_line_tables (const char *regexp, int from_tty) ALL_PSPACES (pspace) for (struct objfile *objfile : all_objfiles (pspace)) { - struct symtab *symtab; - for (struct compunit_symtab *cust : objfile_compunits (objfile)) { - ALL_COMPUNIT_FILETABS (cust, symtab) + for (struct symtab *symtab : compunit_filetabs (cust)) { QUIT; diff --git a/gdb/symtab.c b/gdb/symtab.c index 86fa99b057..c16fc307ad 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 (struct symtab *s : compunit_filetabs (cust)) { if (compare_filenames_for_search (s->filename, name)) { @@ -3044,7 +3043,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; @@ -3181,7 +3179,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 (struct symtab *iter_s : compunit_filetabs (cust)) { /* Find the best line in this symtab. */ l = SYMTAB_LINETABLE (iter_s); @@ -3343,8 +3341,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 @@ -4178,7 +4174,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; @@ -5568,7 +5563,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 e0b870135b..8383addeec 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. */