From fe2830c31ceb85ef14389c5d640d33f5ac5a89b0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 27 Sep 2025 15:11:13 -0600 Subject: [PATCH] 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 --- gdb/progspace.c | 10 ++++++++++ gdb/progspace.h | 7 +++++++ gdb/symfile.c | 11 ----------- gdb/symfile.h | 2 -- gdb/symtab.c | 5 +++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/gdb/progspace.c b/gdb/progspace.c index 6ee0134f20b..4017d0f4f27 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -160,6 +160,16 @@ program_space::iterate_over_objfiles_in_search_order /* 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 program_space::add_objfile (std::unique_ptr &&objfile, struct objfile *before) diff --git a/gdb/progspace.h b/gdb/progspace.h index 1cf60420f73..498a5b460f1 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -24,6 +24,7 @@ #include "solib.h" #include "target.h" #include "gdb_bfd.h" +#include "quick-symbol.h" #include "registry.h" #include "gdbsupport/safe-iterator.h" #include "gdbsupport/intrusive_list.h" @@ -224,6 +225,12 @@ struct program_space (iterate_over_objfiles_in_search_order_cb_ftype cb, 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 BEFORE. If BEFORE is nullptr, it will go at the end of the list. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 2a687c01ab4..b15782ea9de 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3755,17 +3755,6 @@ symfile_free_objfile (struct objfile *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 namespace selftests { diff --git a/gdb/symfile.h b/gdb/symfile.h index 06509a61d03..7e7de3800d8 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -345,8 +345,6 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd); extern scoped_restore_tmpl 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. ARGS should be in the form "EXECUTABLE [OFFSET]", where OFFSET is an diff --git a/gdb/symtab.c b/gdb/symtab.c index aef4842a7af..05a1fd0ba68 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4630,7 +4630,8 @@ info_sources_worker (struct ui_out *uiout, if (!group_by_objfile) { 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.text_len = text_len; datum.list = &list; - map_symbol_filenames (datum, false /*need_fullname*/); + current_program_space->map_symbol_filenames (datum, false /*need_fullname*/); return list; } -- 2.47.3