Skip to content

Commit 9987646

Browse files
committed
[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 <[email protected]>
1 parent b709149 commit 9987646

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,18 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
378378

379379
void LeaveSession();
380380

381-
uint32_t IsExecutingPython() const { return m_lock_count > 0; }
381+
uint32_t IsExecutingPython() {
382+
std::lock_guard<std::mutex> guard(m_mutex);
383+
return m_lock_count > 0;
384+
}
382385

383-
uint32_t IncrementLockCount() { return ++m_lock_count; }
386+
uint32_t IncrementLockCount() {
387+
std::lock_guard<std::mutex> guard(m_mutex);
388+
return ++m_lock_count;
389+
}
384390

385391
uint32_t DecrementLockCount() {
392+
std::lock_guard<std::mutex> guard(m_mutex);
386393
if (m_lock_count > 0)
387394
--m_lock_count;
388395
return m_lock_count;
@@ -422,6 +429,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
422429
bool m_pty_secondary_is_open;
423430
bool m_valid_session;
424431
uint32_t m_lock_count;
432+
std::mutex m_mutex;
425433
PyThreadState *m_command_thread_state;
426434
};
427435

lldb/source/Target/Process.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
24672467
}
24682468

24692469
void Process::LoadOperatingSystemPlugin(bool flush) {
2470+
std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
24702471
if (flush)
24712472
m_thread_list.Clear();
24722473
m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));

0 commit comments

Comments
 (0)