From 0d77e034749f57676fd79e4a5b560be4d5b52b48 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 13 Mar 2023 15:34:29 -0700 Subject: [PATCH] [lldb/API] Introduce SBProcess::ForceScriptedState method This patch introduces a new method to the SBProcess API called ForceScriptedState. As the name suggests, this affordance will allow the user to alter the state of the scripted process programatically. This is necessary to update the scripted process state when perform interactive debugging. Differential Revision: https://reviews.llvm.org/D145294 Signed-off-by: Med Ismail Bennani --- lldb/include/lldb/API/SBProcess.h | 8 ++++++++ lldb/include/lldb/Target/Process.h | 2 ++ lldb/source/API/SBProcess.cpp | 10 ++++++++++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index b7eb203..d1e15cc 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -186,6 +186,14 @@ public: /// The stop event corresponding to stop ID. lldb::SBEvent GetStopEventForStopID(uint32_t stop_id); + /// If the process is a scripted process, changes its state to the new state. + /// No-op otherwise. + /// + /// \param [in] new_state + /// The new state that the scripted process should be set to. + /// + void ForceScriptedState(StateType new_state); + size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error); size_t WriteMemory(addr_t addr, const void *buf, size_t size, diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 8082260..b4b75e5 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2565,6 +2565,8 @@ void PruneThreadPlans(); virtual void *GetImplementation() { return nullptr; } + virtual void ForceScriptedState(lldb::StateType state) {} + protected: friend class Trace; diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index ca47317..2004b66 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -466,6 +466,16 @@ SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) { return sb_event; } +void SBProcess::ForceScriptedState(StateType new_state) { + LLDB_INSTRUMENT_VA(this, new_state); + + if (ProcessSP process_sp = GetSP()) { + std::lock_guard guard( + process_sp->GetTarget().GetAPIMutex()); + process_sp->ForceScriptedState(new_state); + } +} + StateType SBProcess::GetState() { LLDB_INSTRUMENT_VA(this); diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h index 60f42cb..9837f7f 100644 --- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h +++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h @@ -90,6 +90,10 @@ public: void *GetImplementation() override; + void ForceScriptedState(lldb::StateType state) override { + SetPrivateState(state); + } + protected: ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const ScriptedMetadata &scripted_metadata, Status &error); -- 2.7.4