[3/9] Add search_flags to expand_symtabs_matching

Message ID 20210325170458.2351251-4-tom@tromey.com
State New
Headers show
Series
  • Simplify quick_symbol_functions
Related show

Commit Message

Tom Tromey March 25, 2021, 5:04 p.m.
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(-)

-- 
2.26.2

Patch

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);
 }
 
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