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>
This commit is contained in:
Tom Tromey
2025-10-08 17:29:34 -06:00
parent 61a98786bf
commit 906678d08e
9 changed files with 58 additions and 59 deletions

View File

@@ -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))

View File

@@ -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);
}
}

View File

@@ -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 ());
}
}
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;