mib created this revision. mib added reviewers: JDevlieghere, bulbazord, jingham. mib added a project: LLDB. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits.
This patch should fix some data races when a python script (i.e. a Scripted Process) has an indirect nested call to another python script (i.e. a OperatingSystem Plugin), which can cause concurrent writes to the python lock count. This patch addresses that issue by guarding the accesses by a recursive mutex. rdar://109413039 Signed-off-by: Med Ismail Bennani <ism...@bennani.ma> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154271 Files: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h lldb/source/Target/Process.cpp Index: lldb/source/Target/Process.cpp =================================================================== --- lldb/source/Target/Process.cpp +++ lldb/source/Target/Process.cpp @@ -2467,6 +2467,7 @@ } 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)); Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -380,9 +380,13 @@ uint32_t IsExecutingPython() const { return m_lock_count > 0; } - uint32_t IncrementLockCount() { return ++m_lock_count; } + uint32_t IncrementLockCount() { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return ++m_lock_count; + } uint32_t DecrementLockCount() { + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_lock_count > 0) --m_lock_count; return m_lock_count; @@ -422,6 +426,7 @@ bool m_pty_secondary_is_open; bool m_valid_session; uint32_t m_lock_count; + std::recursive_mutex m_mutex; PyThreadState *m_command_thread_state; };
Index: lldb/source/Target/Process.cpp =================================================================== --- lldb/source/Target/Process.cpp +++ lldb/source/Target/Process.cpp @@ -2467,6 +2467,7 @@ } 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)); Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -380,9 +380,13 @@ uint32_t IsExecutingPython() const { return m_lock_count > 0; } - uint32_t IncrementLockCount() { return ++m_lock_count; } + uint32_t IncrementLockCount() { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + return ++m_lock_count; + } uint32_t DecrementLockCount() { + std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_lock_count > 0) --m_lock_count; return m_lock_count; @@ -422,6 +426,7 @@ bool m_pty_secondary_is_open; bool m_valid_session; uint32_t m_lock_count; + std::recursive_mutex m_mutex; PyThreadState *m_command_thread_state; };
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits