This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 06/12] Remove ALL_OBJFILE_COMPUNITS
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Sun, 25 Nov 2018 09:54:33 -0700
- Subject: [PATCH 06/12] Remove ALL_OBJFILE_COMPUNITS
- References: <20181125165439.13773-1-tom@tromey.com>
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
2018-11-25 Tom Tromey <tom@tromey.com>
* 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/ada-lang.c b/gdb/ada-lang.c
index 0520ec144a..1a1db17421 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5603,7 +5603,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);
@@ -5628,7 +5627,7 @@ add_nonlocal_symbols (struct obstack *obstackp,
symbol_name_match_type::FULL,
compare_names);
- ALL_OBJFILE_COMPUNITS (objfile, cu)
+ for (struct compunit_symtab *cu : objfile_compunits (objfile))
{
const struct block *global_block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu), GLOBAL_BLOCK);
@@ -6389,7 +6388,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;
@@ -13547,7 +13545,6 @@ ada_add_global_exceptions (compiled_regex *preg,
std::vector<ada_exc_info> *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 401aacbbe2..81d00b5248 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1201,7 +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 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 184d637da6..e976354f1f 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1374,7 +1374,6 @@ static void
add_symbol_overload_list_qualified (const char *func_name,
std::vector<symbol *> *overload_list)
{
- struct compunit_symtab *cust;
struct objfile *objfile;
const struct block *b, *surrounding_static_block = 0;
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8e0fb866e8..b641c22a03 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1138,8 +1138,6 @@ iterate_over_all_matching_symtabs
for (struct objfile *objfile : all_objfiles (current_program_space))
{
- struct compunit_symtab *cu;
-
if (objfile->sf)
objfile->sf->qf->expand_symtabs_matching (objfile,
NULL,
@@ -1147,7 +1145,7 @@ iterate_over_all_matching_symtabs
NULL, NULL,
search_domain);
- ALL_OBJFILE_COMPUNITS (objfile, cu)
+ for (struct compunit_symtab *cu : objfile_compunits (objfile))
{
struct symtab *symtab = COMPUNIT_FILETABS (cu);
diff --git a/gdb/maint.c b/gdb/maint.c
index 5a4aa83eaf..56fbf3cfba 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 6e40e5d736..bbf3ed30ac 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 19047694af..abfe425358 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 (struct 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 b24145f0ca..916d80f571 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 (struct 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<struct compunit_symtab>
+{
+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<struct compunit_symtab> (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 (struct 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 bef4ffe0ad..81be5f5f60 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -244,7 +244,6 @@ void
select_source_symtab (struct symtab *s)
{
struct objfile *ofp;
- struct compunit_symtab *cu;
if (s)
{
@@ -356,7 +355,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 ebad334d6c..60aef3c8bb 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 (struct 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 (struct 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 (struct 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 (struct 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 (struct objfile *objfile : all_objfiles (pspace))
{
- struct compunit_symtab *cust;
struct symtab *symtab;
- ALL_OBJFILE_COMPUNITS (objfile, cust)
+ for (struct compunit_symtab *cust : objfile_compunits (objfile))
{
ALL_COMPUNIT_FILETABS (cust, symtab)
{
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 73ab0cb0b7..49dd30235c 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 (struct 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 (struct 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 *objfile;
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;
@@ -5196,7 +5188,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;
@@ -5580,7 +5571,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.17.2