[binutils-gdb] gdb: change some pointers to references in global_symbol_searcher

Simon Marchi simark@sourceware.org
Thu Oct 1 17:48:23 GMT 2026


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

commit ce85cf8f8073b99bfdaf2f2b542990a573724c88
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Wed Sep 30 22:09:27 2026 -0400

    gdb: change some pointers to references in global_symbol_searcher
    
    add_matching_symbols and add_matching_msymbols take the container to
    add results to as a pointer, but it can never be nullptr.  Pass it by
    reference instead.
    
    The objfiles are also passed by pointer to the various helper methods,
    switch that to references.
    
    Change-Id: I65d8e14f2f3152d83afbe3b348fc91a8817b87fa
    Approved-By: Andrew Burgess <aburgess@redhat.com>

Diff:
---
 gdb/symtab.c | 39 +++++++++++++++++++--------------------
 gdb/symtab.h | 10 +++++-----
 2 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index f738cf0dd0e..0758539d058 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4833,7 +4833,7 @@ global_symbol_searcher::msymbol_matches
 
 bool
 global_symbol_searcher::expand_symtabs
-	(objfile *objfile,
+	(objfile &objfile,
 	 const std::optional<compiled_regex> &name_regex) const
 {
   bool found_func_msymbol_without_debug_info = false;
@@ -4846,7 +4846,7 @@ global_symbol_searcher::expand_symtabs
   if (!m_filenames.empty ())
     file_matcher = do_file_match;
 
-  objfile->search
+  objfile.search
     (file_matcher,
      &lookup_name_info::match_any (),
      [&] (const char *symname)
@@ -4873,7 +4873,7 @@ global_symbol_searcher::expand_symtabs
   if (m_filenames.empty ()
       && m_kind == symbol_search_kind::FUNCTION)
     {
-      for (minimal_symbol *msymbol : objfile->msymbols ())
+      for (minimal_symbol *msymbol : objfile.msymbols ())
 	{
 	  QUIT;
 
@@ -4885,7 +4885,7 @@ global_symbol_searcher::expand_symtabs
 	     will add matching symbols or msymbols to the results list, and
 	     that requires that the symbols tables are expanded.  */
 	  if (find_compunit_symtab_for_pc
-		(msymbol->value_address (objfile)) == nullptr)
+		(msymbol->value_address (&objfile)) == nullptr)
 	    found_func_msymbol_without_debug_info = true;
 	}
     }
@@ -4897,13 +4897,13 @@ global_symbol_searcher::expand_symtabs
 
 bool
 global_symbol_searcher::add_matching_symbols
-	(objfile *objfile,
+	(objfile &objfile,
 	 const std::optional<compiled_regex> &name_regex,
 	 const std::optional<compiled_regex> &type_regex,
-	 std::set<symbol_search> *result_set) const
+	 std::set<symbol_search> &result_set) const
 {
   /* Add matching symbols (if not already present).  */
-  for (compunit_symtab &cust : objfile->compunits ())
+  for (compunit_symtab &cust : objfile.compunits ())
     {
       const struct blockvector *bv  = cust.blockvector ();
 
@@ -4919,8 +4919,8 @@ global_symbol_searcher::add_matching_symbols
 		continue;
 
 	      /* Match, insert if not already in the results.  */
-	      if (result_set->size () < m_max_search_results)
-		result_set->emplace (block, sym);
+	      if (result_set.size () < m_max_search_results)
+		result_set.emplace (block, sym);
 	      else
 		return false;
 	    }
@@ -4934,10 +4934,10 @@ global_symbol_searcher::add_matching_symbols
 
 bool
 global_symbol_searcher::add_matching_msymbols
-	(objfile *objfile, const std::optional<compiled_regex> &name_regex,
-	 std::vector<symbol_search> *results) const
+	(objfile &objfile, const std::optional<compiled_regex> &name_regex,
+	 std::vector<symbol_search> &results) const
 {
-  for (minimal_symbol *msymbol : objfile->msymbols ())
+  for (minimal_symbol *msymbol : objfile.msymbols ())
     {
       QUIT;
 
@@ -4948,16 +4948,16 @@ global_symbol_searcher::add_matching_msymbols
 	 symbol might be found via find_pc_symtab.  */
       if (m_kind == symbol_search_kind::FUNCTION
 	  && (find_compunit_symtab_for_pc
-	      (msymbol->value_address (objfile)) != nullptr))
+	      (msymbol->value_address (&objfile)) != nullptr))
 	continue;
 
       if (lookup_symbol_in_objfile_from_linkage_name
-	    (objfile, msymbol->linkage_name (), SEARCH_VFT).symbol != nullptr)
+	    (&objfile, msymbol->linkage_name (), SEARCH_VFT).symbol != nullptr)
 	continue;
 
       /* Matching msymbol, add it to the results list.  */
-      if (results->size () < m_max_search_results)
-	results->emplace_back (GLOBAL_BLOCK, msymbol, objfile);
+      if (results.size () < m_max_search_results)
+	results.emplace_back (GLOBAL_BLOCK, msymbol, &objfile);
       else
 	return false;
     }
@@ -5050,14 +5050,13 @@ global_symbol_searcher::search () const
       /* Expand symtabs within objfile that possibly contain matching
 	 symbols.  */
       found_func_msymbol_without_debug_info
-	|= expand_symtabs (&objfile, name_regex);
+	|= expand_symtabs (objfile, name_regex);
 
       /* Find matching symbols within OBJFILE and add them in to the
 	 RESULT_SET set.  Use a set here so that we can easily detect
 	 duplicates as we go, and can therefore track how many unique
 	 matches we have found so far.  */
-      if (!add_matching_symbols (&objfile, name_regex, type_regex,
-				 &result_set))
+      if (!add_matching_symbols (objfile, name_regex, type_regex, result_set))
 	break;
     }
 
@@ -5077,7 +5076,7 @@ global_symbol_searcher::search () const
       gdb_assert (m_kind == symbol_search_kind::VARIABLE
 		  || m_kind == symbol_search_kind::FUNCTION);
       for (objfile &objfile : current_program_space->objfiles ())
-	if (!add_matching_msymbols (&objfile, name_regex, &result))
+	if (!add_matching_msymbols (objfile, name_regex, result))
 	  break;
     }
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index cf629387a17..117d3fb0134 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2707,7 +2707,7 @@ private:
      Return true if a matching function msymbol without debug info was
      seen, meaning that msymbols should later be considered for the results
      list.  */
-  bool expand_symtabs (objfile *objfile,
+  bool expand_symtabs (objfile &objfile,
 		       const std::optional<compiled_regex> &name_regex) const;
 
   /* Add symbols from symtabs in OBJFILE that match NAME_REGEX, and
@@ -2717,10 +2717,10 @@ private:
      otherwise return true.
      Returning true does not indicate that any results were added, just
      that we didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS.  */
-  bool add_matching_symbols (objfile *objfile,
+  bool add_matching_symbols (objfile &objfile,
 			     const std::optional<compiled_regex> &name_regex,
 			     const std::optional<compiled_regex> &type_regex,
-			     std::set<symbol_search> *result_set) const;
+			     std::set<symbol_search> &result_set) const;
 
   /* Add msymbols from OBJFILE that match NAME_REGEX and M_KIND, to the
      results vector RESULTS.  Return false if we stop adding results early
@@ -2728,9 +2728,9 @@ private:
      results limit M_MAX_SEARCH_RESULTS), otherwise return true.  Returning
      true does not indicate that any results were added, just that we
      didn't _not_ add a result due to reaching MAX_SEARCH_RESULTS.  */
-  bool add_matching_msymbols (objfile *objfile,
+  bool add_matching_msymbols (objfile &objfile,
 			      const std::optional<compiled_regex> &name_regex,
-			      std::vector<symbol_search> *results) const;
+			      std::vector<symbol_search> &results) const;
 
   /* Return true if MSYMBOL is of type M_KIND.  */
   bool is_suitable_msymbol (const minimal_symbol *msymbol) const;


More information about the Gdb-cvs mailing list