]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove dwarf2_per_cu_data::mark
authorTom Tromey <tom@tromey.com>
Sat, 7 Dec 2024 22:51:24 +0000 (15:51 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 10 Sep 2025 22:05:28 +0000 (16:05 -0600)
This removes dwarf2_per_cu_data::mark, replacing it with a
locally-allocated boolean vector.  It also inverts the sense of the
flag -- now, the flag is true when a CU should be skipped, and false
when the CU should be further examined.  Also, the validity of the
flag is no longer dependent on 'file_matcher != NULL'.

This patch makes the subsequent patch to searching a bit simpler, so
I've separated it out.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
Acked-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/read-gdb-index.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index beeaa40e56896e8e0f665c6b0d9e66b58c3782a5..29f6d59ca2b1de2d4b5838e9267532c11f871291 100644 (file)
@@ -1029,11 +1029,12 @@ dwarf2_gdb_index::dump (struct objfile *objfile)
 }
 
 /* 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.  */
+   matched, to expand corresponding CUs (unless the CU is to be
+   skipped).  IDX is the index of the symbol name that matched.  */
 
 static bool
 dw2_expand_marked_cus (dwarf2_per_objfile *per_objfile, offset_type idx,
+                      auto_bool_vector &cus_to_skip,
                       expand_symtabs_file_matcher file_matcher,
                       expand_symtabs_expansion_listener expansion_notify,
                       block_search_flags search_flags,
@@ -1117,8 +1118,9 @@ dw2_expand_marked_cus (dwarf2_per_objfile *per_objfile, offset_type idx,
 
       dwarf2_per_cu *per_cu = index.units[cu_index];
 
-      if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-                                           expansion_notify, lang_matcher))
+      if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, cus_to_skip,
+                                           file_matcher, expansion_notify,
+                                           lang_matcher))
        return false;
     }
 
@@ -1138,7 +1140,9 @@ dwarf2_gdb_index::expand_symtabs_matching
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
+  auto_bool_vector cus_to_skip;
+  dw_expand_symtabs_matching_file_matcher (per_objfile, cus_to_skip,
+                                          file_matcher);
 
   /* This invariant is documented in quick-functions.h.  */
   gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
@@ -1149,7 +1153,7 @@ dwarf2_gdb_index::expand_symtabs_matching
          QUIT;
 
          if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
-                                               file_matcher,
+                                               cus_to_skip, file_matcher,
                                                expansion_notify,
                                                lang_matcher))
            return false;
@@ -1166,7 +1170,7 @@ dwarf2_gdb_index::expand_symtabs_matching
                                          symbol_matcher,
                                          [&] (offset_type idx)
     {
-      if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
+      if (!dw2_expand_marked_cus (per_objfile, idx, cus_to_skip, file_matcher,
                                  expansion_notify, search_flags, domain,
                                  lang_matcher))
        return false;
index 69b1330bdf46f9183c4c86ce7635ed4f7bad5c58..2487acaf3f8b3494b09d68f8f6c5ebd7801a5b3b 100644 (file)
@@ -1974,11 +1974,13 @@ bool
 dw2_expand_symtabs_matching_one
   (dwarf2_per_cu *per_cu,
    dwarf2_per_objfile *per_objfile,
+   auto_bool_vector &cus_to_skip,
    expand_symtabs_file_matcher file_matcher,
    expand_symtabs_expansion_listener expansion_notify,
    expand_symtabs_lang_matcher lang_matcher)
 {
-  if (file_matcher != nullptr && !per_cu->mark)
+  /* Already visited, or intentionally skipped.  */
+  if (cus_to_skip.is_set (per_cu->index))
     return true;
 
   if (lang_matcher != nullptr)
@@ -2005,7 +2007,9 @@ dw2_expand_symtabs_matching_one
 
 void
 dw_expand_symtabs_matching_file_matcher
-  (dwarf2_per_objfile *per_objfile, expand_symtabs_file_matcher file_matcher)
+  (dwarf2_per_objfile *per_objfile,
+   auto_bool_vector &cus_to_skip,
+   expand_symtabs_file_matcher file_matcher)
 {
   if (file_matcher == NULL)
     return;
@@ -2021,54 +2025,57 @@ dw_expand_symtabs_matching_file_matcher
       QUIT;
 
       if (per_cu->is_debug_types)
-       continue;
-      per_cu->mark = 0;
+       {
+         cus_to_skip.set (per_cu->index, true);
+         continue;
+       }
 
       /* We only need to look at symtabs not already expanded.  */
       if (per_objfile->symtab_set_p (per_cu.get ()))
-       continue;
+       {
+         cus_to_skip.set (per_cu->index, true);
+         continue;
+       }
 
       if (per_cu->fnd != nullptr)
        {
          file_and_directory *fnd = per_cu->fnd.get ();
 
          if (file_matcher (fnd->get_name (), false))
-           {
-             per_cu->mark = 1;
-             continue;
-           }
+           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
               || file_matcher (lbasename (fnd->get_name ()), true))
              && file_matcher (fnd->get_fullname (), false))
-           {
-             per_cu->mark = 1;
-             continue;
-           }
+           continue;
        }
 
       quick_file_names *file_data = dw2_get_file_names (per_cu.get (),
                                                        per_objfile);
       if (file_data == NULL)
-       continue;
+       {
+         cus_to_skip.set (per_cu->index, true);
+         continue;
+       }
 
       if (visited_not_found.contains (file_data))
-       continue;
-      else if (visited_found.contains (file_data))
        {
-         per_cu->mark = 1;
+         cus_to_skip.set (per_cu->index, true);
          continue;
        }
+      else if (visited_found.contains (file_data))
+       continue;
 
+      bool matched = false;
       for (int j = 0; j < file_data->num_file_names; ++j)
        {
          const char *this_real_name;
 
          if (file_matcher (file_data->file_names[j], false))
            {
-             per_cu->mark = 1;
+             matched = true;
              break;
            }
 
@@ -2082,15 +2089,18 @@ dw_expand_symtabs_matching_file_matcher
          this_real_name = dw2_get_real_path (per_objfile, file_data, j);
          if (file_matcher (this_real_name, false))
            {
-             per_cu->mark = 1;
+             matched = true;
              break;
            }
        }
 
-      if (per_cu->mark)
+      if (matched)
        visited_found.insert (file_data);
       else
-       visited_not_found.insert (file_data);
+       {
+         cus_to_skip.set (per_cu->index, true);
+         visited_not_found.insert (file_data);
+       }
     }
 }
 
@@ -14575,7 +14585,9 @@ cooked_index_functions::expand_symtabs_matching
 
   cooked_index *table = wait (objfile, true);
 
-  dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
+  auto_bool_vector cus_to_skip;
+  dw_expand_symtabs_matching_file_matcher (per_objfile, cus_to_skip,
+                                          file_matcher);
 
   /* This invariant is documented in quick-functions.h.  */
   gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
@@ -14586,7 +14598,7 @@ cooked_index_functions::expand_symtabs_matching
          QUIT;
 
          if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
-                                               file_matcher,
+                                               cus_to_skip, file_matcher,
                                                expansion_notify,
                                                lang_matcher))
            return false;
@@ -14667,9 +14679,8 @@ cooked_index_functions::expand_symtabs_matching
          if (per_objfile->symtab_set_p (entry->per_cu))
            continue;
 
-         /* If file-matching was done, we don't need to consider
-            symbols from unmarked CUs.  */
-         if (file_matcher != nullptr && !entry->per_cu->mark)
+         /* We don't need to consider symbols from some CUs.  */
+         if (cus_to_skip.is_set (entry->per_cu->index))
            continue;
 
          /* See if the symbol matches the type filter.  */
@@ -14754,7 +14765,7 @@ cooked_index_functions::expand_symtabs_matching
            }
 
          if (!dw2_expand_symtabs_matching_one (entry->per_cu, per_objfile,
-                                               file_matcher,
+                                               cus_to_skip, file_matcher,
                                                expansion_notify, nullptr))
            return false;
        }
index 469e68ac0deb500d29b9a967151a45c50433b62b..de6315f6123755d18d6f28fcbd28667567c83a09 100644 (file)
@@ -128,7 +128,6 @@ struct dwarf2_per_cu
       lto_artificial (false),
       queued (false),
       m_header_read_in (false),
-      mark (false),
       files_read (false),
       scanned (false),
       section (section),
@@ -196,10 +195,6 @@ public:
      it private at the moment.  */
   mutable packed<bool, 1> m_header_read_in;
 
-  /* A temporary mark bit used when iterating over all CUs in
-     expand_symtabs_matching.  */
-  packed<unsigned int, 1> mark;
-
   /* True if we've tried to read the file table.  There will be no
      point in trying to read it again next time.  */
   packed<bool, 1> files_read;
@@ -1223,24 +1218,51 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
                             bool need_fullname) override;
 };
 
-/* If FILE_MATCHER is NULL or if PER_CU has
-   dwarf2_per_cu_quick_data::MARK set (see
-   dw_expand_symtabs_matching_file_matcher), expand the CU and call
-   EXPANSION_NOTIFY on it.  */
+/* This is used to track whether a CU has already been visited during
+   symbol expansion.  It is an auto-resizing bool vector.  */
+class auto_bool_vector
+{
+public:
+
+  auto_bool_vector () = default;
+
+  /* Return true if element I is set.  */
+  bool is_set (size_t i) const
+  {
+    if (i < m_vec.size ())
+      return m_vec[i];
+    return false;
+  }
+
+  /* Set a value in this vector, growing it automatically.  */
+  void set (size_t i, bool value)
+  {
+    if (m_vec.size () < i + 1)
+      m_vec.resize (i + 1);
+    m_vec[i] = value;
+  }
+
+private:
+  std::vector<bool> m_vec;
+};
+
+/* If FILE_MATCHER is NULL and if CUS_TO_SKIP does not include the
+   CU's index, expand the CU and call EXPANSION_NOTIFY on it.  */
 
 extern bool dw2_expand_symtabs_matching_one
   (dwarf2_per_cu *per_cu,
    dwarf2_per_objfile *per_objfile,
+   auto_bool_vector &cus_to_skip,
    expand_symtabs_file_matcher file_matcher,
    expand_symtabs_expansion_listener expansion_notify,
    expand_symtabs_lang_matcher lang_matcher);
 
-/* If FILE_MATCHER is non-NULL, set all the
-   dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
-   that match FILE_MATCHER.  */
+/* If FILE_MATCHER is non-NULL, update CUS_TO_SKIP as appropriate
+   based on FILE_MATCHER.  */
 
 extern void dw_expand_symtabs_matching_file_matcher
   (dwarf2_per_objfile *per_objfile,
+   auto_bool_vector &cus_to_skip,
    expand_symtabs_file_matcher file_matcher);
 
 /* Return pointer to string at .debug_str offset STR_OFFSET.  */