public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/9] Simplify quick_symbol_functions
@ 2021-03-25 17:04 Tom Tromey
  2021-03-25 17:04 ` [PATCH 1/9] Add block_search_flags Tom Tromey
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches

I have been looking at writing a new implementation of
quick_symbol_functions, and while doing so I was reminded that there
is some redundancy in these methods.

These were introduced when .gdb_index was created, by factoring out
some psymtab calls.  They were purely ad hoc -- which I think can be
seen by reading through the descriptions.

This series removes the map_symtabs_matching_filename,
expand_symtabs_for_function, and lookup_symbol calls, in favor of
slightly expanding expand_symtabs_matching and using that.

Doing this required a few additions to expand_symtabs_matching.  This
series also requires my earlier 2-patch series to tweak psymtabs a
bit; otherwise there are regressions.

Note that the new approach may look slightly less performant, because
expand_symtabs_matching does not binary search global psymbols.
However, I instrumented "maint print statistics" and found that the
median number of global psymbols (per psymtab, which is what matters
for searching) is actually quite low -- it was 8 for gdb.

So, I tend to think the binary search is not important.  However,
perhaps psymbol_functions::expand_symtabs_matching (really
recursively_search_psymtabs) could be improved to use binary search,
if that should prove necessary.

I wrote a patch to remove expand_all_symtabs, but didn't include it
here.  It required some special cases in the DWARF
quick_symbol_functions, and didn't seem to add much value, considering
that this method is normally easy to implement.

I looked at removing map_matching_symbols, but it does name
comparisons in a subtly different way than expand_symtabs_matching.
Perhaps this could be done by another generalization of
expand_symtabs_matching.  Meanwhile, this series does simplify
map_matching_symbols somewhat.



Regression tested on x86-64 Fedora 32.

Let me know what you think.

Tom



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/9] Add block_search_flags
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 2/9] Let expand_symtabs_matching short-circuit Tom Tromey
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds block_search_flags, a flag enum.  This will be used to by
certain search functions so that the caller can control which blocks
are searched more precisely.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* quick-symbol.h (enum block_search_flag_values): New.
	(block_search_flags): New enum flags type.
---
 gdb/ChangeLog      |  5 +++++
 gdb/quick-symbol.h | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index dd2b896fd5f..1ca4945bf60 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -20,6 +20,16 @@
 #ifndef GDB_QUICK_SYMBOL_H
 #define GDB_QUICK_SYMBOL_H
 
+/* Like block_enum, but used as flags to pass to lookup functions.  */
+
+enum block_search_flag_values
+{
+  SEARCH_GLOBAL_BLOCK = 1,
+  SEARCH_STATIC_BLOCK = 2
+};
+
+DEF_ENUM_FLAGS_TYPE (enum block_search_flag_values, block_search_flags);
+
 /* Comparison function for symbol look ups.  */
 
 typedef int (symbol_compare_ftype) (const char *string1,
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/9] Let expand_symtabs_matching short-circuit
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
  2021-03-25 17:04 ` [PATCH 1/9] Add block_search_flags Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 3/9] Add search_flags to expand_symtabs_matching Tom Tromey
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes expand_symtabs_exp_notify_ftype to return bool, and
updates all the uses.  Now, if the notification function returns
false, the call is short-circuited and stops examining symtabs.  This
is a step toward replacing map_symtabs_matching_filename with
expand_symtabs_matching.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Update.
	* symfile.h (expand_symtabs_matching): Return bool.
	* symfile.c (expand_symtabs_matching): Return bool.
	* symfile-debug.c (objfile::expand_symtabs_matching): Return
	bool.
	* quick-symbol.h (expand_symtabs_exp_notify_ftype): Return bool.
	(struct quick_symbol_functions) <expand_symtabs_matching>: Return
	bool.
	* psymtab.c (psymbol_functions::expand_symtabs_matching): Return
	bool.
	* psympriv.h (struct psymbol_functions)
	<expand_symtabs_matching>: Return bool.
	* objfiles.h (struct objfile) <expand_symtabs_matching>: Return
	bool.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_matching>: Return bool.
	(struct dwarf2_debug_names_index) <expand_symtabs_matching>:
	Return bool.
	(dw2_expand_symtabs_matching_symbol): Return bool.
	(dw2_expand_symtabs_matching_one, dw2_expand_marked_cus)
	(dw2_expand_symtabs_matching)
	(dwarf2_gdb_index::expand_symtabs_matching)
	(dwarf2_debug_names_index::expand_symtabs_matching)
	(dwarf2_debug_names_index::expand_symtabs_matching): Return bool.
---
 gdb/ChangeLog       | 28 ++++++++++++++
 gdb/dwarf2/read.c   | 91 ++++++++++++++++++++++++++++-----------------
 gdb/objfiles.h      |  2 +-
 gdb/psympriv.h      |  2 +-
 gdb/psymtab.c       |  7 +++-
 gdb/quick-symbol.h  | 14 +++++--
 gdb/symfile-debug.c |  9 +++--
 gdb/symfile.c       | 12 +++---
 gdb/symfile.h       |  2 +-
 gdb/symtab.c        |  1 +
 10 files changed, 117 insertions(+), 51 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ee6f3f7f7e1..c351c9491aa 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2254,7 +2254,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
@@ -2283,7 +2283,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
@@ -3793,7 +3793,7 @@ dwarf2_base_index_functions::expand_symtabs_with_fullname
     }
 }
 
-static void
+static bool
 dw2_expand_symtabs_matching_symbol
   (mapped_index_base &index,
    const lookup_name_info &lookup_name_in,
@@ -3801,7 +3801,7 @@ dw2_expand_symtabs_matching_symbol
    gdb::function_view<bool (offset_type)> match_callback,
    dwarf2_per_objfile *per_objfile);
 
-static void
+static bool
 dw2_expand_symtabs_matching_one
   (dwarf2_per_cu_data *per_cu,
    dwarf2_per_objfile *per_objfile,
@@ -4108,7 +4108,7 @@ mapped_index_base::build_name_components (dwarf2_per_objfile *per_objfile)
    symbol name that matches, calls MATCH_CALLBACK, passing it the
    symbol's index in the mapped_index_base symbol table.  */
 
-static void
+static bool
 dw2_expand_symtabs_matching_symbol
   (mapped_index_base &index,
    const lookup_name_info &lookup_name_in,
@@ -4193,12 +4193,16 @@ dw2_expand_symtabs_matching_symbol
 
   /* Finally call the callback, once per match.  */
   ULONGEST prev = -1;
+  bool result = true;
   for (offset_type idx : matches)
     {
       if (prev != idx)
 	{
 	  if (!match_callback (idx))
-	    break;
+	    {
+	      result = false;
+	      break;
+	    }
 	  prev = idx;
 	}
     }
@@ -4206,6 +4210,8 @@ dw2_expand_symtabs_matching_symbol
   /* Above we use a type wider than idx's for 'prev', since 0 and
      (offset_type)-1 are both possible values.  */
   static_assert (sizeof (prev) > sizeof (offset_type), "");
+
+  return result;
 }
 
 #if GDB_SELF_TEST
@@ -4646,7 +4652,7 @@ run_test ()
    dw_expand_symtabs_matching_file_matcher), expand the CU and call
    EXPANSION_NOTIFY on it.  */
 
-static void
+static bool
 dw2_expand_symtabs_matching_one
   (dwarf2_per_cu_data *per_cu,
    dwarf2_per_objfile *per_objfile,
@@ -4662,15 +4668,16 @@ dw2_expand_symtabs_matching_one
       gdb_assert (symtab != nullptr);
 
       if (expansion_notify != NULL && symtab_was_null)
-	expansion_notify (symtab);
+	return expansion_notify (symtab);
     }
+  return true;
 }
 
 /* Helper for dw2_expand_matching symtabs.  Called on each symbol
    matched, to expand corresponding CUs that were marked.  IDX is the
    index of the symbol name that matched.  */
 
-static void
+static bool
 dw2_expand_marked_cus
   (dwarf2_per_objfile *per_objfile, offset_type idx,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4747,9 +4754,12 @@ dw2_expand_marked_cus
 	}
 
       dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (cu_index);
-      dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-				       expansion_notify);
+      if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
+					    expansion_notify))
+	return false;
     }
+
+  return true;
 }
 
 /* If FILE_MATCHER is non-NULL, set all the
@@ -4829,7 +4839,7 @@ dw_expand_symtabs_matching_file_matcher
     }
 }
 
-static void
+static bool
 dw2_expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4842,7 +4852,7 @@ dw2_expand_symtabs_matching
 
   /* index_table is NULL if OBJF_READNOW.  */
   if (!per_objfile->per_bfd->index_table)
-    return;
+    return true;
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
@@ -4852,25 +4862,31 @@ dw2_expand_symtabs_matching
 	{
 	  QUIT;
 
-	  dw2_expand_symtabs_matching_one (per_cu, per_objfile,
-					   file_matcher, expansion_notify);
+	  if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+						file_matcher,
+						expansion_notify))
+	    return false;
 	}
-      return;
+      return true;
     }
 
   mapped_index &index = *per_objfile->per_bfd->index_table;
 
-  dw2_expand_symtabs_matching_symbol (index, *lookup_name,
-				      symbol_matcher,
-				      [&] (offset_type idx)
+  bool result
+    = dw2_expand_symtabs_matching_symbol (index, *lookup_name,
+					  symbol_matcher,
+					  [&] (offset_type idx)
     {
-      dw2_expand_marked_cus (per_objfile, idx, file_matcher, expansion_notify,
-			     kind);
+      if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
+				  expansion_notify, kind))
+	return false;
       return true;
     }, per_objfile);
+
+  return result;
 }
 
-void
+bool
 dwarf2_gdb_index::expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4879,8 +4895,8 @@ dwarf2_gdb_index::expand_symtabs_matching
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      enum search_domain kind)
 {
-  dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
-			       symbol_matcher, expansion_notify, kind);
+  return dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
+				      symbol_matcher, expansion_notify, kind);
 }
 
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -5892,7 +5908,7 @@ dwarf2_debug_names_index::map_matching_symbols
     }
 }
 
-void
+bool
 dwarf2_debug_names_index::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -5905,7 +5921,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
 
   /* debug_names_table is NULL if OBJF_READNOW.  */
   if (!per_objfile->per_bfd->debug_names_table)
-    return;
+    return true;
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
@@ -5915,17 +5931,20 @@ dwarf2_debug_names_index::expand_symtabs_matching
 	{
 	  QUIT;
 
-	  dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-					   expansion_notify);
+	  if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+						file_matcher,
+						expansion_notify))
+	    return false;
 	}
-      return;
+      return true;
     }
 
   mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
 
-  dw2_expand_symtabs_matching_symbol (map, *lookup_name,
-				      symbol_matcher,
-				      [&] (offset_type namei)
+  bool result
+    = dw2_expand_symtabs_matching_symbol (map, *lookup_name,
+					  symbol_matcher,
+					  [&] (offset_type namei)
     {
       /* The name was matched, now expand corresponding CUs that were
 	 marked.  */
@@ -5933,10 +5952,14 @@ dwarf2_debug_names_index::expand_symtabs_matching
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
-	dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-					 expansion_notify);
+	if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+					      file_matcher,
+					      expansion_notify))
+	  return false;
       return true;
     }, per_objfile);
+
+  return result;
 }
 
 /* Get the content of the .gdb_index section of OBJ.  SECTION_OWNER should point
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 41f8fc913d8..f8dca8c6d56 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -575,7 +575,7 @@ struct objfile
      symbol_compare_ftype *ordered_compare);
 
   /* See quick_symbol_functions.  */
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index bbae2fc90e4..4fa1feb9461 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -540,7 +540,7 @@ struct psymbol_functions : public quick_symbol_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1ea7376a8c8..ea554e8bebb 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1293,7 +1293,7 @@ recursively_search_psymtabs
 /* Psymtab version of expand_symtabs_matching.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-void
+bool
 psymbol_functions::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -1346,9 +1346,12 @@ psymbol_functions::expand_symtabs_matching
 	    psymtab_to_symtab (objfile, ps);
 
 	  if (expansion_notify != NULL)
-	    expansion_notify (symtab);
+	    if (!expansion_notify (symtab))
+	      return false;
 	}
     }
+
+  return true;
 }
 
 /* Psymtab version of has_symbols.  See its definition in
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 1ca4945bf60..fa41b70fc3a 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -52,9 +52,11 @@ typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
 typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
 
 /* Callback for quick_symbol_functions->expand_symtabs_matching
-   to be called after a symtab has been expanded.  */
+   to be called after a symtab has been expanded.  If this returns
+   true, more symtabs are checked; if it returns false, iteration
+   stops.  */
 
-typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
+typedef bool (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
 
 /* The "quick" symbol functions exist so that symbol readers can
    avoiding an initial read of all the symbols.  For example, symbol
@@ -206,8 +208,12 @@ struct quick_symbol_functions
 
      If SYMBOL_MATCHER returns false, then the symbol is skipped.
 
-     Otherwise, the symbol's symbol table is expanded.  */
-  virtual void expand_symtabs_matching
+     Otherwise, the symbol's symbol table is expanded and the
+     notification function is called.  If the notification function
+     returns false, execution stops and this method returns false.
+     Otherwise, more files are considered.  This method will return
+     true if all calls to the notification function return true.  */
+  virtual bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 3daede88292..9890bfbd52f 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -265,7 +265,7 @@ objfile::map_matching_symbols
 				callback, ordered_compare);
 }
 
-void
+bool
 objfile::expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -283,8 +283,11 @@ objfile::expand_symtabs_matching
 		      search_domain_name (kind));
 
   for (const auto &iter : qf)
-    iter->expand_symtabs_matching (this, file_matcher, lookup_name,
-				   symbol_matcher, expansion_notify, kind);
+    if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
+					symbol_matcher, expansion_notify,
+					kind))
+      return false;
+  return true;
 }
 
 struct compunit_symtab *
diff --git a/gdb/symfile.c b/gdb/symfile.c
index e417878031d..09318474489 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3717,7 +3717,7 @@ symfile_free_objfile (struct objfile *objfile)
    Expand all symtabs that match the specified criteria.
    See quick_symbol_functions.expand_symtabs_matching for details.  */
 
-void
+bool
 expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info &lookup_name,
@@ -3726,10 +3726,12 @@ expand_symtabs_matching
    enum search_domain kind)
 {
   for (objfile *objfile : current_program_space->objfiles ())
-    objfile->expand_symtabs_matching (file_matcher,
-				      &lookup_name,
-				      symbol_matcher,
-				      expansion_notify, kind);
+    if (!objfile->expand_symtabs_matching (file_matcher,
+					   &lookup_name,
+					   symbol_matcher,
+					   expansion_notify, kind))
+      return false;
+  return true;
 }
 
 /* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
diff --git a/gdb/symfile.h b/gdb/symfile.h
index bae2a798703..b44c139a0b2 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -321,7 +321,7 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
 
 extern scoped_restore_tmpl<int> increment_reading_symtab (void);
 
-void expand_symtabs_matching
+bool expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 122fdf0b1d3..779d7a8de31 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5735,6 +5735,7 @@ default_collect_symbol_completion_matches_break_on
 			       add_symtab_completions (symtab,
 						       tracker, mode, lookup_name,
 						       sym_text, word, code);
+			       return true;
 			     },
 			   ALL_DOMAIN);
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/9] Add search_flags to expand_symtabs_matching
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
  2021-03-25 17:04 ` [PATCH 1/9] Add block_search_flags Tom Tromey
  2021-03-25 17:04 ` [PATCH 2/9] Let expand_symtabs_matching short-circuit Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 4/9] Add 'domain' parameter " Tom Tromey
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds a block search flags parameter to expand_symtabs_matching.
All callers are updated to search both the static and global blocks,
as that was the implied behavior before this patch.

This is a step toward replacing lookup_symbol with
expand_symtabs_matching.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symtab.c (global_symbol_searcher::expand_symtabs)
	(default_collect_symbol_completion_matches_break_on): Update.
	* symmisc.c (maintenance_expand_symtabs): Update.
	* symfile.h (expand_symtabs_matching): Add search_flags
	parameter.
	* symfile.c (expand_symtabs_matching): Add search_flags
	parameter.
	* symfile-debug.c (objfile::expand_symtabs_matching): Add
	search_flags parameter.
	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_matching>: Add search_flags parameter.
	* python/py-symbol.c (gdbpy_lookup_static_symbols): Update.
	* psymtab.c (recursively_search_psymtabs)
	(psymbol_functions::expand_symtabs_matching): Add search_flags
	parameter.
	* psympriv.h (struct psymbol_functions) <expand_symtabs_matching>:
	Add search_flags parameter.
	* objfiles.h (struct objfile) <expand_symtabs_matching>: Add
	search_flags parameter.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_matching>: Add search_flags parameter.
	(struct dwarf2_debug_names_index) <expand_symtabs_matching>: Add
	search_flags parameter.
	(dw2_map_matching_symbols): Update.
	(dw2_expand_marked_cus, dw2_expand_symtabs_matching)
	(dwarf2_gdb_index::expand_symtabs_matching): Add search_flags
	parameter.
	(dw2_debug_names_iterator): Change block_index to search flags.
	<m_block_index>: Likewise.
	(dw2_debug_names_iterator::next)
	(dwarf2_debug_names_index::lookup_symbol)
	(dwarf2_debug_names_index::expand_symtabs_for_function)
	(dwarf2_debug_names_index::map_matching_symbols)
	(dwarf2_debug_names_index::map_matching_symbols): Update.
	(dwarf2_debug_names_index::expand_symtabs_matching): Add
	search_flags parameter.
	* ada-lang.c (ada_add_global_exceptions)
	(collect_symbol_completion_matches): Update.
---
 gdb/ChangeLog          | 42 ++++++++++++++++++++++++++
 gdb/ada-lang.c         |  2 ++
 gdb/dwarf2/read.c      | 67 +++++++++++++++++++++++++++++++-----------
 gdb/linespec.c         |  2 ++
 gdb/objfiles.h         |  1 +
 gdb/psympriv.h         |  1 +
 gdb/psymtab.c          | 23 ++++++++++++---
 gdb/python/py-symbol.c |  4 ++-
 gdb/quick-symbol.h     |  1 +
 gdb/symfile-debug.c    |  3 +-
 gdb/symfile.c          |  5 +++-
 gdb/symfile.h          |  1 +
 gdb/symmisc.c          |  1 +
 gdb/symtab.c           |  2 ++
 14 files changed, 131 insertions(+), 24 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d0374780b98..f529d842f90 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12527,6 +12527,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 			     return name_matches_regex (decoded.c_str (), preg);
 			   },
 			   NULL,
+			   SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
 			   VARIABLES_DOMAIN);
 
   for (objfile *objfile : current_program_space->objfiles ())
@@ -13043,6 +13044,7 @@ class ada_language : public language_defn
 			     lookup_name,
 			     NULL,
 			     NULL,
+			     SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
 			     ALL_DOMAIN);
 
     /* At this point scan through the misc symbol vectors and add each
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c351c9491aa..36177ebc944 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2260,6 +2260,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind) override;
 };
 
@@ -2289,6 +2290,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind) override;
 };
 
@@ -4682,6 +4684,7 @@ dw2_expand_marked_cus
   (dwarf2_per_objfile *per_objfile, offset_type idx,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    search_domain kind)
 {
   offset_type *vec, vec_len, vec_idx;
@@ -4721,6 +4724,17 @@ dw2_expand_marked_cus
       /* Only check the symbol's kind if it has one.  */
       if (attrs_valid)
 	{
+	  if (is_static)
+	    {
+	      if ((search_flags & SEARCH_STATIC_BLOCK) == 0)
+		continue;
+	    }
+	  else
+	    {
+	      if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0)
+		continue;
+	    }
+
 	  switch (kind)
 	    {
 	    case VARIABLES_DOMAIN:
@@ -4846,6 +4860,7 @@ dw2_expand_symtabs_matching
    const lookup_name_info *lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain kind)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -4878,7 +4893,7 @@ dw2_expand_symtabs_matching
 					  [&] (offset_type idx)
     {
       if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
-				  expansion_notify, kind))
+				  expansion_notify, search_flags, kind))
 	return false;
       return true;
     }, per_objfile);
@@ -4893,10 +4908,12 @@ dwarf2_gdb_index::expand_symtabs_matching
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind)
 {
   return dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
-				      symbol_matcher, expansion_notify, kind);
+				      symbol_matcher, expansion_notify,
+				      search_flags, kind);
 }
 
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -5369,7 +5386,7 @@ class dw2_debug_names_iterator
 {
 public:
   dw2_debug_names_iterator (const mapped_debug_names &map,
-			    gdb::optional<block_enum> block_index,
+			    block_search_flags block_index,
 			    domain_enum domain,
 			    const char *name, dwarf2_per_objfile *per_objfile)
     : m_map (map), m_block_index (block_index), m_domain (domain),
@@ -5378,7 +5395,8 @@ class dw2_debug_names_iterator
   {}
 
   dw2_debug_names_iterator (const mapped_debug_names &map,
-			    search_domain search, uint32_t namei, dwarf2_per_objfile *per_objfile)
+			    search_domain search, uint32_t namei,
+			    dwarf2_per_objfile *per_objfile)
     : m_map (map),
       m_search (search),
       m_addr (find_vec_in_debug_names (map, namei, per_objfile)),
@@ -5386,7 +5404,7 @@ class dw2_debug_names_iterator
   {}
 
   dw2_debug_names_iterator (const mapped_debug_names &map,
-			    block_enum block_index, domain_enum domain,
+			    block_search_flags block_index, domain_enum domain,
 			    uint32_t namei, dwarf2_per_objfile *per_objfile)
     : m_map (map), m_block_index (block_index), m_domain (domain),
       m_addr (find_vec_in_debug_names (map, namei, per_objfile)),
@@ -5407,9 +5425,9 @@ class dw2_debug_names_iterator
   /* The internalized form of .debug_names.  */
   const mapped_debug_names &m_map;
 
-  /* If set, only look for symbols that match that block.  Valid values are
-     GLOBAL_BLOCK and STATIC_BLOCK.  */
-  const gdb::optional<block_enum> m_block_index;
+  /* Restrict the search to these blocks.  */
+  block_search_flags m_block_index = (SEARCH_GLOBAL_BLOCK
+				      | SEARCH_STATIC_BLOCK);
 
   /* The kind of symbol we're looking for.  */
   const domain_enum m_domain = UNDEF_DOMAIN;
@@ -5658,13 +5676,18 @@ dw2_debug_names_iterator::next ()
     goto again;
 
   /* Check static vs global.  */
-  if (symbol_linkage_ != symbol_linkage::unknown && m_block_index.has_value ())
+  if (symbol_linkage_ != symbol_linkage::unknown)
     {
-	const bool want_static = *m_block_index == STATIC_BLOCK;
-	const bool symbol_is_static =
-	  symbol_linkage_ == symbol_linkage::static_;
-	if (want_static != symbol_is_static)
-	  goto again;
+      if (symbol_linkage_ == symbol_linkage::static_)
+	{
+	  if ((m_block_index & SEARCH_STATIC_BLOCK) == 0)
+	    goto again;
+	}
+      else
+	{
+	  if ((m_block_index & SEARCH_GLOBAL_BLOCK) == 0)
+	    goto again;
+	}
     }
 
   /* Match dw2_symtab_iter_next, symbol_kind
@@ -5779,7 +5802,11 @@ dwarf2_debug_names_index::lookup_symbol
     }
   const auto &map = *mapp;
 
-  dw2_debug_names_iterator iter (map, block_index, domain, name, per_objfile);
+  dw2_debug_names_iterator iter (map,
+				 block_index == GLOBAL_BLOCK
+				 ? SEARCH_GLOBAL_BLOCK
+				 : SEARCH_STATIC_BLOCK,
+				 domain, name, per_objfile);
 
   struct compunit_symtab *stab_best = NULL;
   struct dwarf2_per_cu_data *per_cu;
@@ -5841,7 +5868,10 @@ dwarf2_debug_names_index::expand_symtabs_for_function
     {
       const mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
 
-      dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name,
+      dw2_debug_names_iterator iter (map,
+				     (SEARCH_GLOBAL_BLOCK
+				      | SEARCH_STATIC_BLOCK),
+				     VAR_DOMAIN, func_name,
 				     per_objfile);
 
       struct dwarf2_per_cu_data *per_cu;
@@ -5866,6 +5896,8 @@ dwarf2_debug_names_index::map_matching_symbols
 
   mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
   const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+  const block_search_flags block_flags
+    = global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK;
 
   const char *match_name = name.ada ().lookup_name ().c_str ();
   auto matcher = [&] (const char *symname)
@@ -5880,7 +5912,7 @@ dwarf2_debug_names_index::map_matching_symbols
     {
       /* The name was matched, now expand corresponding CUs that were
 	 marked.  */
-      dw2_debug_names_iterator iter (map, block_kind, domain, namei,
+      dw2_debug_names_iterator iter (map, block_flags, domain, namei,
 				     per_objfile);
 
       struct dwarf2_per_cu_data *per_cu;
@@ -5915,6 +5947,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
    const lookup_name_info *lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain kind)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4034bbab8a0..f37861b343a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1170,6 +1170,8 @@ iterate_over_all_matching_symtabs
       for (objfile *objfile : current_program_space->objfiles ())
 	{
 	  objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL,
+					    (SEARCH_GLOBAL_BLOCK
+					     | SEARCH_STATIC_BLOCK),
 					    search_domain);
 
 	  for (compunit_symtab *cu : objfile->compunits ())
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index f8dca8c6d56..5c362d509e2 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -580,6 +580,7 @@ struct objfile
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind);
 
   /* See quick_symbol_functions.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 4fa1feb9461..74c1262709d 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -546,6 +546,7 @@ struct psymbol_functions : public quick_symbol_functions
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind) override;
 
   struct compunit_symtab *find_pc_sect_compunit_symtab
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index ea554e8bebb..1d92c61bad3 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1207,6 +1207,7 @@ static bool
 recursively_search_psymtabs
   (struct partial_symtab *ps,
    struct objfile *objfile,
+   block_search_flags search_flags,
    enum search_domain domain,
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
@@ -1229,8 +1230,8 @@ recursively_search_psymtabs
 	continue;
 
       r = recursively_search_psymtabs (ps->dependencies[i],
-				       objfile, domain, lookup_name,
-				       sym_matcher);
+				       objfile, search_flags, domain,
+				       lookup_name, sym_matcher);
       if (r != 0)
 	{
 	  ps->searched_flag = PST_SEARCHED_AND_FOUND;
@@ -1247,11 +1248,24 @@ recursively_search_psymtabs
   /* Go through all of the symbols stored in a partial
      symtab in one loop.  */
   partial_symbol **psym = ps->global_psymbols.data ();
+
+  if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0)
+    {
+      if (ps->static_psymbols.empty ())
+	keep_going = 0;
+      else
+	{
+	  psym = ps->static_psymbols.data ();
+	  bound = sbound;
+	}
+    }
+
   while (keep_going)
     {
       if (psym >= bound)
 	{
-	  if (bound == gbound && !ps->static_psymbols.empty ())
+	  if (bound == gbound && !ps->static_psymbols.empty ()
+	      && (search_flags & SEARCH_STATIC_BLOCK) != 0)
 	    {
 	      psym = ps->static_psymbols.data ();
 	      bound = sbound;
@@ -1300,6 +1314,7 @@ psymbol_functions::expand_symtabs_matching
    const lookup_name_info *lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain domain)
 {
   /* Clear the search flags.  */
@@ -1338,7 +1353,7 @@ psymbol_functions::expand_symtabs_matching
 	}
 
       if ((symbol_matcher == NULL && lookup_name == NULL)
-	  || recursively_search_psymtabs (ps, objfile, domain,
+	  || recursively_search_psymtabs (ps, objfile, search_flags, domain,
 					  *psym_lookup_name,
 					  symbol_matcher))
 	{
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 25b6488f1be..ead26d5d441 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -560,7 +560,9 @@ 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, ALL_DOMAIN);
+      expand_symtabs_matching (NULL, lookup_name, NULL, NULL,
+			       SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+			       ALL_DOMAIN);
 
       for (objfile *objfile : current_program_space->objfiles ())
 	{
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index fa41b70fc3a..0a3e6d40d92 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -219,6 +219,7 @@ struct quick_symbol_functions
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+     block_search_flags search_flags,
      enum search_domain kind) = 0;
 
   /* Return the comp unit from OBJFILE that contains PC and
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 9890bfbd52f..35720769460 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -271,6 +271,7 @@ objfile::expand_symtabs_matching
    const lookup_name_info *lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain kind)
 {
   if (debug_symfile)
@@ -285,7 +286,7 @@ objfile::expand_symtabs_matching
   for (const auto &iter : qf)
     if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
 					symbol_matcher, expansion_notify,
-					kind))
+					search_flags, kind))
       return false;
   return true;
 }
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 09318474489..9f2b1614dc3 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3723,13 +3723,16 @@ expand_symtabs_matching
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain kind)
 {
   for (objfile *objfile : current_program_space->objfiles ())
     if (!objfile->expand_symtabs_matching (file_matcher,
 					   &lookup_name,
 					   symbol_matcher,
-					   expansion_notify, kind))
+					   expansion_notify,
+					   search_flags,
+					   kind))
       return false;
   return true;
 }
diff --git a/gdb/symfile.h b/gdb/symfile.h
index b44c139a0b2..3e7c8bbc4ec 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -326,6 +326,7 @@ bool expand_symtabs_matching
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
+   block_search_flags search_flags,
    enum search_domain kind);
 
 void map_symbol_filenames (symbol_filename_ftype *fun, void *data,
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 9ea5cb55d0f..33657f88fa9 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -938,6 +938,7 @@ maintenance_expand_symtabs (const char *args, int from_tty)
 	 NULL,
 	 NULL,
 	 NULL,
+	 SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
 	 ALL_DOMAIN);
 }
 \f
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 779d7a8de31..91251a22ce6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4552,6 +4552,7 @@ global_symbol_searcher::expand_symtabs
 	       || preg->exec (symname, 0, NULL, 0) == 0);
      },
      NULL,
+     SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
      kind);
 
   /* Here, we search through the minimal symbol tables for functions and
@@ -5737,6 +5738,7 @@ default_collect_symbol_completion_matches_break_on
 						       sym_text, word, code);
 			       return true;
 			     },
+			   SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
 			   ALL_DOMAIN);
 
   /* Search upwards from currently selected frame (so that we can
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/9] Add 'domain' parameter to expand_symtabs_matching
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (2 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 3/9] Add search_flags to expand_symtabs_matching Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 5/9] Remove quick_symbol_functions::lookup_symbol Tom Tromey
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Currently, expand_symtabs_matching only accepts a search_domain
parameter.  However, lookup_symbol uses a domain_enum instead, and the
two, confusingly, do quite different things -- one cannot emulate the
other.  So, this patch adds a domain_enum parameter to
expand_symtabs_matching, with UNDEF_DOMAIN used as a wildcard.

This is another step toward replacing lookup_symbol with
expand_symtabs_matching.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symtab.c (global_symbol_searcher::expand_symtabs): Update.
	* symmisc.c (maintenance_expand_symtabs): Update.
	* symfile.c (expand_symtabs_matching): Update.
	* symfile-debug.c (objfile::expand_symtabs_matching): Add 'domain'
	parameter.
	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_matching>: Add 'domain' parameter.
	* psymtab.c (recursively_search_psymtabs)
	(psymbol_functions::expand_symtabs_matching): Add 'domain'
	parameter.
	* psympriv.h (struct psymbol_functions) <expand_symtabs_matching>:
	Add 'domain' parameter.
	* objfiles.h (struct objfile) <expand_symtabs_matching>: Add
	'domain' parameter.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_matching>: Add 'domain' parameter.
	(struct dwarf2_debug_names_index) <expand_symtabs_matching>: Add
	'domain' parameter.
	(dw2_expand_symtabs_matching)
	(dwarf2_gdb_index::expand_symtabs_matching)
	(dw2_debug_names_iterator)
	(dwarf2_debug_names_index::expand_symtabs_matching): Add 'domain'
	parameter.
---
 gdb/ChangeLog       | 27 +++++++++++++++++++++++++++
 gdb/dwarf2/read.c   | 13 ++++++++++---
 gdb/linespec.c      |  1 +
 gdb/objfiles.h      |  1 +
 gdb/psympriv.h      |  1 +
 gdb/psymtab.c       | 34 ++++++++++++++++++++--------------
 gdb/quick-symbol.h  |  4 +++-
 gdb/symfile-debug.c |  3 ++-
 gdb/symfile.c       |  1 +
 gdb/symmisc.c       |  1 +
 gdb/symtab.c        |  1 +
 11 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 36177ebc944..195def9d355 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2261,6 +2261,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind) override;
 };
 
@@ -2291,6 +2292,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind) override;
 };
 
@@ -4861,6 +4863,7 @@ dw2_expand_symtabs_matching
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    block_search_flags search_flags,
+   domain_enum domain,
    enum search_domain kind)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -4909,11 +4912,12 @@ dwarf2_gdb_index::expand_symtabs_matching
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind)
 {
   return dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name,
 				      symbol_matcher, expansion_notify,
-				      search_flags, kind);
+				      search_flags, domain, kind);
 }
 
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -5396,8 +5400,10 @@ class dw2_debug_names_iterator
 
   dw2_debug_names_iterator (const mapped_debug_names &map,
 			    search_domain search, uint32_t namei,
-			    dwarf2_per_objfile *per_objfile)
+			    dwarf2_per_objfile *per_objfile,
+			    domain_enum domain = UNDEF_DOMAIN)
     : m_map (map),
+      m_domain (domain),
       m_search (search),
       m_addr (find_vec_in_debug_names (map, namei, per_objfile)),
       m_per_objfile (per_objfile)
@@ -5948,6 +5954,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    block_search_flags search_flags,
+   domain_enum domain,
    enum search_domain kind)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -5981,7 +5988,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
     {
       /* The name was matched, now expand corresponding CUs that were
 	 marked.  */
-      dw2_debug_names_iterator iter (map, kind, namei, per_objfile);
+      dw2_debug_names_iterator iter (map, kind, namei, per_objfile, domain);
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index f37861b343a..03a11fda214 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1172,6 +1172,7 @@ iterate_over_all_matching_symtabs
 	  objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL,
 					    (SEARCH_GLOBAL_BLOCK
 					     | SEARCH_STATIC_BLOCK),
+					    UNDEF_DOMAIN,
 					    search_domain);
 
 	  for (compunit_symtab *cu : objfile->compunits ())
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 5c362d509e2..22e7d7d84e1 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -581,6 +581,7 @@ struct objfile
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind);
 
   /* See quick_symbol_functions.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 74c1262709d..ff3157c6691 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -547,6 +547,7 @@ struct psymbol_functions : public quick_symbol_functions
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind) override;
 
   struct compunit_symtab *find_pc_sect_compunit_symtab
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1d92c61bad3..a1df7c777fe 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1208,7 +1208,8 @@ recursively_search_psymtabs
   (struct partial_symtab *ps,
    struct objfile *objfile,
    block_search_flags search_flags,
-   enum search_domain domain,
+   domain_enum domain,
+   enum search_domain search,
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
 {
@@ -1230,7 +1231,7 @@ recursively_search_psymtabs
 	continue;
 
       r = recursively_search_psymtabs (ps->dependencies[i],
-				       objfile, search_flags, domain,
+				       objfile, search_flags, domain, search,
 				       lookup_name, sym_matcher);
       if (r != 0)
 	{
@@ -1278,16 +1279,19 @@ recursively_search_psymtabs
 	{
 	  QUIT;
 
-	  if ((domain == ALL_DOMAIN
-	       || (domain == MODULES_DOMAIN
-		   && (*psym)->domain == MODULE_DOMAIN)
-	       || (domain == VARIABLES_DOMAIN
-		   && (*psym)->aclass != LOC_TYPEDEF
-		   && (*psym)->aclass != LOC_BLOCK)
-	       || (domain == FUNCTIONS_DOMAIN
-		   && (*psym)->aclass == LOC_BLOCK)
-	       || (domain == TYPES_DOMAIN
-		   && (*psym)->aclass == LOC_TYPEDEF))
+	  if ((domain == UNDEF_DOMAIN
+	       || symbol_matches_domain ((*psym)->ginfo.language (),
+					 (*psym)->domain, domain))
+	      && (search == ALL_DOMAIN
+		  || (search == MODULES_DOMAIN
+		      && (*psym)->domain == MODULE_DOMAIN)
+		  || (search == VARIABLES_DOMAIN
+		      && (*psym)->aclass != LOC_TYPEDEF
+		      && (*psym)->aclass != LOC_BLOCK)
+		  || (search == FUNCTIONS_DOMAIN
+		      && (*psym)->aclass == LOC_BLOCK)
+		  || (search == TYPES_DOMAIN
+		      && (*psym)->aclass == LOC_TYPEDEF))
 	      && psymbol_name_matches (*psym, lookup_name)
 	      && (sym_matcher == NULL
 		  || sym_matcher ((*psym)->ginfo.search_name ())))
@@ -1315,7 +1319,8 @@ psymbol_functions::expand_symtabs_matching
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    block_search_flags search_flags,
-   enum search_domain domain)
+   domain_enum domain,
+   enum search_domain search)
 {
   /* Clear the search flags.  */
   for (partial_symtab *ps : require_partial_symbols (objfile))
@@ -1353,7 +1358,8 @@ psymbol_functions::expand_symtabs_matching
 	}
 
       if ((symbol_matcher == NULL && lookup_name == NULL)
-	  || recursively_search_psymtabs (ps, objfile, search_flags, domain,
+	  || recursively_search_psymtabs (ps, objfile, search_flags,
+					  domain, search,
 					  *psym_lookup_name,
 					  symbol_matcher))
 	{
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 0a3e6d40d92..822e3643566 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -202,7 +202,8 @@ struct quick_symbol_functions
 
      Otherwise, individual symbols are considered.
 
-     If KIND does not match, the symbol is skipped.
+     If DOMAIN or KIND do not match, the symbol is skipped.
+     If DOMAIN is UNDEF_DOMAIN, that is treated as a wildcard.
 
      If the symbol name does not match LOOKUP_NAME, the symbol is skipped.
 
@@ -220,6 +221,7 @@ struct quick_symbol_functions
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
      gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
      block_search_flags search_flags,
+     domain_enum domain,
      enum search_domain kind) = 0;
 
   /* Return the comp unit from OBJFILE that contains PC and
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 35720769460..1e8cd549764 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -272,6 +272,7 @@ objfile::expand_symtabs_matching
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
    block_search_flags search_flags,
+   domain_enum domain,
    enum search_domain kind)
 {
   if (debug_symfile)
@@ -286,7 +287,7 @@ objfile::expand_symtabs_matching
   for (const auto &iter : qf)
     if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
 					symbol_matcher, expansion_notify,
-					search_flags, kind))
+					search_flags, domain, kind))
       return false;
   return true;
 }
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 9f2b1614dc3..bd11d6f0799 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3732,6 +3732,7 @@ expand_symtabs_matching
 					   symbol_matcher,
 					   expansion_notify,
 					   search_flags,
+					   UNDEF_DOMAIN,
 					   kind))
       return false;
   return true;
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 33657f88fa9..d992c671635 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -939,6 +939,7 @@ maintenance_expand_symtabs (const char *args, int from_tty)
 	 NULL,
 	 NULL,
 	 SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+	 UNDEF_DOMAIN,
 	 ALL_DOMAIN);
 }
 \f
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 91251a22ce6..5d9534032ea 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4553,6 +4553,7 @@ global_symbol_searcher::expand_symtabs
      },
      NULL,
      SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
+     UNDEF_DOMAIN,
      kind);
 
   /* Here, we search through the minimal symbol tables for functions and
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/9] Remove quick_symbol_functions::lookup_symbol
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (3 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 4/9] Add 'domain' parameter " Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 6/9] Remove quick_symbol_functions::map_symtabs_matching_filename Tom Tromey
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes quick_symbol_functions, replacing it with calls to
expand_symtabs_matching.  Because the replacement is somewhat verbose,
objfile::lookup_symbol is not removed.  This consolidates some
duplicated code into this one spot.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::lookup_symbol): Rewrite.
	* quick-symbol.h (struct quick_symbol_functions) <lookup_symbol>:
	Remove.
	* psymtab.c (psymbol_functions::lookup_symbol): Remove.
	* psympriv.h (struct psymbol_functions) <lookup_symbol>: Remove.
	* objfiles.h (struct objfile) <lookup_symbol>: Add comment.
	* dwarf2/read.c (struct dwarf2_gdb_index) <lookup_symbol>:
	Remove.
	(struct dwarf2_debug_names_index) <lookup_symbol>: Remove.
	(dwarf2_gdb_index::lookup_symbol)
	(dwarf2_debug_names_index::lookup_symbol): Remove.
---
 gdb/ChangeLog       |  14 ++++++
 gdb/dwarf2/read.c   | 106 --------------------------------------------
 gdb/objfiles.h      |  11 ++++-
 gdb/psympriv.h      |   5 ---
 gdb/psymtab.c       |  51 ---------------------
 gdb/quick-symbol.h  |  15 -------
 gdb/symfile-debug.c |  44 +++++++++++++++++-
 7 files changed, 66 insertions(+), 180 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 195def9d355..5274e31b591 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2236,11 +2236,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
 
 struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) override;
-
   void dump (struct objfile *objfile) override;
 
   void expand_symtabs_for_function (struct objfile *objfile,
@@ -2267,11 +2262,6 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
 
 struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) override;
-
   void dump (struct objfile *objfile) override;
 
   void expand_symtabs_for_function (struct objfile *objfile,
@@ -3638,50 +3628,6 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
   return NULL;
 }
 
-struct compunit_symtab *
-dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
-				 block_enum block_index,
-				 const char *name, domain_enum domain)
-{
-  struct compunit_symtab *stab_best = NULL;
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
-  struct dw2_symtab_iterator iter;
-  struct dwarf2_per_cu_data *per_cu;
-
-  dw2_symtab_iter_init (&iter, per_objfile, block_index, domain, name);
-
-  while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-    {
-      struct symbol *sym, *with_opaque = NULL;
-      struct compunit_symtab *stab
-	= dw2_instantiate_symtab (per_cu, per_objfile, false);
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-      sym = block_find_symbol (block, name, domain,
-			       block_find_non_opaque_type_preferred,
-			       &with_opaque);
-
-      /* Some caution must be observed with overloaded functions
-	 and methods, since the index will not contain any overload
-	 information (but NAME might contain it).  */
-
-      if (sym != NULL
-	  && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
-	return stab;
-      if (with_opaque != NULL
-	  && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
-	stab_best = stab;
-
-      /* Keep looking through other CUs.  */
-    }
-
-  return stab_best;
-}
-
 void
 dwarf2_base_index_functions::print_stats (struct objfile *objfile,
 					  bool print_bcache)
@@ -5793,58 +5739,6 @@ dw2_debug_names_iterator::next ()
   return per_cu;
 }
 
-struct compunit_symtab *
-dwarf2_debug_names_index::lookup_symbol
-     (struct objfile *objfile, block_enum block_index,
-      const char *name, domain_enum domain)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  const auto &mapp = per_objfile->per_bfd->debug_names_table;
-  if (!mapp)
-    {
-      /* index is NULL if OBJF_READNOW.  */
-      return NULL;
-    }
-  const auto &map = *mapp;
-
-  dw2_debug_names_iterator iter (map,
-				 block_index == GLOBAL_BLOCK
-				 ? SEARCH_GLOBAL_BLOCK
-				 : SEARCH_STATIC_BLOCK,
-				 domain, name, per_objfile);
-
-  struct compunit_symtab *stab_best = NULL;
-  struct dwarf2_per_cu_data *per_cu;
-  while ((per_cu = iter.next ()) != NULL)
-    {
-      struct symbol *sym, *with_opaque = NULL;
-      compunit_symtab *stab
-	= dw2_instantiate_symtab (per_cu, per_objfile, false);
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-      sym = block_find_symbol (block, name, domain,
-			       block_find_non_opaque_type_preferred,
-			       &with_opaque);
-
-      /* Some caution must be observed with overloaded functions and
-	 methods, since the index will not contain any overload
-	 information (but NAME might contain it).  */
-
-      if (sym != NULL
-	  && strcmp_iw (sym->search_name (), name) == 0)
-	return stab;
-      if (with_opaque != NULL
-	  && strcmp_iw (with_opaque->search_name (), name) == 0)
-	stab_best = stab;
-
-      /* Keep looking through other CUs.  */
-    }
-
-  return stab_best;
-}
-
 /* This dumps minimal information about .debug_names.  It is called
    via "mt print objfiles".  The gdb.dwarf2/gdb-index.exp testcase
    uses this to verify that .debug_names has been loaded.  */
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 22e7d7d84e1..bc3ad7bcdef 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -548,7 +548,16 @@ struct objfile
     (const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback);
 
-  /* See quick_symbol_functions.  */
+  /* Check to see if the symbol is defined in a "partial" symbol table
+     of this objfile.  BLOCK_INDEX should be either GLOBAL_BLOCK or
+     STATIC_BLOCK, depending on whether we want to search global
+     symbols or static symbols.  NAME is the name of the symbol to
+     look for.  DOMAIN indicates what sort of symbol to search for.
+
+     Returns the newly-expanded compunit in which the symbol is
+     defined, or NULL if no such symbol table exists.  If OBJFILE
+     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
+     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
   struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
 					 domain_enum domain);
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index ff3157c6691..c4e484481ea 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -510,11 +510,6 @@ struct psymbol_functions : public quick_symbol_functions
     (struct objfile *objfile, const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback) override;
 
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) override;
-
   enum language lookup_global_symbol_language (struct objfile *objfile,
 					       const char *name,
 					       domain_enum domain,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index a1df7c777fe..ad7d06087d2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -432,57 +432,6 @@ find_pc_sect_psymbol (struct objfile *objfile,
   return best;
 }
 
-/* Psymtab version of lookup_symbol.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-struct compunit_symtab *
-psymbol_functions::lookup_symbol (struct objfile *objfile,
-				  block_enum block_index, const char *name,
-				  const domain_enum domain)
-{
-  const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
-  struct compunit_symtab *stab_best = NULL;
-
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
-  lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
-
-  for (partial_symtab *ps : require_partial_symbols (objfile))
-    {
-      if (!ps->readin_p (objfile)
-	  && lookup_partial_symbol (objfile, ps, psym_lookup_name,
-				    psymtab_index, domain))
-	{
-	  struct symbol *sym, *with_opaque = NULL;
-	  struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps);
-	  /* Note: While psymtab_to_symtab can return NULL if the
-	     partial symtab is empty, we can assume it won't here
-	     because lookup_partial_symbol succeeded.  */
-	  const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-	  const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-	  sym = block_find_symbol (block, name, domain,
-				   block_find_non_opaque_type_preferred,
-				   &with_opaque);
-
-	  /* Some caution must be observed with overloaded functions
-	     and methods, since the index will not contain any overload
-	     information (but NAME might contain it).  */
-
-	  if (sym != NULL
-	      && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
-	    return stab;
-	  if (with_opaque != NULL
-	      && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
-	    stab_best = stab;
-
-	  /* Keep looking through other psymtabs.  */
-	}
-    }
-
-  return stab_best;
-}
-
 /* Psymtab version of lookup_global_symbol_language.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 822e3643566..4886b9e8842 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -109,21 +109,6 @@ struct quick_symbol_functions
     (struct objfile *objfile, const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback) = 0;
 
-  /* Check to see if the symbol is defined in a "partial" symbol table
-     of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
-     depending on whether we want to search global symbols or static
-     symbols.  NAME is the name of the symbol to look for.  DOMAIN
-     indicates what sort of symbol to search for.
-
-     Returns the newly-expanded compunit in which the symbol is
-     defined, or NULL if no such symbol table exists.  If OBJFILE
-     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
-     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
-  virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-						 block_enum block_index,
-						 const char *name,
-						 domain_enum domain) = 0;
-
   /* Check to see if the global symbol is defined in a "partial" symbol table
      of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
      indicates what sort of symbol to search for.
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 1e8cd549764..2a1c366ddcc 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -32,6 +32,7 @@
 #include "source.h"
 #include "symtab.h"
 #include "symfile.h"
+#include "block.h"
 
 /* We need to save a pointer to the real symbol functions.
    Plus, the debug versions are malloc'd because we have to NULL out the
@@ -173,10 +174,49 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 		      objfile_debug_name (this), kind, name,
 		      domain_name (domain));
 
+  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+
+  auto search_one_symtab = [&] (compunit_symtab *stab)
+  {
+    struct symbol *sym, *with_opaque = NULL;
+    const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
+    const struct block *block = BLOCKVECTOR_BLOCK (bv, kind);
+
+    sym = block_find_symbol (block, name, domain,
+			     block_find_non_opaque_type_preferred,
+			     &with_opaque);
+
+    /* Some caution must be observed with overloaded functions
+       and methods, since the index will not contain any overload
+       information (but NAME might contain it).  */
+
+    if (sym != NULL
+	&& SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
+      {
+	retval = stab;
+	/* Found it.  */
+	return false;
+      }
+    if (with_opaque != NULL
+	&& SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
+      retval = stab;
+
+    /* Keep looking through other psymtabs.  */
+    return true;
+  };
+
   for (const auto &iter : qf)
     {
-      retval = iter->lookup_symbol (this, kind, name, domain);
-      if (retval != nullptr)
+      if (!iter->expand_symtabs_matching (this,
+					  nullptr,
+					  &lookup_name,
+					  nullptr,
+					  search_one_symtab,
+					  kind == GLOBAL_BLOCK
+					  ? SEARCH_GLOBAL_BLOCK
+					  : SEARCH_STATIC_BLOCK,
+					  domain,
+					  ALL_DOMAIN))
 	break;
     }
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/9] Remove quick_symbol_functions::map_symtabs_matching_filename
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (4 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 5/9] Remove quick_symbol_functions::lookup_symbol Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 7/9] Remove quick_symbol_functions::expand_symtabs_for_function Tom Tromey
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This replaces quick_symbol_functions::map_symtabs_matching_filename
with a call to expand_symtabs_matching.  As with the previous patch,
rather than update all callers, the implementation is consolidated in
objfile::map_symtabs_matching_filename.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::map_symtabs_matching_filename):
	Rewrite.
	* quick-symbol.h (struct quick_symbol_functions)
	<map_symtabs_matching_filename>: Remove.
	* psymtab.c (partial_map_expand_apply)
	(psymbol_functions::map_symtabs_matching_filename): Remove.
	* psympriv.h (struct psymbol_functions)
	<map_symtabs_matching_filename>: Remove.
	* objfiles.h (struct objfile) <map_symtabs_matching_filename>:
	Update comment.
	* dwarf2/read.c (struct dwarf2_base_index_functions)
	<map_symtabs_matching_filename>: Remove.
	(dw2_map_expand_apply)
	(dwarf2_base_index_functions::map_symtabs_matching_filename):
	Remove.
---
 gdb/ChangeLog       | 18 +++++++++
 gdb/dwarf2/read.c   | 98 ---------------------------------------------
 gdb/objfiles.h      | 13 +++++-
 gdb/psympriv.h      |  4 --
 gdb/psymtab.c       | 90 -----------------------------------------
 gdb/quick-symbol.h  | 16 --------
 gdb/symfile-debug.c | 53 +++++++++++++++++++++---
 7 files changed, 77 insertions(+), 215 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5274e31b591..8d5ef85f15b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2199,10 +2199,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
 
   void forget_cached_source_info (struct objfile *objfile) override;
 
-  bool map_symtabs_matching_filename
-    (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback) override;
-
   enum language lookup_global_symbol_language (struct objfile *objfile,
 					       const char *name,
 					       domain_enum domain,
@@ -3352,100 +3348,6 @@ dwarf2_base_index_functions::forget_cached_source_info
 			  dw2_free_cached_file_names, NULL);
 }
 
-/* Helper function for dw2_map_symtabs_matching_filename that expands
-   the symtabs and calls the iterator.  */
-
-static int
-dw2_map_expand_apply (struct objfile *objfile,
-		      struct dwarf2_per_cu_data *per_cu,
-		      const char *name, const char *real_path,
-		      gdb::function_view<bool (symtab *)> callback)
-{
-  struct compunit_symtab *last_made = objfile->compunit_symtabs;
-
-  /* Don't visit already-expanded CUs.  */
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-  if (per_objfile->symtab_set_p (per_cu))
-    return 0;
-
-  /* This may expand more than one symtab, and we want to iterate over
-     all of them.  */
-  dw2_instantiate_symtab (per_cu, per_objfile, false);
-
-  return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
-				    last_made, callback);
-}
-
-/* Implementation of the map_symtabs_matching_filename method.  */
-
-bool
-dwarf2_base_index_functions::map_symtabs_matching_filename
-  (struct objfile *objfile, const char *name, const char *real_path,
-   gdb::function_view<bool (symtab *)> callback)
-{
-  const char *name_basename = lbasename (name);
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  /* The rule is CUs specify all the files, including those used by
-     any TU, so there's no need to scan TUs here.  */
-
-  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
-    {
-      /* We only need to look at symtabs not already expanded.  */
-      if (per_objfile->symtab_set_p (per_cu))
-	continue;
-
-      quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
-      if (file_data == NULL)
-	continue;
-
-      for (int j = 0; j < file_data->num_file_names; ++j)
-	{
-	  const char *this_name = file_data->file_names[j];
-	  const char *this_real_name;
-
-	  if (compare_filenames_for_search (this_name, name))
-	    {
-	      if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
-					callback))
-		return true;
-	      continue;
-	    }
-
-	  /* Before we invoke realpath, which can get expensive when many
-	     files are involved, do a quick comparison of the basenames.  */
-	  if (! basenames_may_differ
-	      && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
-	    continue;
-
-	  this_real_name = dw2_get_real_path (per_objfile, file_data, j);
-	  if (compare_filenames_for_search (this_real_name, name))
-	    {
-	      if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
-					callback))
-		return true;
-	      continue;
-	    }
-
-	  if (real_path != NULL)
-	    {
-	      gdb_assert (IS_ABSOLUTE_PATH (real_path));
-	      gdb_assert (IS_ABSOLUTE_PATH (name));
-	      if (this_real_name != NULL
-		  && FILENAME_CMP (real_path, this_real_name) == 0)
-		{
-		  if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
-					    callback))
-		    return true;
-		  continue;
-		}
-	    }
-	}
-    }
-
-  return false;
-}
-
 /* Struct used to manage iterating over all CUs looking for a symbol.  */
 
 struct dw2_symtab_iterator
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index bc3ad7bcdef..06628e38e88 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -543,7 +543,18 @@ struct objfile
   /* See quick_symbol_functions.  */
   void forget_cached_source_info ();
 
-  /* See quick_symbol_functions.  */
+  /* Expand and iterate over each "partial" symbol table in OBJFILE
+     where the source file is named NAME.
+
+     If NAME is not absolute, a match after a '/' in the symbol table's
+     file name will also work, REAL_PATH is NULL then.  If NAME is
+     absolute then REAL_PATH is non-NULL absolute file name as resolved
+     via gdb_realpath from NAME.
+
+     If a match is found, the "partial" symbol table is expanded.
+     Then, this calls iterate_over_some_symtabs (or equivalent) over
+     all newly-created symbol tables, passing CALLBACK to it.
+     The result of this call is returned.  */
   bool map_symtabs_matching_filename
     (const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback);
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index c4e484481ea..db6e85efa37 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -506,10 +506,6 @@ struct psymbol_functions : public quick_symbol_functions
 
   void forget_cached_source_info (struct objfile *objfile) override;
 
-  bool map_symtabs_matching_filename
-    (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback) override;
-
   enum language lookup_global_symbol_language (struct objfile *objfile,
 					       const char *name,
 					       domain_enum domain,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index ad7d06087d2..624c3be01ce 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -87,96 +87,6 @@ psymbol_functions::require_partial_symbols (struct objfile *objfile)
   return m_partial_symtabs->range ();
 }
 
-/* Helper function for psym_map_symtabs_matching_filename that
-   expands the symtabs and calls the iterator.  */
-
-static bool
-partial_map_expand_apply (struct objfile *objfile,
-			  const char *name,
-			  const char *real_path,
-			  struct partial_symtab *pst,
-			  gdb::function_view<bool (symtab *)> callback)
-{
-  struct compunit_symtab *last_made = objfile->compunit_symtabs;
-
-  /* Shared psymtabs should never be seen here.  Instead they should
-     be handled properly by the caller.  */
-  gdb_assert (pst->user == NULL);
-
-  /* Don't visit already-expanded psymtabs.  */
-  if (pst->readin_p (objfile))
-    return 0;
-
-  /* This may expand more than one symtab, and we want to iterate over
-     all of them.  */
-  psymtab_to_symtab (objfile, pst);
-
-  return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
-				    last_made, callback);
-}
-
-/*  Psymtab version of map_symtabs_matching_filename.  See its definition in
-    the definition of quick_symbol_functions in symfile.h.  */
-
-bool
-psymbol_functions::map_symtabs_matching_filename
-  (struct objfile *objfile,
-   const char *name,
-   const char *real_path,
-   gdb::function_view<bool (symtab *)> callback)
-{
-  const char *name_basename = lbasename (name);
-
-  for (partial_symtab *pst : require_partial_symbols (objfile))
-    {
-      /* Anonymous psymtabs don't have a file name.  */
-      if (pst->anonymous)
-	continue;
-
-      if (compare_filenames_for_search (pst->filename, name))
-	{
-	  while (pst->user)
-	    pst = pst->user;
-
-	  if (partial_map_expand_apply (objfile, name, real_path,
-					pst, callback))
-	    return true;
-	  continue;
-	}
-
-      /* Before we invoke realpath, which can get expensive when many
-	 files are involved, do a quick comparison of the basenames.  */
-      if (! basenames_may_differ
-	  && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
-	continue;
-
-      if (compare_filenames_for_search (psymtab_to_fullname (pst), name))
-	{
-	  if (partial_map_expand_apply (objfile, name, real_path,
-					pst, callback))
-	    return true;
-	  continue;
-	}
-
-      /* If the user gave us an absolute path, try to find the file in
-	 this symtab and use its absolute path.  */
-      if (real_path != NULL)
-	{
-	  gdb_assert (IS_ABSOLUTE_PATH (real_path));
-	  gdb_assert (IS_ABSOLUTE_PATH (name));
-	  if (filename_cmp (psymtab_to_fullname (pst), real_path) == 0)
-	    {
-	      if (partial_map_expand_apply (objfile, name, real_path,
-					    pst, callback))
-		return true;
-	      continue;
-	    }
-	}
-    }
-
-  return false;
-}
-
 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
    We may find a different psymtab than PST.  See FIND_PC_SECT_PSYMTAB.  */
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 4886b9e8842..6a721e08b3f 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -93,22 +93,6 @@ struct quick_symbol_functions
   /* Forget all cached full file names for OBJFILE.  */
   virtual void forget_cached_source_info (struct objfile *objfile) = 0;
 
-  /* Expand and iterate over each "partial" symbol table in OBJFILE
-     where the source file is named NAME.
-
-     If NAME is not absolute, a match after a '/' in the symbol table's
-     file name will also work, REAL_PATH is NULL then.  If NAME is
-     absolute then REAL_PATH is non-NULL absolute file name as resolved
-     via gdb_realpath from NAME.
-
-     If a match is found, the "partial" symbol table is expanded.
-     Then, this calls iterate_over_some_symtabs (or equivalent) over
-     all newly-created symbol tables, passing CALLBACK to it.
-     The result of this call is returned.  */
-  virtual bool map_symtabs_matching_filename
-    (struct objfile *objfile, const char *name, const char *real_path,
-     gdb::function_view<bool (symtab *)> callback) = 0;
-
   /* Check to see if the global symbol is defined in a "partial" symbol table
      of OBJFILE. NAME is the name of the symbol to look for.  DOMAIN
      indicates what sort of symbol to search for.
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 2a1c366ddcc..b58823ffa12 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -33,6 +33,7 @@
 #include "symtab.h"
 #include "symfile.h"
 #include "block.h"
+#include "filenames.h"
 
 /* We need to save a pointer to the real symbol functions.
    Plus, the debug versions are malloc'd because we have to NULL out the
@@ -146,13 +147,51 @@ objfile::map_symtabs_matching_filename
 		      real_path ? real_path : NULL,
 		      host_address_to_string (&callback));
 
-  bool retval = false;
+  bool retval = true;
+  const char *name_basename = lbasename (name);
+
+  auto match_one_filename = [&] (const char *filename, bool basenames)
+  {
+    if (compare_filenames_for_search (filename, name))
+      return true;
+    if (basenames && FILENAME_CMP (name_basename, filename) == 0)
+      return true;
+    if (real_path != nullptr && IS_ABSOLUTE_PATH (filename)
+	&& IS_ABSOLUTE_PATH (real_path))
+      return filename_cmp (filename, real_path) == 0;
+    return false;
+  };
+
+  compunit_symtab *last_made = this->compunit_symtabs;
+
+  auto on_expansion = [&] (compunit_symtab *symtab)
+  {
+    /* The callback to iterate_over_some_symtabs returns false to keep
+       going and true to continue, so we have to invert the result
+       here, for expand_symtabs_matching.  */
+    bool result = !iterate_over_some_symtabs (name, real_path,
+					      this->compunit_symtabs,
+					      last_made,
+					      callback);
+    last_made = this->compunit_symtabs;
+    return result;
+  };
+
   for (const auto &iter : qf)
     {
-      retval = (iter->map_symtabs_matching_filename
-		(this, name, real_path, callback));
-      if (retval)
-	break;
+      if (!iter->expand_symtabs_matching (this,
+					  match_one_filename,
+					  nullptr,
+					  nullptr,
+					  on_expansion,
+					  (SEARCH_GLOBAL_BLOCK
+					   | SEARCH_STATIC_BLOCK),
+					  UNDEF_DOMAIN,
+					  ALL_DOMAIN))
+	{
+	  retval = false;
+	  break;
+	}
     }
 
   if (debug_symfile)
@@ -160,7 +199,9 @@ objfile::map_symtabs_matching_filename
 		      "qf->map_symtabs_matching_filename (...) = %d\n",
 		      retval);
 
-  return retval;
+  /* We must re-invert the return value here to match the caller's
+     expectations.  */
+  return !retval;
 }
 
 struct compunit_symtab *
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/9] Remove quick_symbol_functions::expand_symtabs_for_function
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (5 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 6/9] Remove quick_symbol_functions::map_symtabs_matching_filename Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 8/9] Remove quick_symbol_functions::expand_symtabs_with_fullname Tom Tromey
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes quick_symbol_functions::expand_symtabs_for_function,
replacing it with a call to expand_symtabs_matching.  As with the
previous patches, the implementation is consolidated in the objfile
method.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::expand_symtabs_for_function):
	Rewrite.
	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_for_function>: Remove.
	* psymtab.c (psymbol_functions::expand_symtabs_for_function):
	Remove.
	* psympriv.h (struct psymbol_functions)
	<expand_symtabs_for_function>: Remove.
	* objfiles.h (struct objfile) <expand_symtabs_for_function>:
	Update comment.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_for_function>: Remove.
	(struct dwarf2_debug_names_index) <expand_symtabs_for_function>:
	Remove.
	(find_slot_in_mapped_hash): Remove.
	(dw2_symtab_iter_init_common): Merge with dw2_symtab_iter_init.
	(dw2_symtab_iter_init): Remove one overload.
	(dwarf2_gdb_index::expand_symtabs_for_function)
	(dwarf2_debug_names_index::expand_symtabs_for_function): Remove.
---
 gdb/ChangeLog       |  22 +++++++
 gdb/dwarf2/read.c   | 148 ++------------------------------------------
 gdb/objfiles.h      |   3 +-
 gdb/psympriv.h      |   3 -
 gdb/psymtab.c       |  23 -------
 gdb/quick-symbol.h  |   5 --
 gdb/symfile-debug.c |  13 +++-
 7 files changed, 41 insertions(+), 176 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8d5ef85f15b..09529cf535c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2234,9 +2234,6 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-				    const char *func_name) override;
-
   void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
@@ -2260,9 +2257,6 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-				    const char *func_name) override;
-
   void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
@@ -2910,68 +2904,6 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 						 &per_bfd->obstack);
 }
 
-/* Find a slot in the mapped index INDEX for the object named NAME.
-   If NAME is found, set *VEC_OUT to point to the CU vector in the
-   constant pool and return true.  If NAME cannot be found, return
-   false.  */
-
-static bool
-find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
-			  offset_type **vec_out)
-{
-  offset_type hash;
-  offset_type slot, step;
-  int (*cmp) (const char *, const char *);
-
-  gdb::unique_xmalloc_ptr<char> without_params;
-  if (current_language->la_language == language_cplus
-      || current_language->la_language == language_fortran
-      || current_language->la_language == language_d)
-    {
-      /* NAME is already canonical.  Drop any qualifiers as .gdb_index does
-	 not contain any.  */
-
-      if (strchr (name, '(') != NULL)
-	{
-	  without_params = cp_remove_params (name);
-
-	  if (without_params != NULL)
-	    name = without_params.get ();
-	}
-    }
-
-  /* Index version 4 did not support case insensitive searches.  But the
-     indices for case insensitive languages are built in lowercase, therefore
-     simulate our NAME being searched is also lowercased.  */
-  hash = mapped_index_string_hash ((index->version == 4
-				    && case_sensitivity == case_sensitive_off
-				    ? 5 : index->version),
-				   name);
-
-  slot = hash & (index->symbol_table.size () - 1);
-  step = ((hash * 17) & (index->symbol_table.size () - 1)) | 1;
-  cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
-
-  for (;;)
-    {
-      const char *str;
-
-      const auto &bucket = index->symbol_table[slot];
-      if (bucket.name == 0 && bucket.vec == 0)
-	return false;
-
-      str = index->constant_pool + MAYBE_SWAP (bucket.name);
-      if (!cmp (name, str))
-	{
-	  *vec_out = (offset_type *) (index->constant_pool
-				      + MAYBE_SWAP (bucket.vec));
-	  return true;
-	}
-
-      slot = (slot + step) & (index->symbol_table.size () - 1);
-    }
-}
-
 /* A helper function that reads the .gdb_index from BUFFER and fills
    in MAP.  FILENAME is the name of the file containing the data;
    it is used for error reporting.  DEPRECATED_OK is true if it is
@@ -3373,13 +3305,13 @@ struct dw2_symtab_iterator
   int global_seen;
 };
 
-/* Initialize the index symtab iterator ITER, common part.  */
+/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
 
 static void
-dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
-			     dwarf2_per_objfile *per_objfile,
-			     gdb::optional<block_enum> block_index,
-			     domain_enum domain)
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+		      dwarf2_per_objfile *per_objfile,
+		      gdb::optional<block_enum> block_index,
+		      domain_enum domain, offset_type namei)
 {
   iter->per_objfile = per_objfile;
   iter->block_index = block_index;
@@ -3388,37 +3320,6 @@ dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
   iter->global_seen = 0;
   iter->vec = NULL;
   iter->length = 0;
-}
-
-/* Initialize the index symtab iterator ITER, const char *NAME variant.  */
-
-static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-		      dwarf2_per_objfile *per_objfile,
-		      gdb::optional<block_enum> block_index,
-		      domain_enum domain,
-		      const char *name)
-{
-  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
-
-  mapped_index *index = per_objfile->per_bfd->index_table.get ();
-  /* index is NULL if OBJF_READNOW.  */
-  if (index == NULL)
-    return;
-
-  if (find_slot_in_mapped_hash (index, name, &iter->vec))
-    iter->length = MAYBE_SWAP (*iter->vec);
-}
-
-/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
-
-static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-		      dwarf2_per_objfile *per_objfile,
-		      gdb::optional<block_enum> block_index,
-		      domain_enum domain, offset_type namei)
-{
-  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
 
   mapped_index *index = per_objfile->per_bfd->index_table.get ();
   /* index is NULL if OBJF_READNOW.  */
@@ -3575,22 +3476,6 @@ dwarf2_gdb_index::dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-void
-dwarf2_gdb_index::expand_symtabs_for_function (struct objfile *objfile,
-					       const char *func_name)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  struct dw2_symtab_iterator iter;
-  struct dwarf2_per_cu_data *per_cu;
-
-  dw2_symtab_iter_init (&iter, per_objfile, {}, VAR_DOMAIN, func_name);
-
-  while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-    dw2_instantiate_symtab (per_cu, per_objfile, false);
-
-}
-
 void
 dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
 {
@@ -5659,29 +5544,6 @@ dwarf2_debug_names_index::dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-void
-dwarf2_debug_names_index::expand_symtabs_for_function
-     (struct objfile *objfile, const char *func_name)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW.  */
-  if (per_objfile->per_bfd->debug_names_table)
-    {
-      const mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
-
-      dw2_debug_names_iterator iter (map,
-				     (SEARCH_GLOBAL_BLOCK
-				      | SEARCH_STATIC_BLOCK),
-				     VAR_DOMAIN, func_name,
-				     per_objfile);
-
-      struct dwarf2_per_cu_data *per_cu;
-      while ((per_cu = iter.next ()) != NULL)
-	dw2_instantiate_symtab (per_cu, per_objfile, false);
-    }
-}
-
 void
 dwarf2_debug_names_index::map_matching_symbols
   (struct objfile *objfile,
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 06628e38e88..4a170415ece 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -578,7 +578,8 @@ struct objfile
   /* See quick_symbol_functions.  */
   void dump ();
 
-  /* See quick_symbol_functions.  */
+  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
+     the corresponding symbol tables are loaded.  */
   void expand_symtabs_for_function (const char *func_name);
 
   /* See quick_symbol_functions.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index db6e85efa37..a400bc85f41 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -515,9 +515,6 @@ struct psymbol_functions : public quick_symbol_functions
 
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-				    const char *func_name) override;
-
   void expand_all_symtabs (struct objfile *objfile) override;
 
   void expand_symtabs_with_fullname (struct objfile *objfile,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 624c3be01ce..8205dbc2923 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -892,29 +892,6 @@ psymbol_functions::dump (struct objfile *objfile)
     }
 }
 
-/* Psymtab version of expand_symtabs_for_function.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-void
-psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
-						const char *func_name)
-{
-  lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
-  lookup_name_info lookup_name = base_lookup.make_ignore_params ();
-
-  for (partial_symtab *ps : require_partial_symbols (objfile))
-    {
-      if (ps->readin_p (objfile))
-	continue;
-
-      if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN)
-	   != NULL)
-	  || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN)
-	      != NULL))
-	psymtab_to_symtab (objfile, ps);
-    }
-}
-
 /* Psymtab version of expand_all_symtabs.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 6a721e08b3f..50bcf397e2e 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -116,11 +116,6 @@ struct quick_symbol_functions
      gdb_stdout.  This is used for "maint print objfiles".  */
   virtual void dump (struct objfile *objfile) = 0;
 
-  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
-     the corresponding symbol tables are loaded.  */
-  virtual void expand_symtabs_for_function (struct objfile *objfile,
-					    const char *func_name) = 0;
-
   /* Read all symbol tables associated with OBJFILE.  */
   virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index b58823ffa12..97e806b659f 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -300,8 +300,19 @@ objfile::expand_symtabs_for_function (const char *func_name)
 		      "qf->expand_symtabs_for_function (%s, \"%s\")\n",
 		      objfile_debug_name (this), func_name);
 
+  lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
+  lookup_name_info lookup_name = base_lookup.make_ignore_params ();
+
   for (const auto &iter : qf)
-    iter->expand_symtabs_for_function (this, func_name);
+    iter->expand_symtabs_matching (this,
+				   nullptr,
+				   &lookup_name,
+				   nullptr,
+				   nullptr,
+				   (SEARCH_GLOBAL_BLOCK
+				    | SEARCH_STATIC_BLOCK),
+				   VAR_DOMAIN,
+				   ALL_DOMAIN);
 }
 
 void
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/9] Remove quick_symbol_functions::expand_symtabs_with_fullname
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (6 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 7/9] Remove quick_symbol_functions::expand_symtabs_for_function Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-03-25 17:04 ` [PATCH 9/9] Simplify quick_symbol_functions::map_matching_symbols Tom Tromey
  2021-04-17 15:38 ` [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes quick_symbol_functions::expand_symtabs_with_fullname,
replacing it with a call to expand_symtabs_matching.  As with the
previous patches, the implementation is consolidated in the objfile
method.

gdb/ChangeLog
2021-03-25  Tom Tromey  <tom@tromey.com>

	* quick-symbol.h (struct quick_symbol_functions)
	<expand_symtabs_with_fullname>: Remove.
	* psymtab.c (psymbol_functions::expand_symtabs_with_fullname):
	Remove.
	* psympriv.h (struct psymbol_functions)
	<expand_symtabs_with_fullname>: Remove.
	* dwarf2/read.c (struct dwarf2_base_index_functions)
	<expand_symtabs_with_fullname>: Remove.
	(dwarf2_base_index_functions::expand_symtabs_with_fullname):
	Remove.
	* objfiles.h (struct objfile) <expand_symtabs_with_fullname>:
	Update comment.
	* symfile-debug.c (objfile::expand_symtabs_with_fullname):
	Rewrite.
---
 gdb/ChangeLog       | 17 +++++++++++++++++
 gdb/dwarf2/read.c   | 37 -------------------------------------
 gdb/objfiles.h      |  6 +++++-
 gdb/psympriv.h      |  3 ---
 gdb/psymtab.c       | 22 ----------------------
 gdb/quick-symbol.h  |  8 --------
 gdb/symfile-debug.c | 16 +++++++++++++++-
 7 files changed, 37 insertions(+), 72 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 09529cf535c..498e34b097d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2212,9 +2212,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
-  void expand_symtabs_with_fullname (struct objfile *objfile,
-				     const char *fullname) override;
-
   struct compunit_symtab *find_pc_sect_compunit_symtab
     (struct objfile *objfile, struct bound_minimal_symbol msymbol,
      CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override;
@@ -3496,40 +3493,6 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
     }
 }
 
-void
-dwarf2_base_index_functions::expand_symtabs_with_fullname
-     (struct objfile *objfile, const char *fullname)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  /* We don't need to consider type units here.
-     This is only called for examining code, e.g. expand_line_sal.
-     There can be an order of magnitude (or more) more type units
-     than comp units, and we avoid them if we can.  */
-
-  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
-    {
-      /* We only need to look at symtabs not already expanded.  */
-      if (per_objfile->symtab_set_p (per_cu))
-	continue;
-
-      quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
-      if (file_data == NULL)
-	continue;
-
-      for (int j = 0; j < file_data->num_file_names; ++j)
-	{
-	  const char *this_fullname = file_data->file_names[j];
-
-	  if (filename_cmp (this_fullname, fullname) == 0)
-	    {
-	      dw2_instantiate_symtab (per_cu, per_objfile, false);
-	      break;
-	    }
-	}
-    }
-}
-
 static bool
 dw2_expand_symtabs_matching_symbol
   (mapped_index_base &index,
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 4a170415ece..264e783c76e 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -585,7 +585,11 @@ struct objfile
   /* See quick_symbol_functions.  */
   void expand_all_symtabs ();
 
-  /* See quick_symbol_functions.  */
+  /* Read all symbol tables associated with OBJFILE which have
+     symtab_to_fullname equal to FULLNAME.
+     This is for the purposes of examining code only, e.g., expand_line_sal.
+     The routine may ignore debug info that is known to not be useful with
+     code, e.g., DW_TAG_type_unit for dwarf debug info.  */
   void expand_symtabs_with_fullname (const char *fullname);
 
   /* See quick_symbol_functions.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index a400bc85f41..664f14b45d5 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -517,9 +517,6 @@ struct psymbol_functions : public quick_symbol_functions
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
-  void expand_symtabs_with_fullname (struct objfile *objfile,
-				     const char *fullname) override;
-
   void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 8205dbc2923..f35a9f1dca2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -902,28 +902,6 @@ psymbol_functions::expand_all_symtabs (struct objfile *objfile)
     psymtab_to_symtab (objfile, psymtab);
 }
 
-/* Psymtab version of expand_symtabs_with_fullname.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-void
-psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile,
-						 const char *fullname)
-{
-  for (partial_symtab *p : require_partial_symbols (objfile))
-    {
-      /* Anonymous psymtabs don't have a name of a source file.  */
-      if (p->anonymous)
-	continue;
-
-      /* psymtab_to_fullname tries to open the file which is slow.
-	 Don't call it if we know the basenames don't match.  */
-      if ((basenames_may_differ
-	   || filename_cmp (lbasename (fullname), lbasename (p->filename)) == 0)
-	  && filename_cmp (fullname, psymtab_to_fullname (p)) == 0)
-	psymtab_to_symtab (objfile, p);
-    }
-}
-
 /* Psymtab version of map_symbol_filenames.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 50bcf397e2e..064922a3b66 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -119,14 +119,6 @@ struct quick_symbol_functions
   /* Read all symbol tables associated with OBJFILE.  */
   virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
-  /* Read all symbol tables associated with OBJFILE which have
-     symtab_to_fullname equal to FULLNAME.
-     This is for the purposes of examining code only, e.g., expand_line_sal.
-     The routine may ignore debug info that is known to not be useful with
-     code, e.g., DW_TAG_type_unit for dwarf debug info.  */
-  virtual void expand_symtabs_with_fullname (struct objfile *objfile,
-					     const char *fullname) = 0;
-
   /* Find global or static symbols in all tables that are in DOMAIN
      and for which MATCH (symbol name, NAME) == 0, passing each to 
      CALLBACK, reading in partial symbol tables as needed.  Look
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 97e806b659f..7addb85453f 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -334,8 +334,22 @@ objfile::expand_symtabs_with_fullname (const char *fullname)
 		      "qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
 		      objfile_debug_name (this), fullname);
 
+  const char *basename = lbasename (fullname);
+  auto file_matcher = [&] (const char *filename, bool basenames)
+  {
+    return filename_cmp (basenames ? basename : fullname, filename) == 0;
+  };
+
   for (const auto &iter : qf)
-    iter->expand_symtabs_with_fullname (this, fullname);
+    iter->expand_symtabs_matching (this,
+				   file_matcher,
+				   nullptr,
+				   nullptr,
+				   nullptr,
+				   (SEARCH_GLOBAL_BLOCK
+				    | SEARCH_STATIC_BLOCK),
+				   UNDEF_DOMAIN,
+				   ALL_DOMAIN);
 }
 
 void
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 9/9] Simplify quick_symbol_functions::map_matching_symbols
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (7 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 8/9] Remove quick_symbol_functions::expand_symtabs_with_fullname Tom Tromey
@ 2021-03-25 17:04 ` Tom Tromey
  2021-04-17 15:38 ` [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-03-25 17:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

quick_symbol_functions::map_matching_symbols is only used by the Ada
code.  Currently, it both expands certain psymtabs and then walks over
the full symtabs -- including any already-expanded ones -- calling a
callback.

It appears to work lazily as well, in that if the callback returns
false, iteration stops.  However, only the psymtab implementation does
this; the DWARF index implementations are not lazy.  It turns out,
though, that the only callback that is ever passed here never returns
false.

This patch simplifies this method by removing the callback.  The
method is also renamed.  In the new scheme, the caller is responsible
for walking the full symtabs, which removes some redundancy as well.

gdb/ChangeLog
2021-03-25  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymbol_functions::expand_matching_symbols): Rename
	from map_matching_symbols.  Change parameters.
	* psympriv.h (struct psymbol_functions) <expand_matching_symbols>:
	Rename from map_matching_symbols.  Change parameters.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_matching_symbols>: Rename from map_matching_symbols.
	Change parameters.
	(struct dwarf2_debug_names_index) <expand_matching_symbols>:
	Rename from map_matching_symbols.  Change parameters.
	(dwarf2_gdb_index::expand_matching_symbols): Rename from
	dw2_map_matching_symbols.  Change parameters.
	(dwarf2_gdb_index::expand_matching_symbols): Remove old
	implementation.
	(dwarf2_debug_names_index::expand_matching_symbols): Rename from
	map_matching_symbols.  Change parameters.
	* objfiles.h (struct objfile) <expand_matching_symbols>: Rename
	from map_matching_symbols.  Change parameters.
	* symfile-debug.c (objfile::expand_matching_symbols): Rename from
	map_matching_symbols.  Change parameters.
	* ada-lang.c (map_matching_symbols): New function.
	(add_nonlocal_symbols): Update.
---
 gdb/ChangeLog       | 24 +++++++++++++++++++
 gdb/ada-lang.c      | 51 +++++++++++++++++++++++++++++------------
 gdb/dwarf2/read.c   | 56 ++++-----------------------------------------
 gdb/objfiles.h      |  3 +--
 gdb/psympriv.h      |  3 +--
 gdb/psymtab.c       | 23 ++++---------------
 gdb/quick-symbol.h  | 15 +++++-------
 gdb/symfile-debug.c |  9 ++++----
 8 files changed, 82 insertions(+), 102 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f529d842f90..7e50ab08313 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5180,6 +5180,38 @@ ada_lookup_name (const lookup_name_info &lookup_name)
   return lookup_name.ada ().lookup_name ().c_str ();
 }
 
+/* A helper for add_nonlocal_symbols.  Call expand_matching_symbols
+   for OBJFILE, then walk the objfile's symtabs and update the
+   results.  */
+
+static void
+map_matching_symbols (struct objfile *objfile,
+		      const lookup_name_info &lookup_name,
+		      bool is_wild_match,
+		      domain_enum domain,
+		      int global,
+		      match_data *data)
+{
+  data->objfile = objfile;
+  objfile->expand_matching_symbols (lookup_name, domain, global,
+				    is_wild_match ? nullptr : compare_names);
+
+  auto callback = [&] (struct block_symbol *bsym)
+    {
+      return aux_add_nonlocal_symbols (bsym, data);
+    };
+
+  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+  for (compunit_symtab *symtab : objfile->compunits ())
+    {
+      const struct block *block
+	= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind);
+      if (!iterate_over_symbols_terminated (block, lookup_name,
+					    domain, callback))
+	break;
+    }
+}
+
 /* Add to RESULT all non-local symbols whose name and domain match
    LOOKUP_NAME and DOMAIN respectively.  The search is performed on
    GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK
@@ -5194,17 +5226,10 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
-  auto callback = [&] (struct block_symbol *bsym)
-    {
-      return aux_add_nonlocal_symbols (bsym, &data);
-    };
-
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      data.objfile = objfile;
-
-      objfile->map_matching_symbols (lookup_name, domain, global, callback,
-				     is_wild_match ? NULL : compare_names);
+      map_matching_symbols (objfile, lookup_name, is_wild_match, domain,
+			    global, &data);
 
       for (compunit_symtab *cu : objfile->compunits ())
 	{
@@ -5224,12 +5249,8 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
       lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL);
 
       for (objfile *objfile : current_program_space->objfiles ())
-	{
-	  data.objfile = objfile;
-	  objfile->map_matching_symbols (name1, domain, global, callback,
-					 compare_names);
-	}
-    }      	
+	map_matching_symbols (objfile, name1, false, domain, global, &data);
+    }
 }
 
 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 498e34b097d..3088dbd0d17 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2231,12 +2231,11 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
@@ -2254,12 +2253,11 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
@@ -3508,12 +3506,11 @@ dw2_expand_symtabs_matching_one
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify);
 
-static void
-dw2_map_matching_symbols
+void
+dwarf2_gdb_index::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   /* Used for Ada.  */
@@ -3552,30 +3549,6 @@ dw2_map_matching_symbols
       /* We have -readnow: no .gdb_index, but no partial symtabs either.  So,
 	 proceed assuming all symtabs have been read in.  */
     }
-
-  for (compunit_symtab *cust : objfile->compunits ())
-    {
-      const struct block *block;
-
-      if (cust == NULL)
-	continue;
-      block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-      if (!iterate_over_symbols_terminated (block, name,
-					    domain, callback))
-	return;
-    }
-}
-
-void
-dwarf2_gdb_index::map_matching_symbols
-  (struct objfile *objfile,
-   const lookup_name_info &name, domain_enum domain,
-   int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
-   symbol_compare_ftype *ordered_compare)
-{
-  dw2_map_matching_symbols (objfile, name, domain, global, callback,
-			    ordered_compare);
 }
 
 /* Starting from a search name, return the string that finds the upper
@@ -5508,11 +5481,10 @@ dwarf2_debug_names_index::dump (struct objfile *objfile)
 }
 
 void
-dwarf2_debug_names_index::map_matching_symbols
+dwarf2_debug_names_index::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -5522,7 +5494,6 @@ dwarf2_debug_names_index::map_matching_symbols
     return;
 
   mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
-  const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
   const block_search_flags block_flags
     = global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK;
 
@@ -5548,23 +5519,6 @@ dwarf2_debug_names_index::map_matching_symbols
 					 nullptr);
       return true;
     }, per_objfile);
-
-  /* It's a shame we couldn't do this inside the
-     dw2_expand_symtabs_matching_symbol callback, but that skips CUs
-     that have already been expanded.  Instead, this loop matches what
-     the psymtab code does.  */
-  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
-    {
-      compunit_symtab *symtab = per_objfile->get_symtab (per_cu);
-      if (symtab != nullptr)
-	{
-	  const struct block *block
-	    = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind);
-	  if (!iterate_over_symbols_terminated (block, name,
-						domain, callback))
-	    break;
-	}
-    }
 }
 
 bool
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 264e783c76e..cc33fdfbd6d 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -593,10 +593,9 @@ struct objfile
   void expand_symtabs_with_fullname (const char *fullname);
 
   /* See quick_symbol_functions.  */
-  void map_matching_symbols
+  void expand_matching_symbols
     (const lookup_name_info &name, domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare);
 
   /* See quick_symbol_functions.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 664f14b45d5..424566a1736 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -517,12 +517,11 @@ struct psymbol_functions : public quick_symbol_functions
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index f35a9f1dca2..1477ffc9b3e 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -979,36 +979,23 @@ psymtab_to_fullname (struct partial_symtab *ps)
   return ps->fullname;
 }
 
-/* Psymtab version of map_matching_symbols.  See its definition in
+/* Psymtab version of expand_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 void
-psymbol_functions::map_matching_symbols
+psymbol_functions::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
-  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
-
   for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       QUIT;
-      if (ps->readin_p (objfile)
-	  || match_partial_symbol (objfile, ps, global, name, domain,
+      if (!ps->readin_p (objfile)
+	  && match_partial_symbol (objfile, ps, global, name, domain,
 				   ordered_compare))
-	{
-	  struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps);
-	  const struct block *block;
-
-	  if (cust == NULL)
-	    continue;
-	  block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-	  if (!iterate_over_symbols_terminated (block, name,
-						domain, callback))
-	    return;
-	}
+	psymtab_to_symtab (objfile, ps);
     }
 }
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 064922a3b66..d8b6e636103 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -120,11 +120,10 @@ struct quick_symbol_functions
   virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
   /* Find global or static symbols in all tables that are in DOMAIN
-     and for which MATCH (symbol name, NAME) == 0, passing each to 
-     CALLBACK, reading in partial symbol tables as needed.  Look
-     through global symbols if GLOBAL and otherwise static symbols.
-     Passes NAME and NAMESPACE to CALLBACK with each symbol
-     found.  After each block is processed, passes NULL to CALLBACK.
+     and for which MATCH (symbol name, NAME) == 0, reading in partial
+     symbol tables as needed.  Look through global symbols if GLOBAL
+     and otherwise static symbols.
+
      MATCH must be weaker than strcmp_iw_ordered in the sense that
      strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE,
      if non-null, must be an ordering relation compatible with
@@ -133,15 +132,13 @@ struct quick_symbol_functions
      and 
 	    strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
      (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
-     CALLBACK returns true to indicate that the scan should continue, or
-     false to indicate that the scan should be terminated.  */
+  */
 
-  virtual void map_matching_symbols
+  virtual void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) = 0;
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 7addb85453f..447483779e4 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -353,22 +353,21 @@ objfile::expand_symtabs_with_fullname (const char *fullname)
 }
 
 void
-objfile::map_matching_symbols
+objfile::expand_matching_symbols
   (const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
-		      "qf->map_matching_symbols (%s, %s, %d, %s)\n",
+		      "qf->expand_matching_symbols (%s, %s, %d, %s)\n",
 		      objfile_debug_name (this),
 		      domain_name (domain), global,
 		      host_address_to_string (ordered_compare));
 
   for (const auto &iter : qf)
-    iter->map_matching_symbols (this, name, domain, global,
-				callback, ordered_compare);
+    iter->expand_matching_symbols (this, name, domain, global,
+				   ordered_compare);
 }
 
 bool
-- 
2.26.2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/9] Simplify quick_symbol_functions
  2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
                   ` (8 preceding siblings ...)
  2021-03-25 17:04 ` [PATCH 9/9] Simplify quick_symbol_functions::map_matching_symbols Tom Tromey
@ 2021-04-17 15:38 ` Tom Tromey
  9 siblings, 0 replies; 11+ messages in thread
From: Tom Tromey @ 2021-04-17 15:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> I have been looking at writing a new implementation of
Tom> quick_symbol_functions, and while doing so I was reminded that there
Tom> is some redundancy in these methods.
...
Tom> This series removes the map_symtabs_matching_filename,
Tom> expand_symtabs_for_function, and lookup_symbol calls, in favor of
Tom> slightly expanding expand_symtabs_matching and using that.
...
Tom> Regression tested on x86-64 Fedora 32.

I've rebased this (no changes needed) and re-tested it.
I'm checking it in now.

Tom

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-04-17 15:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 17:04 [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey
2021-03-25 17:04 ` [PATCH 1/9] Add block_search_flags Tom Tromey
2021-03-25 17:04 ` [PATCH 2/9] Let expand_symtabs_matching short-circuit Tom Tromey
2021-03-25 17:04 ` [PATCH 3/9] Add search_flags to expand_symtabs_matching Tom Tromey
2021-03-25 17:04 ` [PATCH 4/9] Add 'domain' parameter " Tom Tromey
2021-03-25 17:04 ` [PATCH 5/9] Remove quick_symbol_functions::lookup_symbol Tom Tromey
2021-03-25 17:04 ` [PATCH 6/9] Remove quick_symbol_functions::map_symtabs_matching_filename Tom Tromey
2021-03-25 17:04 ` [PATCH 7/9] Remove quick_symbol_functions::expand_symtabs_for_function Tom Tromey
2021-03-25 17:04 ` [PATCH 8/9] Remove quick_symbol_functions::expand_symtabs_with_fullname Tom Tromey
2021-03-25 17:04 ` [PATCH 9/9] Simplify quick_symbol_functions::map_matching_symbols Tom Tromey
2021-04-17 15:38 ` [PATCH 0/9] Simplify quick_symbol_functions Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).