]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert gdbpy_lookup_static_symbols
authorTom Tromey <tom@tromey.com>
Thu, 19 Dec 2024 00:26:16 +0000 (17:26 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 10 Sep 2025 22:05:28 +0000 (16:05 -0600)
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
Acked-By: Simon Marchi <simon.marchi@efficios.com>
gdb/python/py-symbol.c

index 69062f2e5462e2d0be66d2af396ae6feec0b5160..7feab1f6761c17757f0ddb8a4f2a2f6f2964fb7e 100644 (file)
@@ -602,17 +602,15 @@ 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 ())
+         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 ();
@@ -625,13 +623,19 @@ 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)
+                       return false;
                    }
                }
-           }
+
+             return true;
+           };
+
+         if (!objfile->expand_symtabs_matching
+             (nullptr, &lookup_name, nullptr, callback,
+              SEARCH_STATIC_BLOCK, flags))
+           return nullptr;
        }
     }
   catch (const gdb_exception &except)