diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 25635d9b72e..7ddcdedf9d0 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -460,12 +460,15 @@ cooked_index::cooked_index (vec_type &&vec) void cooked_index::start_writing_index (dwarf2_per_bfd *per_bfd) { + index_cache_store_context ctx (global_index_cache); + /* This must be set after all the finalization tasks have been started, because it may call 'wait'. */ m_write_future - = gdb::thread_pool::g_thread_pool->post_task ([this, per_bfd] () + = gdb::thread_pool::g_thread_pool->post_task ([this, per_bfd, + ctx = std::move (ctx)] () { - maybe_write_index (per_bfd); + maybe_write_index (per_bfd, ctx); }); } @@ -629,13 +632,14 @@ cooked_index::dump (gdbarch *arch) const } void -cooked_index::maybe_write_index (dwarf2_per_bfd *per_bfd) +cooked_index::maybe_write_index (dwarf2_per_bfd *per_bfd, + const index_cache_store_context &ctx) { /* Wait for finalization. */ wait (); /* (maybe) store an index in the cache. */ - global_index_cache.store (per_bfd); + global_index_cache.store (per_bfd, ctx); } /* Wait for all the index cache entries to be written before gdb diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 0d6f3e5aa0e..5aacb321c91 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -37,6 +37,7 @@ struct dwarf2_per_cu_data; struct dwarf2_per_bfd; +struct index_cache_store_context; /* Flags that describe an entry in the index. */ enum cooked_index_flag_enum : unsigned char @@ -435,7 +436,8 @@ class cooked_index : public dwarf_scanner_base private: /* Maybe write the index to the index cache. */ - void maybe_write_index (dwarf2_per_bfd *per_bfd); + void maybe_write_index (dwarf2_per_bfd *per_bfd, + const index_cache_store_context &); /* The vector of cooked_index objects. This is stored because the entries are stored on the obstacks in those objects. */ diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 79ab706ee9d..e2fb984799c 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -86,12 +86,20 @@ index_cache::disable () m_enabled = false; } + /* See index-cache.h. */ + +index_cache_store_context::index_cache_store_context (const index_cache &ic) + : m_enabled (ic.enabled ()) +{ +} + /* See dwarf-index-cache.h. */ void -index_cache::store (dwarf2_per_bfd *per_bfd) +index_cache::store (dwarf2_per_bfd *per_bfd, + const index_cache_store_context &ctx) { - if (!enabled ()) + if (!ctx.m_enabled) return; /* Get build id of objfile. */ diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index 1efff17049f..7ea972d5c7f 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -25,6 +25,7 @@ #include "symfile.h" class dwarf2_per_bfd; +class index_cache; /* Base of the classes used to hold the resources of the indices loaded from the cache (e.g. mmapped files). */ @@ -34,6 +35,20 @@ struct index_cache_resource virtual ~index_cache_resource () = 0; }; +/* Information to be captured in the main thread, and to be used by worker + threads during store (). */ + +struct index_cache_store_context +{ + friend class index_cache; + + explicit index_cache_store_context (const index_cache &ic); + +private: + /* Captured value of enabled (). */ + bool m_enabled; +}; + /* Class to manage the access to the DWARF index cache. */ class index_cache @@ -55,7 +70,8 @@ class index_cache void disable (); /* Store an index for the specified object file in the cache. */ - void store (dwarf2_per_bfd *per_bfd); + void store (dwarf2_per_bfd *per_bfd, + const index_cache_store_context &); /* Look for an index file matching BUILD_ID. If found, return the contents as an array_view and store the underlying resources (allocated memory,