[Lldb-commits] [PATCH] D158034: [lldb] Fix data race in ThreadList

Augusto Noronha via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 18 16:55:15 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb9006324970: [lldb] Fix data race in ThreadList (authored by augusto2112).

Changed prior to commit:
  https://reviews.llvm.org/D158034?vs=550519&id=551673#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158034/new/

https://reviews.llvm.org/D158034

Files:
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Target/ThreadCollection.h
  lldb/include/lldb/Target/ThreadList.h
  lldb/source/Target/Process.cpp
  lldb/source/Target/ThreadList.cpp


Index: lldb/source/Target/ThreadList.cpp
===================================================================
--- lldb/source/Target/ThreadList.cpp
+++ lldb/source/Target/ThreadList.cpp
@@ -736,7 +736,8 @@
   if (this != &rhs) {
     // Lock both mutexes to make sure neither side changes anyone on us while
     // the assignment occurs
-    std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard(GetMutex(), rhs.GetMutex());
+    std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard(
+        GetMutex(), rhs.GetMutex());
 
     m_process = rhs.m_process;
     m_stop_id = rhs.m_stop_id;
@@ -781,10 +782,6 @@
     (*pos)->Flush();
 }
 
-std::recursive_mutex &ThreadList::GetMutex() const {
-  return m_process->m_thread_mutex;
-}
-
 ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher(
     lldb::ThreadSP thread_sp)
     : m_thread_list(nullptr), m_tid(LLDB_INVALID_THREAD_ID) {
Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -435,7 +435,7 @@
           Listener::MakeListener("lldb.process.internal_state_listener")),
       m_mod_id(), m_process_unique_id(0), m_thread_index_id(0),
       m_thread_id_to_index_id_map(), m_exit_status(-1), m_exit_string(),
-      m_exit_status_mutex(), m_thread_mutex(), m_thread_list_real(this),
+      m_exit_status_mutex(), m_thread_list_real(this),
       m_thread_list(this), m_thread_plans(*this), m_extended_thread_list(this),
       m_extended_thread_stop_id(0), m_queue_list(this), m_queue_list_stop_id(0),
       m_notifications(), m_image_tokens(),
@@ -2456,7 +2456,7 @@
 }
 
 void Process::LoadOperatingSystemPlugin(bool flush) {
-  std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
+  std::lock_guard<std::recursive_mutex> guard(GetThreadList().GetMutex());
   if (flush)
     m_thread_list.Clear();
   m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));
Index: lldb/include/lldb/Target/ThreadList.h
===================================================================
--- lldb/include/lldb/Target/ThreadList.h
+++ lldb/include/lldb/Target/ThreadList.h
@@ -133,8 +133,6 @@
 
   void SetStopID(uint32_t stop_id);
 
-  std::recursive_mutex &GetMutex() const override;
-
   void Update(ThreadList &rhs);
 
 protected:
Index: lldb/include/lldb/Target/ThreadCollection.h
===================================================================
--- lldb/include/lldb/Target/ThreadCollection.h
+++ lldb/include/lldb/Target/ThreadCollection.h
@@ -47,7 +47,7 @@
     return ThreadIterable(m_threads, GetMutex());
   }
 
-  virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
+  std::recursive_mutex &GetMutex() const { return m_mutex; }
 
 protected:
   collection m_threads;
Index: lldb/include/lldb/Target/Process.h
===================================================================
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2970,7 +2970,6 @@
   std::string m_exit_string; ///< A textual description of why a process exited.
   std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can
                                   ///be safely accessed from multiple threads
-  std::recursive_mutex m_thread_mutex;
   ThreadList m_thread_list_real; ///< The threads for this process as are known
                                  ///to the protocol we are debugging with
   ThreadList m_thread_list; ///< The threads for this process as the user will


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158034.551673.patch
Type: text/x-patch
Size: 3555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230818/502204dc/attachment.bin>


More information about the lldb-commits mailing list