]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add cooked_index_worker::done_reading
authorTom Tromey <tom@tromey.com>
Tue, 25 Mar 2025 23:41:13 +0000 (17:41 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 1 Apr 2025 13:30:10 +0000 (07:30 -0600)
The two readers currently using cooked_index_worker shared some code.
This patch factors this out into a new "done_reading" method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/cooked-index-worker.c
gdb/dwarf2/cooked-index-worker.h
gdb/dwarf2/read-debug-names.c
gdb/dwarf2/read.c

index bde2055f0f14e677452d94fbab7bae3c8593a280..95ec9436c17b02c84d945b07148eab2af9f84594 100644 (file)
@@ -239,3 +239,27 @@ cooked_index_worker::write_to_cache (const cooked_index *idx,
       m_cache_store.store ();
     }
 }
+
+/* See cooked-index-worker.h.  */
+
+void
+cooked_index_worker::done_reading ()
+{
+  /* Only handle the scanning results here.  Complaints and exceptions
+     can only be dealt with on the main thread.  */
+  std::vector<cooked_index_shard_up> shards;
+
+  for (auto &one_result : m_results)
+    {
+      shards.push_back (one_result.release_shard ());
+      m_all_parents_map.add_map (*one_result.get_parent_map ());
+    }
+
+  shards.shrink_to_fit ();
+
+  dwarf2_per_bfd *per_bfd = m_per_objfile->per_bfd;
+  cooked_index *table
+    = (gdb::checked_static_cast<cooked_index *>
+       (per_bfd->index_table.get ()));
+  table->set_contents (std::move (shards), &m_warnings, &m_all_parents_map);
+}
index 4950a56e031e6a95d9948be6dc5d69e180c4cab1..fbbb3b50905dbb513e2260b944ece5c5452ae6e2 100644 (file)
@@ -240,6 +240,12 @@ protected:
      to be run in a worker thread without problems.  */
   virtual void do_reading () = 0;
 
+  /* Helper function that should be called when done reading.  This
+     assumes that m_results is filled in, and will initialize
+     m_all_parents_map and end by calling
+     cooked_index::set_contents.  */
+  virtual void done_reading ();
+
   /* A callback that can print stats, if needed.  This is called when
      transitioning to the 'MAIN_AVAILABLE' state.  */
   virtual void print_stats ()
index 99c8c015900c88aeec67508965814835efa1db6e..96a8ad3406d1377fd67873178f4bb9356ecab1fd 100644 (file)
@@ -426,7 +426,6 @@ cooked_index_worker_debug_names::do_reading ()
       m_map.indices[0].note_error (std::move (exc));
     }
 
-  std::vector<cooked_index_shard_up> shards;
   bool first = true;
   for (auto &iter : m_map.indices)
     {
@@ -437,20 +436,10 @@ cooked_index_worker_debug_names::do_reading ()
        }
       else
        iter.done_reading ({});
-      shards.push_back (iter.release_shard ());
-      m_all_parents_map.add_map (*iter.get_parent_map ());
     }
 
   m_results = std::move (m_map.indices);
-
-  dwarf2_per_bfd *per_bfd = m_per_objfile->per_bfd;
-  cooked_index *table
-    = (gdb::checked_static_cast<cooked_index *>
-       (per_bfd->index_table.get ()));
-
-  /* Note that this code never uses IS_PARENT_DEFERRED, so it is safe
-     to pass nullptr here.  */
-  table->set_contents (std::move (shards), &m_warnings, nullptr);
+  done_reading ();
 
   bfd_thread_cleanup ();
 }
index 179289ae699337dc070254fbc9e2ed0d66f51458..17f06ff134220d7753e7d9ac25e424965e9e55ed 100644 (file)
@@ -3553,7 +3553,7 @@ private:
 
   /* After the last DWARF-reading task has finished, this function
      does the remaining work to finish the scan.  */
-  void done_reading ();
+  void done_reading () override;
 
   /* An iterator for the comp units.  */
   using unit_iterator = std::vector<dwarf2_per_cu_up>::iterator;
@@ -3603,30 +3603,13 @@ cooked_index_worker_debug_info::process_cus (size_t task_number,
 void
 cooked_index_worker_debug_info::done_reading ()
 {
-  /* Only handle the scanning results here.  Complaints and exceptions
-     can only be dealt with on the main thread.  */
-  std::vector<cooked_index_shard_up> shards;
-
-  for (auto &one_result : m_results)
-    {
-      shards.push_back (one_result.release_shard ());
-      m_all_parents_map.add_map (*one_result.get_parent_map ());
-    }
-
   /* This has to wait until we read the CUs, we need the list of DWOs.  */
   process_skeletonless_type_units (m_per_objfile, &m_index_storage);
 
-  shards.push_back (m_index_storage.release_shard ());
-  shards.shrink_to_fit ();
-
-  m_all_parents_map.add_map (*m_index_storage.get_parent_map ());
+  m_results.push_back (std::move (m_index_storage));
 
-  dwarf2_per_bfd *per_bfd = m_per_objfile->per_bfd;
-  cooked_index *table
-    = (gdb::checked_static_cast<cooked_index *>
-       (per_bfd->index_table.get ()));
-  table->set_contents (std::move (shards), &m_warnings,
-                      &m_all_parents_map);
+  /* Call into the base class.  */
+  cooked_index_worker::done_reading ();
 }
 
 void