Skip to content

Conversation

@felipepiovezan
Copy link
Contributor

The UpdateRegisterContext method can be called from multiple threads.

The UpdateRegisterContext method can be called from multiple threads.
@llvmbot
Copy link
Member

llvmbot commented Apr 5, 2025

@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)

Changes

The UpdateRegisterContext method can be called from multiple threads.


Full diff: https://github.com/llvm/llvm-project/pull/134469.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp (+2)
  • (modified) lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h (+2)
diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
index 75438550ce914..29927e3b5e4ed 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
@@ -25,6 +25,8 @@ RegisterContextThreadMemory::RegisterContextThreadMemory(
 RegisterContextThreadMemory::~RegisterContextThreadMemory() = default;
 
 void RegisterContextThreadMemory::UpdateRegisterContext() {
+  std::lock_guard<std::mutex> lock(m_update_register_ctx_lock);
+
   ThreadSP thread_sp(m_thread_wp.lock());
   if (thread_sp) {
     ProcessSP process_sp(thread_sp->GetProcess());
diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h b/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
index 23f675508cf38..1df32bbc1f057 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
@@ -99,6 +99,8 @@ class RegisterContextThreadMemory : public lldb_private::RegisterContext {
   RegisterContextThreadMemory(const RegisterContextThreadMemory &) = delete;
   const RegisterContextThreadMemory &
   operator=(const RegisterContextThreadMemory &) = delete;
+
+  std::mutex m_update_register_ctx_lock;
 };
 
 } // namespace lldb_private

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felipepiovezan felipepiovezan merged commit 6272e1f into llvm:main Apr 5, 2025
12 checks passed
@felipepiovezan felipepiovezan deleted the felipe/thread_safe branch April 5, 2025 01:43
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Apr 5, 2025
The UpdateRegisterContext method can be called from multiple threads.

(cherry picked from commit 6272e1f)
felipepiovezan added a commit to swiftlang/llvm-project that referenced this pull request Apr 5, 2025
…ry-pick

[cherry-pick][lldb] Make `RegisterContextThreadMemory` thread safe (llvm#134469)
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Apr 7, 2025
The UpdateRegisterContext method can be called from multiple threads.

(cherry picked from commit 6272e1f)
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Apr 8, 2025
…dsafe_6.2

[lldb] Make `RegisterContextThreadMemory` thread safe (llvm#134469)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants