[binutils-gdb] Return references from compunit_symtab iterator
Tom Tromey
tromey@sourceware.org
Sat Oct 11 19:52:52 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=906678d08ed6bc72dac49d943518781bed4916bd
commit 906678d08ed6bc72dac49d943518781bed4916bd
Author: Tom Tromey <tom@tromey.com>
Date: Wed Oct 8 17:29:34 2025 -0600
Return references from compunit_symtab iterator
This changes the compunit_symtab iterator to return references rather
than pointers, following the style of some other recent changes.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diff:
---
gdb/ada-lang.c | 4 ++--
gdb/coffread.c | 4 ++--
gdb/maint.c | 8 ++++----
gdb/objfiles.c | 4 ++--
gdb/objfiles.h | 3 +--
gdb/source.c | 4 ++--
gdb/symfile-debug.c | 4 ++--
gdb/symmisc.c | 52 ++++++++++++++++++++++++++--------------------------
gdb/symtab.c | 34 +++++++++++++++++-----------------
9 files changed, 58 insertions(+), 59 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index ac6270d54f0..4d363e643bb 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5588,10 +5588,10 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
{
map_matching_symbols (&objfile, lookup_name, domain, global, data);
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
const struct block *global_block
- = cu->blockvector ()->global_block ();
+ = cu.blockvector ()->global_block ();
if (ada_add_block_renamings (result, global_block, lookup_name,
domain))
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 44e761abe89..0a3be97c8d8 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1256,9 +1256,9 @@ 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"). */
{
- for (compunit_symtab *cu : objfile->compunits ())
+ for (compunit_symtab &cu : objfile->compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
patch_opaque_types (s);
}
}
diff --git a/gdb/maint.c b/gdb/maint.c
index 576582925c6..84847939a62 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -972,12 +972,12 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
{
for (objfile &o : current_program_space->objfiles ())
{
- for (compunit_symtab *cu : o.compunits ())
+ for (compunit_symtab &cu : o.compunits ())
{
++nr_compunit_symtabs;
- nr_blocks += cu->blockvector ()->num_blocks ();
- nr_symtabs += std::distance (cu->filetabs ().begin (),
- cu->filetabs ().end ());
+ nr_blocks += cu.blockvector ()->num_blocks ();
+ nr_symtabs += std::distance (cu.filetabs ().begin (),
+ cu.filetabs ().end ());
}
}
}
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 482e12e717f..bc909db7d0e 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -548,9 +548,9 @@ objfile_relocate1 (struct objfile *objfile,
return 0;
/* OK, get all the symtabs. */
- for (compunit_symtab *cust : objfile->compunits ())
+ for (compunit_symtab &cust : objfile->compunits ())
{
- struct blockvector *bv = cust->blockvector ();
+ struct blockvector *bv = cust.blockvector ();
int block_line_section = SECT_OFF_TEXT (objfile);
if (bv->map () != nullptr)
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 0f9c7709d06..9566acfe33b 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -34,7 +34,6 @@
#include <forward_list>
#include "gdbsupport/unordered_map.h"
#include "gdbsupport/owning_intrusive_list.h"
-#include "gdbsupport/reference-to-pointer-iterator.h"
struct htab;
struct objfile_data;
@@ -474,7 +473,7 @@ public:
program_space *pspace () { return m_pspace; }
using compunit_symtab_iterator
- = reference_to_pointer_iterator<owning_intrusive_list<compunit_symtab>::iterator>;
+ = owning_intrusive_list<compunit_symtab>::iterator;
using compunit_symtab_range = iterator_range<compunit_symtab_iterator>;
/* A range adapter that makes it possible to iterate over all
diff --git a/gdb/source.c b/gdb/source.c
index aaafa1cf788..1018d2ce6be 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -356,9 +356,9 @@ select_source_symtab ()
for (objfile &ofp : current_program_space->objfiles ())
{
- for (compunit_symtab *cu : ofp.compunits ())
+ for (compunit_symtab &cu : ofp.compunits ())
{
- for (symtab *symtab : cu->filetabs ())
+ for (symtab *symtab : cu.filetabs ())
{
const char *name = symtab->filename;
int len = strlen (name);
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 55e8a5e2a59..b402a87b7a7 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -152,8 +152,8 @@ objfile::forget_cached_source_info ()
gdb_printf (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
objfile_debug_name (this));
- for (compunit_symtab *cu : compunits ())
- cu->forget_cached_source_info ();
+ for (compunit_symtab &cu : compunits ())
+ cu.forget_cached_source_info ();
for (const auto &iter : qf)
iter->forget_cached_source_info (this);
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index f031d00a77e..2ad3620c9f2 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -73,9 +73,9 @@ print_objfile_statistics (void)
OBJSTAT ((&objfile), n_types));
i = linetables = 0;
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
{
i++;
if (s->linetable () != NULL)
@@ -123,7 +123,7 @@ dump_objfile (struct objfile *objfile)
objfile->dump ();
bool symtabs_printed = false;
- for (compunit_symtab *cu : objfile->compunits ())
+ for (compunit_symtab &cu : objfile->compunits ())
{
if (!symtabs_printed)
{
@@ -131,7 +131,7 @@ dump_objfile (struct objfile *objfile)
symtabs_printed = true;
}
- for (symtab *symtab : cu->filetabs ())
+ for (symtab *symtab : cu.filetabs ())
{
gdb_printf ("%s at %s",
symtab_to_filename_for_display (symtab),
@@ -468,9 +468,9 @@ maintenance_print_symbols (const char *args, int from_tty)
if (!print_for_objfile)
continue;
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
{
int print_for_source = 0;
@@ -751,11 +751,11 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
actually find a symtab whose name matches. */
int printed_objfile_start = 0;
- for (compunit_symtab *cust : objfile.compunits ())
+ for (compunit_symtab &cust : objfile.compunits ())
{
int printed_compunit_symtab_start = 0;
- for (symtab *symtab : cust->filetabs ())
+ for (symtab *symtab : cust.filetabs ())
{
QUIT;
@@ -773,32 +773,32 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
if (! printed_compunit_symtab_start)
{
gdb_printf (" { ((struct compunit_symtab *) %s)\n",
- host_address_to_string (cust));
+ host_address_to_string (&cust));
gdb_printf (" debugformat %s\n",
- cust->debugformat ());
+ cust.debugformat ());
gdb_printf (" producer %s\n",
- (cust->producer () != nullptr
- ? cust->producer () : "(null)"));
- gdb_printf (" name %s\n", cust->name);
+ (cust.producer () != nullptr
+ ? cust.producer () : "(null)"));
+ gdb_printf (" name %s\n", cust.name);
gdb_printf (" dirname %s\n",
- (cust->dirname () != NULL
- ? cust->dirname () : "(null)"));
+ (cust.dirname () != NULL
+ ? cust.dirname () : "(null)"));
gdb_printf (" blockvector"
" ((struct blockvector *) %s)\n",
host_address_to_string
- (cust->blockvector ()));
+ (cust.blockvector ()));
gdb_printf (" user"
" ((struct compunit_symtab *) %s)\n",
- cust->user != nullptr
- ? host_address_to_string (cust->user)
+ cust.user != nullptr
+ ? host_address_to_string (cust.user)
: "(null)");
- if (cust->includes != nullptr)
+ if (cust.includes != nullptr)
{
gdb_printf (" ( includes\n");
for (int i = 0; ; ++i)
{
struct compunit_symtab *include
- = cust->includes[i];
+ = cust.includes[i];
if (include == nullptr)
break;
const char *addr
@@ -856,14 +856,14 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
actually find something worth printing. */
int printed_objfile_start = 0;
- for (compunit_symtab *cust : objfile.compunits ())
+ for (compunit_symtab &cust : objfile.compunits ())
{
int found_something = 0;
- struct symtab *symtab = cust->primary_filetab ();
+ struct symtab *symtab = cust.primary_filetab ();
QUIT;
- if (cust->blockvector () == NULL)
+ if (cust.blockvector () == NULL)
found_something = 1;
/* Add more checks here. */
@@ -879,7 +879,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
}
gdb_printf (" { symtab %s\n",
symtab_to_filename_for_display (symtab));
- if (cust->blockvector () == NULL)
+ if (cust.blockvector () == NULL)
gdb_printf (" NULL blockvector\n");
gdb_printf (" }\n");
}
@@ -1036,9 +1036,9 @@ maintenance_info_line_tables (const char *regexp, int from_tty)
for (struct program_space *pspace : program_spaces)
for (objfile &objfile : pspace->objfiles ())
{
- for (compunit_symtab *cust : objfile.compunits ())
+ for (compunit_symtab &cust : objfile.compunits ())
{
- for (symtab *symtab : cust->filetabs ())
+ for (symtab *symtab : cust.filetabs ())
{
QUIT;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e24b31c528d..d4089c87792 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2251,14 +2251,14 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
best_symbol_tracker accum;
- for (compunit_symtab *cust : objfile->compunits ())
+ for (compunit_symtab &cust : objfile->compunits ())
{
const struct blockvector *bv;
const struct block *block;
- bv = cust->blockvector ();
+ bv = cust.blockvector ();
block = bv->block (block_index);
- if (accum.search (cust, block, lookup_name, domain))
+ if (accum.search (&cust, block, lookup_name, domain))
break;
}
@@ -2738,9 +2738,9 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
for (objfile &obj_file : current_program_space->objfiles ())
{
- for (compunit_symtab *cust : obj_file.compunits ())
+ for (compunit_symtab &cust : obj_file.compunits ())
{
- const struct blockvector *bv = cust->blockvector ();
+ const struct blockvector *bv = cust.blockvector ();
const struct block *global_block = bv->global_block ();
CORE_ADDR start = global_block->start ();
CORE_ADDR end = global_block->end ();
@@ -2753,7 +2753,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
if (bv->map ()->find (pc) == nullptr)
continue;
- return cust;
+ return &cust;
}
CORE_ADDR range = end - start;
@@ -2799,7 +2799,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
}
/* Cust is best found so far, save it. */
- best_cust = cust;
+ best_cust = &cust;
best_cust_range = range;
}
}
@@ -2861,9 +2861,9 @@ find_symbol_at_address (CORE_ADDR address)
search the symtabs directly. */
if ((objfile.flags & OBJF_READNOW) != 0)
{
- for (compunit_symtab *symtab : objfile.compunits ())
+ for (compunit_symtab &symtab : objfile.compunits ())
{
- struct symbol *sym = search_symtab (symtab, address);
+ struct symbol *sym = search_symtab (&symtab, address);
if (sym != nullptr)
return sym;
}
@@ -3303,9 +3303,9 @@ find_line_symtab (symtab *sym_tab, int line, int *index)
for (objfile &objfile : current_program_space->objfiles ())
{
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
{
const struct linetable *l;
int ind;
@@ -4537,9 +4537,9 @@ info_sources_worker (struct ui_out *uiout,
sources_list.emplace (uiout, "sources");
}
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
{
const char *file = symtab_to_filename_for_display (s);
const char *fullname = symtab_to_fullname (s);
@@ -4790,9 +4790,9 @@ global_symbol_searcher::add_matching_symbols
domain_search_flags kind = m_kind;
/* Add matching symbols (if not already present). */
- for (compunit_symtab *cust : objfile->compunits ())
+ for (compunit_symtab &cust : objfile->compunits ())
{
- const struct blockvector *bv = cust->blockvector ();
+ const struct blockvector *bv = cust.blockvector ();
for (block_enum block : { GLOBAL_BLOCK, STATIC_BLOCK })
{
@@ -6221,9 +6221,9 @@ make_source_files_completion_list (const char *text)
for (objfile &objfile : current_program_space->objfiles ())
{
- for (compunit_symtab *cu : objfile.compunits ())
+ for (compunit_symtab &cu : objfile.compunits ())
{
- for (symtab *s : cu->filetabs ())
+ for (symtab *s : cu.filetabs ())
{
if (not_interesting_fname (s->filename))
continue;
More information about the Gdb-cvs
mailing list