Convert map_symbol_filenames to method

This patch changes the free function map_symbol_filenames to be a
method of program_space.  This seems a bit cleaner, and also lets us
hoist a use of the global into the callers.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
This commit is contained in:
Tom Tromey
2025-09-27 15:11:13 -06:00
parent db6830694b
commit fe2830c31c
5 changed files with 20 additions and 15 deletions

View File

@@ -160,6 +160,16 @@ program_space::iterate_over_objfiles_in_search_order
/* See progspace.h. */ /* See progspace.h. */
void
program_space::map_symbol_filenames (symbol_filename_listener fun,
bool need_fullname)
{
for (objfile &objfile : objfiles ())
objfile.map_symbol_filenames (fun, need_fullname);
}
/* See progspace.h. */
void void
program_space::add_objfile (std::unique_ptr<objfile> &&objfile, program_space::add_objfile (std::unique_ptr<objfile> &&objfile,
struct objfile *before) struct objfile *before)

View File

@@ -24,6 +24,7 @@
#include "solib.h" #include "solib.h"
#include "target.h" #include "target.h"
#include "gdb_bfd.h" #include "gdb_bfd.h"
#include "quick-symbol.h"
#include "registry.h" #include "registry.h"
#include "gdbsupport/safe-iterator.h" #include "gdbsupport/safe-iterator.h"
#include "gdbsupport/intrusive_list.h" #include "gdbsupport/intrusive_list.h"
@@ -224,6 +225,12 @@ struct program_space
(iterate_over_objfiles_in_search_order_cb_ftype cb, (iterate_over_objfiles_in_search_order_cb_ftype cb,
objfile *current_objfile); objfile *current_objfile);
/* Wrapper around the quick_symbol_functions map_symbol_filenames
"method". Map function FUN over every file, in every objfile in
this program space. See
quick_symbol_functions.map_symbol_filenames for details. */
void map_symbol_filenames (symbol_filename_listener fun, bool need_fullname);
/* Add OBJFILE to the list of objfiles, putting it just before /* Add OBJFILE to the list of objfiles, putting it just before
BEFORE. If BEFORE is nullptr, it will go at the end of the BEFORE. If BEFORE is nullptr, it will go at the end of the
list. */ list. */

View File

@@ -3755,17 +3755,6 @@ symfile_free_objfile (struct objfile *objfile)
objfile->pspace ()->remove_target_sections (objfile); objfile->pspace ()->remove_target_sections (objfile);
} }
/* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
Map function FUN over every file.
See quick_symbol_functions.map_symbol_filenames for details. */
void
map_symbol_filenames (symbol_filename_listener fun, bool need_fullname)
{
for (objfile &objfile : current_program_space->objfiles ())
objfile.map_symbol_filenames (fun, need_fullname);
}
#if GDB_SELF_TEST #if GDB_SELF_TEST
namespace selftests { namespace selftests {

View File

@@ -345,8 +345,6 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
extern scoped_restore_tmpl<int> increment_reading_symtab (void); extern scoped_restore_tmpl<int> increment_reading_symtab (void);
void map_symbol_filenames (symbol_filename_listener fun, bool need_fullname);
/* Target-agnostic function to load the sections of an executable into memory. /* Target-agnostic function to load the sections of an executable into memory.
ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an

View File

@@ -4630,7 +4630,8 @@ info_sources_worker (struct ui_out *uiout,
if (!group_by_objfile) if (!group_by_objfile)
{ {
data.reset_output (); data.reset_output ();
map_symbol_filenames (data, true /*need_fullname*/); current_program_space->map_symbol_filenames (data,
true /*need_fullname*/);
} }
} }
@@ -6323,7 +6324,7 @@ make_source_files_completion_list (const char *text)
datum.word = text; datum.word = text;
datum.text_len = text_len; datum.text_len = text_len;
datum.list = &list; datum.list = &list;
map_symbol_filenames (datum, false /*need_fullname*/); current_program_space->map_symbol_filenames (datum, false /*need_fullname*/);
return list; return list;
} }