From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 09/11] gdb: change objfile::map_symtabs_matching_filename to find_symtab_matching_filename
Date: Thu, 16 Apr 2026 16:16:19 -0400 [thread overview]
Message-ID: <20260416202408.422441-10-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260416202408.422441-1-simon.marchi@efficios.com>
The only user of objfile::map_symtabs_matching_filename uses that method
to find the first matching symtab. It would therefore be more natural
for that method to be a "find" method, returning the first symtab
matching the predicate.
Change map_symtabs_matching_filename to be
find_symtab_in_compunit_symtab, and the internal
iterate_over_one_compunit_symtab to be find_symtab_in_compunit_symtab.
This makes function find_symtab simpler.
Change-Id: Id14a95498fad243495d6eab18810d0c4ab8dbf90
---
gdb/objfiles.h | 16 +++-----
gdb/symfile-debug.c | 89 +++++++++++++++++++++------------------------
gdb/symtab.c | 20 ++--------
3 files changed, 52 insertions(+), 73 deletions(-)
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 8ae54b37bb79..76d6130f5048 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -571,21 +571,17 @@ struct objfile : intrusive_list_node<objfile>
/* See quick_symbol_functions. */
void forget_cached_source_info ();
- /* Expand and iterate over each "partial" symbol table in OBJFILE
- where the source file is named NAME.
+ /* Find the first symtab where the source file matches NAME and REAL_PATH,
+ and for which CALLBACK returns true.
If NAME is not absolute, a match after a '/' in the symbol table's
file name will also work, REAL_PATH is NULL then. If NAME is
absolute then REAL_PATH is non-NULL absolute file name as resolved
- via gdb_realpath from NAME.
+ via gdb_realpath from NAME. */
- If a match is found, the "partial" symbol table is expanded.
- Then, this calls iterate_over_some_symtabs (or equivalent) over
- all newly-created symbol tables, passing CALLBACK to it.
- The result of this call is returned. */
- iteration_status map_symtabs_matching_filename
- (const char *name, const char *real_path,
- gdb::function_view<iteration_status (symtab *)> callback);
+ symtab *find_symtab_matching_filename (const char *name,
+ const char *real_path,
+ find_symtab_callback_ftype callback);
/* Check to see if the symbol is defined in a "partial" symbol table
of this objfile. BLOCK_INDEX should be either GLOBAL_BLOCK or
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 8e4892649508..d90f400f379c 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -159,29 +159,30 @@ objfile::forget_cached_source_info ()
iter->forget_cached_source_info (this);
}
-/* Check for a symtab of a specific name by searching some symtabs.
+/* Find the first symtab of CUST matching BASE_NAME, NAME and REAL_PATH, for
+ which CALLBACK returns true.
If NAME is not absolute, then REAL_PATH is NULL
If NAME is absolute, then REAL_PATH is the gdb_realpath form of NAME.
The return value, NAME, REAL_PATH and CALLBACK are identical to the
- `map_symtabs_matching_filename' method of quick_symbol_functions.
+ `find_symtab_matching_filename' method of quick_symbol_functions.
CUST indicates which compunit symtab to search. Each symtab within
the specified compunit symtab is also searched. */
-static iteration_status
-iterate_over_one_compunit_symtab
- (const char *base_name, const char *name, const char *real_path,
- compunit_symtab *cust,
- gdb::function_view<iteration_status (symtab *)> callback)
+static symtab *
+find_symtab_in_compunit_symtab (const char *base_name, const char *name,
+ const char *real_path, compunit_symtab *cust,
+ find_symtab_callback_ftype callback)
{
for (symtab *s : cust->filetabs ())
{
if (compare_filenames_for_search (s->filename (), name))
{
- if (callback (s) == iteration_status::stop)
- return iteration_status::stop;
+ if (callback (s))
+ return s;
+
continue;
}
@@ -193,8 +194,9 @@ iterate_over_one_compunit_symtab
if (compare_filenames_for_search (symtab_to_fullname (s), name))
{
- if (callback (s) == iteration_status::stop)
- return iteration_status::stop;
+ if (callback (s))
+ return s;
+
continue;
}
@@ -211,30 +213,32 @@ iterate_over_one_compunit_symtab
fullname = fullname_real_path.get ();
if (FILENAME_CMP (real_path, fullname) == 0)
{
- if (callback (s) == iteration_status::stop)
- return iteration_status::stop;
+ if (callback (s))
+ return s;
+
continue;
}
}
}
for (compunit_symtab *iter : cust->includes)
- if (iterate_over_one_compunit_symtab (base_name, name, real_path, iter,
- callback)
- == iteration_status::stop)
- return iteration_status::stop;
+ if (symtab *result = find_symtab_in_compunit_symtab (base_name, name,
+ real_path, iter,
+ callback);
+ result != nullptr)
+ return result;
- return iteration_status::keep_going;
+ return nullptr;
}
-iteration_status
-objfile::map_symtabs_matching_filename
- (const char *name, const char *real_path,
- gdb::function_view<iteration_status (symtab *)> callback)
+symtab *
+objfile::find_symtab_matching_filename (const char *name,
+ const char *real_path,
+ find_symtab_callback_ftype callback)
{
if (debug_symfile)
gdb_printf (gdb_stdlog,
- "qf->map_symtabs_matching_filename (%s, \"%s\", "
+ "qf->find_symtab_matching_filename (%s, \"%s\", "
"\"%s\", %s)\n",
objfile_debug_name (this), name,
real_path ? real_path : NULL,
@@ -254,6 +258,7 @@ objfile::map_symtabs_matching_filename
return false;
};
+ symtab *result = nullptr;
auto compunit_callback = [&] (compunit_symtab *symtab)
{
/* Skip included compunits, as they are searched by
@@ -261,37 +266,27 @@ objfile::map_symtabs_matching_filename
if (symtab->user != nullptr)
return iteration_status::keep_going;
- /* iterate_over_one_compunit_symtab returns true to stop,
- convert to iteration_status. */
- if (iterate_over_one_compunit_symtab (name_basename, name, real_path,
- symtab, callback)
- == iteration_status::stop)
+ result = find_symtab_in_compunit_symtab (name_basename, name, real_path,
+ symtab, callback);
+ if (result == nullptr)
+ return iteration_status::keep_going;
+ else
return iteration_status::stop;
-
- return iteration_status::keep_going;
};
- iteration_status retval = iteration_status::keep_going;
-
for (const auto &iter : qf)
- {
- if (iter->search (this, match_one_filename, nullptr, nullptr,
- compunit_callback,
- SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
- SEARCH_ALL_DOMAINS)
- == iteration_status::stop)
- {
- retval = iteration_status::stop;
- break;
- }
- }
+ if (iter->search (this, match_one_filename, nullptr, nullptr,
+ compunit_callback,
+ SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+ SEARCH_ALL_DOMAINS)
+ == iteration_status::stop)
+ break;
if (debug_symfile)
- gdb_printf (gdb_stdlog,
- "qf->map_symtabs_matching_filename (...) = %s\n",
- iteration_status_str (retval));
+ gdb_printf (gdb_stdlog, "qf->find_symtab_matching_filename (...) = %p\n",
+ result);
- return retval;
+ return result;
}
struct compunit_symtab *
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 6a5c8c7058e4..fd841318387e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -637,8 +637,6 @@ static symtab *
find_symtab (program_space *pspace, const char *name,
find_symtab_callback_ftype callback)
{
- struct symtab *result = NULL;
-
gdb::unique_xmalloc_ptr<char> real_path;
/* Here we are interested in canonicalizing an absolute path, not
@@ -649,21 +647,11 @@ find_symtab (program_space *pspace, const char *name,
gdb_assert (IS_ABSOLUTE_PATH (real_path.get ()));
}
- auto map_callback = [&] (symtab *symtab)
- {
- if (callback (symtab))
- {
- result = symtab;
- return iteration_status::stop;
- }
-
- return iteration_status::keep_going;
- };
-
for (objfile &objfile : pspace->objfiles ())
- if (objfile.map_symtabs_matching_filename (name, real_path.get (),
- map_callback)
- == iteration_status::stop)
+ if (symtab *result
+ = objfile.find_symtab_matching_filename (name, real_path.get (),
+ callback);
+ result != nullptr)
return result;
return nullptr;
--
2.53.0
next prev parent reply other threads:[~2026-04-16 20:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 20:16 [PATCH 00/11] Readability improvements of some iteration functions Simon Marchi
2026-04-16 20:16 ` [PATCH 01/11] gdb/dwarf: remove unused file_match parameter from dwarf2_base_index_functions::search_one Simon Marchi
2026-04-17 11:11 ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 02/11] gdb: rename search_symtabs_expansion_listener -> compunit_symtab_iteration_callback Simon Marchi
2026-04-17 15:08 ` Simon Marchi
2026-04-17 17:17 ` Tom Tromey
2026-04-17 19:34 ` Simon Marchi
2026-04-16 20:16 ` [PATCH 03/11] gdb: introduce iteration_status enum, use it for search callbacks Simon Marchi
2026-04-17 11:01 ` Andrew Burgess
2026-04-17 14:33 ` Simon Marchi
2026-04-17 14:34 ` Tom Tromey
2026-04-16 20:16 ` [PATCH 04/11] gdb, gdbserver: make iterate_over_lwps_ftype a function_view Simon Marchi
2026-04-17 11:09 ` Andrew Burgess
2026-04-17 14:37 ` Simon Marchi
2026-04-16 20:16 ` [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp Simon Marchi
2026-04-17 11:25 ` Andrew Burgess
2026-04-17 14:53 ` Simon Marchi
2026-04-16 20:16 ` [PATCH 06/11] gdb: split iterate_over_threads in for_each_thread and find_thread Simon Marchi
2026-04-17 11:33 ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 07/11] gdb: split iterate_over_minimal_symbols in for_each_minimal_symbol and find_minimal_symbol Simon Marchi
2026-04-17 12:13 ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 08/11] gdb: split iterate_over_symtabs in for_each_symtab and find_symtab Simon Marchi
2026-04-17 13:31 ` Andrew Burgess
2026-04-17 14:54 ` Simon Marchi
2026-04-16 20:16 ` Simon Marchi [this message]
2026-04-17 13:50 ` [PATCH 09/11] gdb: change objfile::map_symtabs_matching_filename to find_symtab_matching_filename Andrew Burgess
2026-04-17 15:03 ` Simon Marchi
2026-04-16 20:16 ` [PATCH 10/11] gdb: make symbol_found_callback_ftype a function_view Simon Marchi
2026-04-17 13:55 ` Andrew Burgess
2026-04-17 15:04 ` Simon Marchi
2026-04-16 20:16 ` [PATCH 11/11] gdb: make iterate_over_symbols return void, rename to for_each_symbol Simon Marchi
2026-04-17 14:05 ` Andrew Burgess
2026-04-17 15:06 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260416202408.422441-10-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox