From: Tom Tromey Date: Fri, 28 Mar 2025 16:26:36 +0000 (-0600) Subject: Clean up cooked_index::done_reading X-Git-Tag: binutils-2_45~985 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60ac9c60fe5b6dc5a59a30a971c3fad020fecf45;p=thirdparty%2Fbinutils-gdb.git Clean up cooked_index::done_reading The cooked index worker maintains the state for the various state transition in the scanner. It is held by the cooked_index while scanning is in progress, then deleted once this has completed. I noticed that none of the arguments to cooked_index::done_reading were really needed -- the cooked_index already has access to the worker should it need it. Removing these parameters makes the code a bit simpler and also cleans up some confusing code around the use of the deferred warnings object. Regression tested on x86-64 Fedora 40. Approved-By: Simon Marchi --- diff --git a/gdb/dwarf2/cooked-index-worker.c b/gdb/dwarf2/cooked-index-worker.c index 95ec9436c17..da51a8c72e8 100644 --- a/gdb/dwarf2/cooked-index-worker.c +++ b/gdb/dwarf2/cooked-index-worker.c @@ -226,8 +226,7 @@ cooked_index_worker::set (cooked_state desired_state) /* See cooked-index-worker.h. */ void -cooked_index_worker::write_to_cache (const cooked_index *idx, - deferred_warnings *warn) const +cooked_index_worker::write_to_cache (const cooked_index *idx) { if (idx != nullptr) { @@ -235,7 +234,7 @@ cooked_index_worker::write_to_cache (const cooked_index *idx, See PR symtab/30837. This arranges to capture all such warnings. This is safe because we know the deferred_warnings object isn't in use by any other thread at this point. */ - scoped_restore_warning_hook defer (warn); + scoped_restore_warning_hook defer (&m_warnings); m_cache_store.store (); } } @@ -245,21 +244,12 @@ cooked_index_worker::write_to_cache (const cooked_index *idx, 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 (); + m_all_parents_map.add_map (*one_result.get_parent_map ()); 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); + table->set_contents (); } diff --git a/gdb/dwarf2/cooked-index-worker.h b/gdb/dwarf2/cooked-index-worker.h index fbbb3b50905..df5c31d572d 100644 --- a/gdb/dwarf2/cooked-index-worker.h +++ b/gdb/dwarf2/cooked-index-worker.h @@ -224,6 +224,22 @@ public: cache writer.) */ bool wait (cooked_state desired_state, bool allow_quit); + /* Release all shards from the results. */ + std::vector release_shards () + { + std::vector result; + for (auto &one_result : m_results) + result.push_back (one_result.release_shard ()); + result.shrink_to_fit (); + return result; + } + + /* Return the object holding all the parent maps. */ + const parent_map_map *get_parent_map_map () const + { + return &m_all_parents_map; + } + protected: /* Let cooked_index call the 'set' and 'write_to_cache' methods. */ @@ -233,8 +249,7 @@ protected: void set (cooked_state desired_state); /* Write to the index cache. */ - void write_to_cache (const cooked_index *idx, - deferred_warnings *warn) const; + void write_to_cache (const cooked_index *idx); /* Helper function that does the work of reading. This must be able to be run in a worker thread without problems. */ diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 7a32a279cdb..0f20b07f90c 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -78,12 +78,10 @@ cooked_index::wait (cooked_state desired_state, bool allow_quit) } void -cooked_index::set_contents (std::vector &&shards, - deferred_warnings *warn, - const parent_map_map *parent_maps) +cooked_index::set_contents () { gdb_assert (m_shards.empty ()); - m_shards = std::move (shards); + m_shards = m_state->release_shards (); m_state->set (cooked_state::MAIN_AVAILABLE); @@ -92,16 +90,17 @@ cooked_index::set_contents (std::vector &&shards, finalization. However, that would take a slot in the global thread pool, and if enough such tasks were submitted at once, it would cause a livelock. */ - gdb::task_group finalizers ([this, warn] () + gdb::task_group finalizers ([this] () { m_state->set (cooked_state::FINALIZED); - m_state->write_to_cache (index_for_writing (), warn); + m_state->write_to_cache (index_for_writing ()); m_state->set (cooked_state::CACHE_DONE); }); for (auto &shard : m_shards) { auto this_shard = shard.get (); + const parent_map_map *parent_maps = m_state->get_parent_map_map (); finalizers.add_task ([=] () { this_shard->finalize (parent_maps); }); } diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 583fa300043..384938e5402 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -105,14 +105,8 @@ public: void start_reading () override; /* Called by cooked_index_worker to set the contents of this index - and transition to the MAIN_AVAILABLE state. WARN is used to - collect any warnings that may arise when writing to the cache. - PARENT_MAPS is used when resolving pending parent links. - PARENT_MAPS may be NULL if there are no IS_PARENT_DEFERRED - entries in VEC. */ - void set_contents (std::vector &&vec, - deferred_warnings *warn, - const parent_map_map *parent_maps); + and transition to the MAIN_AVAILABLE state. */ + void set_contents (); /* A range over a vector of subranges. */ using range = range_chain;