[13/28] Convert gdbpy_lookup_static_symbols

Message ID 20250311-search-in-psyms-v1-13-d73d9be20983@tromey.com
State New
Headers
Series Search symbols via quick API |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey March 11, 2025, 2:12 p.m. UTC
  This changes gdbpy_lookup_static_symbols 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/python/py-symbol.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 3ce104984b4443f543678e2672fdf250b14fa070..5068766faccc39ee6fc40eb40f66708c4390dbd3 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -622,17 +622,17 @@  gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 
       /* Expand any symtabs that contain potentially matching symbols.  */
       lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-      expand_symtabs_matching (NULL, lookup_name, NULL, NULL,
-			       SEARCH_STATIC_BLOCK, flags);
 
       for (objfile *objfile : current_program_space->objfiles ())
 	{
-	  for (compunit_symtab *cust : objfile->compunits ())
+	  bool error_found = false;
+
+	  auto callback = [&] (compunit_symtab *cust)
 	    {
 	      /* Skip included compunits to prevent including compunits from
 		 being searched twice.  */
 	      if (cust->user != nullptr)
-		continue;
+		return true;
 
 	      const struct blockvector *bv = cust->blockvector ();
 	      const struct block *block = bv->static_block ();
@@ -645,13 +645,24 @@  gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 		  if (symbol != nullptr)
 		    {
 		      PyObject *sym_obj = symbol_to_symbol_object (symbol);
-		      if (sym_obj == nullptr)
-			return nullptr;
-		      if (PyList_Append (return_list.get (), sym_obj) == -1)
-			return nullptr;
+		      if (sym_obj == nullptr
+			  || PyList_Append (return_list.get (), sym_obj) == -1)
+			{
+			  error_found = true;
+			  return false;
+			}
 		    }
 		}
-	    }
+
+	      return true;
+	    };
+
+	  objfile->expand_symtabs_matching
+	    (nullptr, &lookup_name, nullptr, callback,
+	     SEARCH_STATIC_BLOCK, flags);
+
+	  if (error_found)
+	    return nullptr;
 	}
     }
   catch (const gdb_exception &except)