[PATCH v2 14/28] Convert ada_add_global_exceptions

Tom Tromey
2025-04-03T00:04:46Z

This converts ada_add_global_exceptions 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/ada-lang.c | 49 ++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4bb6a808fd8c1a7f8e4b2344fdf935f94c602ed1..0a20bfb8c68666326b92a6b9298df09dedcf845c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13098,32 +13098,12 @@ ada_add_global_exceptions (compiled_regex *preg,
return preg == nullptr || preg->exec (name, 0, NULL, 0) == 0;
};

-
- /* In Ada, the symbol "search name" is a linkage name, whereas the
- regular expression used to do the matching refers to the natural
- name. So match against the decoded name. */
- expand_symtabs_matching (NULL,
- lookup_name_info::match_any (),
- [&] (const char *search_name)
- {
- std::string decoded = ada_decode (search_name);
- return name_matches_regex (decoded.c_str ());
- },
- NULL,
- SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
- SEARCH_VAR_DOMAIN,
- [&] (enum language lang)
- {
- /* Try to skip non-Ada CUs. */
- return lang == language_ada;
- });
-
/* Iterate over all objfiles irrespective of scope or linker namespaces
so we get all exceptions anywhere in the progspace. */
for (objfile *objfile : current_program_space->objfiles ())
{
- for (compunit_symtab *s : objfile->compunits ())
- {
+ auto callback = [&] (compunit_symtab *s)
+ {
const struct blockvector *bv = s->blockvector ();
int i;

@@ -13141,7 +13121,30 @@ ada_add_global_exceptions (compiled_regex *preg,
exceptions->push_back (info);
}
}
- }
+
+ return true;
+ };
+
+ /* In Ada, the symbol "search name" is a linkage name, whereas
+ the regular expression used to do the matching refers to the
+ natural name. So match against the decoded name. */
+ auto any = lookup_name_info::match_any ();
+ objfile->expand_symtabs_matching
+ (nullptr,
+ &any,
+ [&] (const char *search_name)
+ {
+ std::string decoded = ada_decode (search_name);
+ return name_matches_regex (decoded.c_str ());
+ },
+ callback,
+ SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+ SEARCH_VAR_DOMAIN,
+ [&] (enum language lang)
+ {
+ /* Try to skip non-Ada CUs. */
+ return lang == language_ada;
+ });
}
}

--
2.46.1