]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Capture directory in index_cache_store_context
authorTom Tromey <tom@tromey.com>
Sat, 27 Jan 2024 15:52:46 +0000 (08:52 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 9 Mar 2024 00:25:49 +0000 (17:25 -0700)
I noticed that index_cache_store_context captures the 'enabled'
setting, but not the index cache directory.  This patch makes this
change, which avoids a possible race -- with background reading, the
user could possibly change this directory at the exact moment the
writer examines the variable.

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

index 645e36c66f773499d66830a48dff33ae40e31a96..a269eb46a3604bad117bddfeaf74b7e1fa81becb 100644 (file)
@@ -90,7 +90,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_enabled (ic.enabled ()),
+     m_dir (ic.m_dir)
 {
   if (!m_enabled)
     return;
@@ -124,7 +125,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
       m_dwz_build_id_str = build_id_to_string (dwz_build_id);
     }
 
-  if (ic.m_dir.empty ())
+  if (m_dir.empty ())
     {
       warning (_("The index cache directory name is empty, skipping store."));
       m_enabled = false;
@@ -134,7 +135,7 @@ index_cache_store_context::index_cache_store_context (const index_cache &ic,
   try
     {
       /* Try to create the containing directory.  */
-      if (!mkdir_recursive (ic.m_dir.c_str ()))
+      if (!mkdir_recursive (m_dir.c_str ()))
        {
          warning (_("index cache: could not make cache directory: %s"),
                   safe_strerror (errno));
@@ -170,7 +171,7 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
 
       /* Write the index itself to the directory, using the build id as the
         filename.  */
-      write_dwarf_index (per_bfd, m_dir.c_str (),
+      write_dwarf_index (per_bfd, ctx.m_dir.c_str (),
                         ctx.m_build_id_str.c_str (), dwz_build_id_ptr,
                         dw_index_kind::GDB_INDEX);
     }
index 079ed412d2eb87421db172d036084824c0ef1614..f66f72caea1ba6d6f18e662eb4e0690c8f1f2588 100644 (file)
@@ -48,6 +48,9 @@ private:
   /* Captured value of enabled ().  */
   bool m_enabled;
 
+  /* Captured value of index cache directory.  */
+  std::string m_dir;
+
   /* Captured value of build id.  */
   std::string m_build_id_str;