Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0cbf4d

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 2ac8da0 commit f0cbf4d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,18 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
375375

376376
void LeaveSession();
377377

378-
uint32_t IsExecutingPython() const { return m_lock_count > 0; }
378+
uint32_t IsExecutingPython() {
379+
std::lock_guard<std::mutex> guard(m_mutex);
380+
return m_lock_count > 0;
381+
}
379382

380-
uint32_t IncrementLockCount() { return ++m_lock_count; }
383+
uint32_t IncrementLockCount() {
384+
std::lock_guard<std::mutex> guard(m_mutex);
385+
return ++m_lock_count;
386+
}
381387

382388
uint32_t DecrementLockCount() {
389+
std::lock_guard<std::mutex> guard(m_mutex);
383390
if (m_lock_count > 0)
384391
--m_lock_count;
385392
return m_lock_count;
@@ -419,6 +426,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
419426
bool m_pty_secondary_is_open;
420427
bool m_valid_session;
421428
uint32_t m_lock_count;
429+
std::mutex m_mutex;
422430
PyThreadState *m_command_thread_state;
423431
};
424432

lldb/source/Target/Process.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
26092609
}
26102610

26112611
void Process::LoadOperatingSystemPlugin(bool flush) {
2612+
std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
26122613
if (flush)
26132614
m_thread_list.Clear();
26142615
m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));

0 commit comments

Comments
 (0)