Skip to content

Commit f436805

Browse files
committed
[lldb] Fix dead lock issue when loading modules in Scripted Process
This patch attempts to fix a dead lock when loading modules in a Scripted Process. This issue was triggered by loading the modules after the process did resume, but before the process actually stop, causing the language runtime mutex to be locked by a separate thread, responsible to unwind the stack (using the runtime unwind plan), while the module loading thread was trying to notify the runtimes of the newly loaded module. To address that, this patch moves the module loading logic to be done before sending the stop event, to prevent the dead lock situation described above. Differential Revision: https://reviews.llvm.org/D154649 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 781ba90 commit f436805

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ void ScriptedProcess::DidLaunch() { m_pid = GetInterface().GetProcessID(); }
166166
void ScriptedProcess::DidResume() {
167167
// Update the PID again, in case the user provided a placeholder pid at launch
168168
m_pid = GetInterface().GetProcessID();
169-
GetLoadedDynamicLibrariesInfos();
170169
}
171170

172171
Status ScriptedProcess::DoResume() {

lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lldb/Target/Process.h"
1313
#include "lldb/Utility/ConstString.h"
1414
#include "lldb/Utility/ScriptedMetadata.h"
15+
#include "lldb/Utility/State.h"
1516
#include "lldb/Utility/Status.h"
1617

1718
#include "ScriptedThread.h"
@@ -93,6 +94,11 @@ class ScriptedProcess : public Process {
9394
void *GetImplementation() override;
9495

9596
void ForceScriptedState(lldb::StateType state) override {
97+
// If we're about to stop, we should fetch the loaded dynamic libraries
98+
// dictionary before emitting the private stop event to avoid having the
99+
// module loading happen while the process state is changing.
100+
if (StateIsStoppedState(state, true))
101+
GetLoadedDynamicLibrariesInfos();
96102
SetPrivateState(state);
97103
}
98104

0 commit comments

Comments
 (0)