[Lldb-commits] [lldb] 9987646 - [lldb] Fix data race when interacting with python scripts
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 3 11:49:19 PDT 2023
Author: Med Ismail Bennani
Date: 2023-07-03T11:49:11-07:00
New Revision: 9987646057d9748514662f96c869a5f87e463bc6
URL: https://github.com/llvm/llvm-project/commit/9987646057d9748514662f96c869a5f87e463bc6
DIFF: https://github.com/llvm/llvm-project/commit/9987646057d9748514662f96c869a5f87e463bc6.diff
LOG: [lldb] Fix data race when interacting with python scripts
This patch should fix some data races when a python script (i.e. a
Scripted Process) has a nested call to another python script (i.e. a
OperatingSystem Plugin), which can cause concurrent writes to the python
lock count.
This patch also fixes a data race happening when resetting the operating
system unique pointer.
To address these issues, both accesses is guarded by a mutex.
rdar://109413039
Differential Revision: https://reviews.llvm.org/D154271
Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
Added:
Modified:
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
lldb/source/Target/Process.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index fe75f69fa2a03a..55ade49a1245c7 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -378,11 +378,18 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
void LeaveSession();
- uint32_t IsExecutingPython() const { return m_lock_count > 0; }
+ uint32_t IsExecutingPython() {
+ std::lock_guard<std::mutex> guard(m_mutex);
+ return m_lock_count > 0;
+ }
- uint32_t IncrementLockCount() { return ++m_lock_count; }
+ uint32_t IncrementLockCount() {
+ std::lock_guard<std::mutex> guard(m_mutex);
+ return ++m_lock_count;
+ }
uint32_t DecrementLockCount() {
+ std::lock_guard<std::mutex> guard(m_mutex);
if (m_lock_count > 0)
--m_lock_count;
return m_lock_count;
@@ -422,6 +429,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
bool m_pty_secondary_is_open;
bool m_valid_session;
uint32_t m_lock_count;
+ std::mutex m_mutex;
PyThreadState *m_command_thread_state;
};
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 4059660e942667..ca2eac7d8e5b04 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2467,6 +2467,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
}
void Process::LoadOperatingSystemPlugin(bool flush) {
+ std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
if (flush)
m_thread_list.Clear();
m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));
More information about the lldb-commits
mailing list