Add search_flags to expand_symtabs_matching
authorTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:04 +0000 (09:35 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:05 +0000 (09:35 -0600)
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.

gdb/ChangeLog
2021-04-17  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.

14 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/dwarf2/read.c
gdb/linespec.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/python/py-symbol.c
gdb/quick-symbol.h
gdb/symfile-debug.c
gdb/symfile.c
gdb/symfile.h
gdb/symmisc.c
gdb/symtab.c

index f1d21931751833989b9de73565379fdbb6ef4a7d..3d27f68b93c1309b365c3cdad386b2f2deb7080e 100644 (file)
@@ -1,3 +1,45 @@
+2021-04-17  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.
+
 2021-04-17  Tom Tromey  <tom@tromey.com>
 
        * symtab.c (default_collect_symbol_completion_matches_break_on):
index f7860f27bfc019b5eb384088669a0f8943b2b743..589fbf1a0c49f3dac17b5956c69177d0374d66dd 100644 (file)
@@ -12516,6 +12516,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 ())
@@ -13032,6 +13033,7 @@ public:
                             lookup_name,
                             NULL,
                             NULL,
+                            SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
                             ALL_DOMAIN);
 
     /* At this point scan through the misc symbol vectors and add each
index b1604a13fc2d320922b8faf018be568cb0d32004..824945a95bcd79a80765b15a1639bcece68df21a 100644 (file)
@@ -2289,6 +2289,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;
 };
 
@@ -2318,6 +2319,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;
 };
 
@@ -4699,6 +4701,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;
@@ -4738,6 +4741,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:
@@ -4863,6 +4877,7 @@ 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)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
@@ -4895,7 +4910,7 @@ dwarf2_gdb_index::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);
@@ -5373,7 +5388,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),
@@ -5382,7 +5397,8 @@ public:
   {}
 
   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)),
@@ -5390,7 +5406,7 @@ public:
   {}
 
   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)),
@@ -5411,9 +5427,9 @@ private:
   /* 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;
@@ -5662,13 +5678,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
@@ -5783,7 +5804,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;
@@ -5845,7 +5870,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;
@@ -5870,6 +5898,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)
@@ -5884,7 +5914,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;
@@ -5919,6 +5949,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);
index 4034bbab8a0d35ac2513c1bd5cf25128ecd4d194..f37861b343ae8ff4742584a2b3e43ff9742a2779 100644 (file)
@@ -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 ())
index fd3323fef07d47734f226e9990d304c03b6c223e..9a194c1d8d47e7b08a7da618bf098e674bc714e9 100644 (file)
@@ -608,6 +608,7 @@ public:
      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.  */
index 51b02f586bb3779b893883e09ce5b69052cf76a4..70a397f8167b0b31c159a75e6bfe9b03df7ebb04 100644 (file)
@@ -547,6 +547,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
index 6e7bf240a39880afda10cfe1a40d97c2c5c298cd..c346116829432879f8478a046d78b846d3a6a89f 100644 (file)
@@ -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))
        {
index 25b6488f1be227baa4ee28a2ef08665d60a95160..ead26d5d441a18ad5aa7f8d8d41427b70b198c5d 100644 (file)
@@ -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 ())
        {
index 37601d8afbd6f4f1a6619bcc85871b9573959d42..3332d329e0230cd81ee9a9c3a71d436819a1ca0f 100644 (file)
@@ -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
index eff2e3aa3371ba6fb7697af747a637a0198eed8a..b1763243534f3c0eba7ee3c6011999ee5b62c33e 100644 (file)
@@ -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;
 }
index 3e8859916afaa73c8dad590c34a533482cc55ce9..5f83cbf67c8ff0dbf22429eb1cf4ccad3612b537 100644 (file)
@@ -3722,13 +3722,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;
 }
index 56fc37910fb42a0a9a7afaf8fcea9901a38b3a04..22b091182aaabb17d9deb2ca7eda3babf9d67be2 100644 (file)
@@ -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 (gdb::function_view<symbol_filename_ftype> fun,
index 9ea5cb55d0f7c5590a3672a684291b5a2692fcb0..33657f88fa9e0dddcd6f42a295326425fec453e3 100644 (file)
@@ -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
index 907ebd0398457de9b62d3eb35666a70ec76eeedc..a34207fc74bb1ef8821901d1e95ba0a56d9339d4 100644 (file)
@@ -4547,6 +4547,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
@@ -5732,6 +5733,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