Skip to content

Commit ef46a32

Browse files
committed
[lldb/Plugins] Fix method dispatch bug when using multiple scripted processes
This patch should address a bug when a user have multiple scripted processes in the same debugging session. In order for the scripted process plugin to be able to call into the scripted object instance methods to fetch the necessary data to reconstruct its state, the scripted process plugin calls into a scripted process interface, that has a reference to the created script object instance. However, prior to this patch, we only had a single instance of the scripted process interface, living the script interpreter. So every time a new scripted process plugin was created, it would overwrite the script object instance that was held by the single scripted process interface in the script interpreter. That would cause all the method calls made to the scripted process interface to be dispatched by the last instanciated script object instance, which is wrong. In order to prevent that, this patch moves the scripted process interface reference to be help by the scripted process plugin itself. rdar://104882562 Differential Revision: https://reviews.llvm.org/D143308 Signed-off-by: Med Ismail Bennani <[email protected]> Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent a90b085 commit ef46a32

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ class ScriptInterpreter : public PluginInterface {
149149

150150
ScriptInterpreter(
151151
Debugger &debugger, lldb::ScriptLanguage script_lang,
152-
lldb::ScriptedProcessInterfaceUP scripted_process_interface_up =
153-
std::make_unique<ScriptedProcessInterface>(),
154152
lldb::ScriptedPlatformInterfaceUP scripted_platform_interface_up =
155153
std::make_unique<ScriptedPlatformInterface>());
156154

@@ -604,7 +602,6 @@ class ScriptInterpreter : public PluginInterface {
604602
protected:
605603
Debugger &m_debugger;
606604
lldb::ScriptLanguage m_script_lang;
607-
lldb::ScriptedProcessInterfaceUP m_scripted_process_interface_up;
608605
lldb::ScriptedPlatformInterfaceUP m_scripted_platform_interface_up;
609606
};
610607

lldb/source/Interpreter/ScriptInterpreter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ using namespace lldb_private;
2828

2929
ScriptInterpreter::ScriptInterpreter(
3030
Debugger &debugger, lldb::ScriptLanguage script_lang,
31-
lldb::ScriptedProcessInterfaceUP scripted_process_interface_up,
3231
lldb::ScriptedPlatformInterfaceUP scripted_platform_interface_up)
3332
: m_debugger(debugger), m_script_lang(script_lang),
34-
m_scripted_process_interface_up(std::move(scripted_process_interface_up)),
3533
m_scripted_platform_interface_up(
3634
std::move(scripted_platform_interface_up)) {}
3735

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Status ScriptedProcess::DoLoadCore() {
151151
Status ScriptedProcess::DoLaunch(Module *exe_module,
152152
ProcessLaunchInfo &launch_info) {
153153
LLDB_LOGF(GetLog(LLDBLog::Process), "ScriptedProcess::%s launching process", __FUNCTION__);
154-
154+
155155
/* MARK: This doesn't reflect how lldb actually launches a process.
156156
In reality, it attaches to debugserver, then resume the process.
157157
That's not true in all cases. If debugserver is remote, lldb

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
411411
m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
412412
m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
413413
m_command_thread_state(nullptr) {
414-
m_scripted_process_interface_up =
415-
std::make_unique<ScriptedProcessPythonInterface>(*this);
416414
m_scripted_platform_interface_up =
417415
std::make_unique<ScriptedPlatformPythonInterface>(*this);
418416

lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ def cleanup():
218218

219219
self.assertGreater(thread.GetNumFrames(), 0)
220220

221+
self.assertTrue(thread, "Invalid thread.")
222+
self.assertEqual(thread.GetThreadID(), 0x19)
223+
self.assertEqual(thread.GetName(), "DummyScriptedThread.thread-1")
224+
self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonTrace)
225+
226+
self.assertGreater(thread.GetNumFrames(), 0)
227+
221228
frame = thread.GetFrameAtIndex(0)
222229
GPRs = None
223230
register_set = frame.registers # Returns an SBValueList.

0 commit comments

Comments
 (0)