Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH v2 10/11] gdb: change some pointers to references in global_symbol_searcher
Date: Wed, 30 Sep 2026 22:09:27 -0400	[thread overview]
Message-ID: <20261001020952.698419-11-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260929194119.155169-1-simon.marchi@efficios.com>

From: Simon Marchi <simon.marchi@efficios.com>

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
---
 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 ef21f285abcd..af748190ddd5 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4830,7 +4830,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;
@@ -4843,7 +4843,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)
@@ -4870,7 +4870,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;
 
@@ -4882,7 +4882,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;
 	}
     }
@@ -4894,13 +4894,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 ();
 
@@ -4916,8 +4916,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;
 	    }
@@ -4931,10 +4931,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;
 
@@ -4945,16 +4945,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)) != NULL))
+	      (msymbol->value_address (&objfile)) != NULL))
 	continue;
 
       if (lookup_symbol_in_objfile_from_linkage_name
-	    (objfile, msymbol->linkage_name (), SEARCH_VFT).symbol != NULL)
+	    (&objfile, msymbol->linkage_name (), SEARCH_VFT).symbol != NULL)
 	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;
     }
@@ -5047,14 +5047,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;
     }
 
@@ -5074,7 +5073,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 cf629387a17c..117d3fb0134f 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2707,7 +2707,7 @@ class global_symbol_searcher
      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 @@ class global_symbol_searcher
      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 @@ class global_symbol_searcher
      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;
-- 
2.55.0


  parent reply	other threads:[~2026-10-01  2:12 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 19:39 [PATCH 0/9] Cleanups " Simon Marchi
2026-09-29 19:39 ` [PATCH 1/9] gdb: add symbol_search_kind enum for global_symbol_searcher Simon Marchi
2026-09-30  9:31   ` Rohr, Stephan
2026-09-30 14:50     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 2/9] gdb: factor out regexp compilation from global_symbol_searcher::search Simon Marchi
2026-09-30 12:10   ` Rohr, Stephan
2026-09-30 16:21     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 3/9] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols Simon Marchi
2026-09-30  8:20   ` Rohr, Stephan
2026-09-30 16:36     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 4/9] gdb: use a switch on m_kind in add_matching_symbols Simon Marchi
     [not found]   ` <DS7PR11MB624725508FC878F3C263C2B3938B2@DS7PR11MB6247.namprd11.prod.outlook.com>
2026-09-30 19:41     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 5/9] gdb: make global_symbol_searcher::is_suitable_msymbol non-static Simon Marchi
2026-09-30 12:39   ` Rohr, Stephan
2026-09-29 19:39 ` [PATCH 6/9] gdb: update comment of global_symbol_searcher::expand_symtabs Simon Marchi
2026-09-30 13:08   ` Rohr, Stephan
2026-09-30 20:01     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 7/9] gdb: add matching helpers to global_symbol_searcher Simon Marchi
2026-09-30 13:51   ` Rohr, Stephan
2026-09-30 20:27     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 8/9] gdb: pass result containers by reference in global_symbol_searcher Simon Marchi
2026-09-30 13:58   ` Rohr, Stephan
2026-10-01  1:33     ` Simon Marchi
2026-09-29 19:39 ` [PATCH 9/9] gdb: fix some comments " Simon Marchi
2026-09-30 14:01   ` Rohr, Stephan
2026-10-01  1:38     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 00/11] Cleanups " simon.marchi
2026-10-01  2:09 ` [PATCH v2 01/11] gdb: add symbol_search_kind enum for global_symbol_searcher simon.marchi
2026-10-01 10:30   ` Andrew Burgess
2026-10-01 13:22     ` Simon Marchi
2026-10-01 15:35       ` Tom Tromey
2026-10-01  2:09 ` [PATCH v2 02/11] gdb: rename some preg/treg variables simon.marchi
2026-10-01 12:59   ` Andrew Burgess
2026-10-01 13:52     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 03/11] gdb: factor out regexp compilation from global_symbol_searcher::search simon.marchi
2026-10-01 13:19   ` Andrew Burgess
2026-10-01 13:54     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 04/11] gdb: use compile_symbol_search_regex in stack.c simon.marchi
2026-10-01 13:43   ` Andrew Burgess
2026-10-01 15:36   ` Tom Tromey
2026-10-01 15:52     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 05/11] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols simon.marchi
2026-10-01 13:46   ` Andrew Burgess
2026-10-01  2:09 ` [PATCH v2 06/11] gdb: use a switch on m_kind in add_matching_symbols simon.marchi
2026-10-01 15:01   ` Andrew Burgess
2026-10-01 15:07     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 07/11] gdb: make global_symbol_searcher::is_suitable_msymbol non-static simon.marchi
2026-10-01 15:09   ` Andrew Burgess
2026-10-01  2:09 ` [PATCH v2 08/11] gdb: update comments of global_symbol_searcher::expand_symtabs simon.marchi
2026-10-01 15:13   ` Andrew Burgess
2026-10-01  2:09 ` [PATCH v2 09/11] gdb: add matching helpers to global_symbol_searcher simon.marchi
2026-10-01 15:39   ` Andrew Burgess
2026-10-01 15:48     ` Simon Marchi
2026-10-01  2:09 ` simon.marchi [this message]
2026-10-01 15:53   ` [PATCH v2 10/11] gdb: change some pointers to references in global_symbol_searcher Andrew Burgess
2026-10-01 15:55     ` Simon Marchi
2026-10-01  2:09 ` [PATCH v2 11/11] gdb: fix some comments " simon.marchi
2026-10-01 15:56   ` Andrew Burgess
2026-10-01 17:47     ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001020952.698419-11-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox