[PATCH v4 6/8] Have iterate_over_one_compunit_symtab search included symtabs

Tom Tromey
2026-02-24T01:17:53Z

A latent bug in the search-via-psyms series was that it neglected to
update iterate_over_one_compunit_symtab to search included symtabs.

I think lookups that needed this search used to work by accident -- an
included CU would be expanded but not searched, but a search of all
compunits() would then find it.

This patch corrects the oversight. I'm not sure if this bug is
readily visible without the next patch.
---
gdb/symfile-debug.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 6562dcad433..2c9deba20ae 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -171,17 +171,12 @@ objfile::forget_cached_source_info ()
the specified compunit symtab is also searched. */

static bool
-iterate_over_one_compunit_symtab (const char *name,
+iterate_over_one_compunit_symtab (const char *base_name,
+ const char *name,
const char *real_path,
compunit_symtab *cust,
gdb::function_view<bool (symtab *)> callback)
{
- const char *base_name = lbasename (name);
-
- /* Skip included compunits. */
- if (cust->user != nullptr)
- return false;
-
for (symtab *s : cust->filetabs ())
{
if (compare_filenames_for_search (s->filename (), name))
@@ -224,6 +219,11 @@ iterate_over_one_compunit_symtab (const char *name,
}
}

+ for (compunit_symtab *iter : cust->includes)
+ if (iterate_over_one_compunit_symtab (base_name, name, real_path,
+ iter, callback))
+ return true;
+
return false;
}

@@ -257,10 +257,15 @@ objfile::map_symtabs_matching_filename

auto listener = [&] (compunit_symtab *symtab)
{
+ /* Skip included compunits, as they are searched by
+ iterate_over_one_compunit_symtab. */
+ if (symtab->user != nullptr)
+ return true;
+
/* CALLBACK returns false to keep going and true to continue, so
we have to invert the result here, for search. */
- return !iterate_over_one_compunit_symtab (name, real_path, symtab,
- callback);
+ return !iterate_over_one_compunit_symtab (name_basename, name, real_path,
+ symtab, callback);
};

for (const auto &iter : qf)

--
2.49.0