[binutils-gdb] Avoid double-decoding in ada_add_global_exceptions

Tom Tromey tromey@sourceware.org
Thu Mar 6 14:28:47 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5393cfd07abcafad6f3a84dcd263f7248943ace6

commit 5393cfd07abcafad6f3a84dcd263f7248943ace6
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Feb 24 13:18:27 2025 -0700

    Avoid double-decoding in ada_add_global_exceptions
    
    I noticed that ada_add_global_exceptions calls ada_decode on
    'search_name' -- and then passes this to name_matches_regex, which
    also calls ada_decode.
    
    name_matches_regex is also used later, where the result of
    'natural_name ()' is passed to it -- but natural_name also calls
    ada_decode.
    
    So, I think the call to ada_decode in name_matches_regex is redundant.
    This patch removes it, and turns name_matches_regex into an inner
    function to avoid propagating its use.
    
    Note that, right now, the DWARF implementation of
    expand_symtabs_matching does not in fact pass an encoded name to this
    callback.  So, this code remains slightly (but currently harmlessly)
    wrong.  expand_symtabs_matching is fixed by another pending series of
    mine.

Diff:
---
 gdb/ada-lang.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1cfd8431c15..b7e24ef6b2c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12999,15 +12999,6 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
     }
 }
 
-/* Return true if NAME matches PREG or if PREG is NULL.  */
-
-static bool
-name_matches_regex (const char *name, compiled_regex *preg)
-{
-  return (preg == NULL
-	  || preg->exec (ada_decode (name).c_str (), 0, NULL, 0) == 0);
-}
-
 /* Add all exceptions defined globally whose name name match
    a regular expression, excluding standard exceptions.
 
@@ -13031,6 +13022,13 @@ static void
 ada_add_global_exceptions (compiled_regex *preg,
 			   std::vector<ada_exc_info> *exceptions)
 {
+  /* Return true if NAME matches PREG or if PREG is NULL.  */
+  auto name_matches_regex = [&] (const char *name)
+    {
+      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.  */
@@ -13039,7 +13037,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 			   [&] (const char *search_name)
 			   {
 			     std::string decoded = ada_decode (search_name);
-			     return name_matches_regex (decoded.c_str (), preg);
+			     return name_matches_regex (decoded.c_str ());
 			   },
 			   NULL,
 			   SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
@@ -13065,7 +13063,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 
 	      for (struct symbol *sym : block_iterator_range (b))
 		if (ada_is_non_standard_exception_sym (sym)
-		    && name_matches_regex (sym->natural_name (), preg))
+		    && name_matches_regex (sym->natural_name ()))
 		  {
 		    struct ada_exc_info info
 		      = {sym->print_name (), sym->value_address ()};


More information about the Gdb-cvs mailing list