From: Tom Tromey Date: Tue, 25 Mar 2025 23:41:13 +0000 (-0600) Subject: Add cooked_index_worker::done_reading X-Git-Tag: binutils-2_45~996 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=34a286acdc30837415adc893b5b71df5a5e1bac6;p=thirdparty%2Fbinutils-gdb.git Add cooked_index_worker::done_reading 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 --- diff --git a/gdb/dwarf2/cooked-index-worker.c b/gdb/dwarf2/cooked-index-worker.c index bde2055f0f1..95ec9436c17 100644 --- a/gdb/dwarf2/cooked-index-worker.c +++ b/gdb/dwarf2/cooked-index-worker.c @@ -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 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 + (per_bfd->index_table.get ())); + table->set_contents (std::move (shards), &m_warnings, &m_all_parents_map); +} diff --git a/gdb/dwarf2/cooked-index-worker.h b/gdb/dwarf2/cooked-index-worker.h index 4950a56e031..fbbb3b50905 100644 --- a/gdb/dwarf2/cooked-index-worker.h +++ b/gdb/dwarf2/cooked-index-worker.h @@ -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 () diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index 99c8c015900..96a8ad3406d 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -426,7 +426,6 @@ cooked_index_worker_debug_names::do_reading () m_map.indices[0].note_error (std::move (exc)); } - std::vector 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 - (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 (); } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 179289ae699..17f06ff1342 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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::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 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 - (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