[PATCH v2 20/28] Convert linespec.c:iterate_over_all_matching_symtabs

Tom Tromey
2025-04-02T23:58:34Z

This converts linespec.c:iterate_over_all_matching_symtabs to the
callback approach, merging the search loop and the call to
expand_symtabs_matching.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
---
gdb/linespec.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 5eef96c44e7dc283c3855690359fd718fe2c0a55..b500930b1feeb447aac81e45ba51439a021c4b48 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1134,12 +1134,7 @@ iterate_over_all_matching_symtabs

for (objfile *objfile : pspace->objfiles ())
{
- objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL,
- (SEARCH_GLOBAL_BLOCK
- | SEARCH_STATIC_BLOCK),
- domain);
-
- for (compunit_symtab *cu : objfile->compunits ())
+ auto expand_callback = [&] (compunit_symtab *cu)
{
struct symtab *symtab = cu->primary_filetab ();

@@ -1166,7 +1161,15 @@ iterate_over_all_matching_symtabs
});
}
}
- }
+
+ return true;
+ };
+
+ objfile->expand_symtabs_matching (nullptr, &lookup_name,
+ nullptr, expand_callback,
+ (SEARCH_GLOBAL_BLOCK
+ | SEARCH_STATIC_BLOCK),
+ domain);
}
}
}

--
2.46.1