]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Capture the per-BFD object in index_cache_store_context
authorTom Tromey <tom@tromey.com>
Sat, 27 Jan 2024 15:56:53 +0000 (08:56 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 9 Mar 2024 00:25:49 +0000 (17:25 -0700)
This changes index_cache_store_context to also capture the per-BFD
object when it is constructed.  This is used when storing to the
cache, and this approach makes the code a little simpler.

gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/index-cache.c
gdb/dwarf2/index-cache.h

index dc8b6f08ff451454f3500bf934b786bda0fa9cb8..7d353c3d25e0b18f62ffafc337f9a99de299e1ac 100644 (file)
@@ -631,7 +631,7 @@ cooked_index::set_contents (vec_type &&vec)
   gdb::task_group finalizers ([this, ctx = std::move (ctx)] ()
   {
     m_state->set (cooked_state::FINALIZED);
-    maybe_write_index (m_per_bfd, ctx);
+    maybe_write_index (ctx);
   });
 
   for (auto &idx : m_vector)
@@ -837,13 +837,12 @@ cooked_index::dump (gdbarch *arch)
 }
 
 void
-cooked_index::maybe_write_index (dwarf2_per_bfd *per_bfd,
-                                const index_cache_store_context &ctx)
+cooked_index::maybe_write_index (const index_cache_store_context &ctx)
 {
   if (index_for_writing () != nullptr)
     {
       /* (maybe) store an index in the cache.  */
-      global_index_cache.store (m_per_bfd, ctx);
+      global_index_cache.store (ctx);
     }
   m_state->set (cooked_state::CACHE_DONE);
 }
index 629a5b6b9eef935d3bb5c4fd47014f417afadf1d..17659df0531abb0595c5446f18a4e59c36a140ed 100644 (file)
@@ -672,8 +672,7 @@ public:
 private:
 
   /* Maybe write the index to the index cache.  */
-  void maybe_write_index (dwarf2_per_bfd *per_bfd,
-                         const index_cache_store_context &);
+  void maybe_write_index (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.  */
index a269eb46a3604bad117bddfeaf74b7e1fa81becb..91f2af3e275e8d3ae716a1091194f327f3861120 100644 (file)
@@ -91,7 +91,8 @@ index_cache::disable ()
 index_cache_store_context::index_cache_store_context (const index_cache &ic,
                                                      dwarf2_per_bfd *per_bfd)
   :  m_enabled (ic.enabled ()),
-     m_dir (ic.m_dir)
+     m_dir (ic.m_dir),
+     m_per_bfd (per_bfd)
 {
   if (!m_enabled)
     return;
@@ -154,8 +155,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
 /* See dwarf-index-cache.h.  */
 
 void
-index_cache::store (dwarf2_per_bfd *per_bfd,
-                   const index_cache_store_context &ctx)
+index_cache::store (const index_cache_store_context &ctx)
 {
   if (!ctx.m_enabled)
     return;
@@ -167,18 +167,18 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
   try
     {
       index_cache_debug ("writing index cache for objfile %s",
-                        bfd_get_filename (per_bfd->obfd));
+                        bfd_get_filename (ctx.m_per_bfd->obfd));
 
       /* Write the index itself to the directory, using the build id as the
         filename.  */
-      write_dwarf_index (per_bfd, ctx.m_dir.c_str (),
+      write_dwarf_index (ctx.m_per_bfd, ctx.m_dir.c_str (),
                         ctx.m_build_id_str.c_str (), dwz_build_id_ptr,
                         dw_index_kind::GDB_INDEX);
     }
   catch (const gdb_exception_error &except)
     {
       index_cache_debug ("couldn't store index cache for objfile %s: %s",
-                        bfd_get_filename (per_bfd->obfd), except.what ());
+                        bfd_get_filename (ctx.m_per_bfd->obfd), except.what ());
     }
 }
 
index f66f72caea1ba6d6f18e662eb4e0690c8f1f2588..09577aca2573728b3a0d35ccd257b10bbfb7e702 100644 (file)
@@ -51,6 +51,9 @@ private:
   /* Captured value of index cache directory.  */
   std::string m_dir;
 
+  /* The per-bfd object that we're caching.  */
+  dwarf2_per_bfd *m_per_bfd;
+
   /* Captured value of build id.  */
   std::string m_build_id_str;
 
@@ -80,8 +83,7 @@ public:
   void disable ();
 
   /* Store an index for the specified object file in the cache.  */
-  void store (dwarf2_per_bfd *per_bfd,
-             const index_cache_store_context &);
+  void store (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,