[lldb/API] Introduce SBProcess::ForceScriptedState method
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Mon, 13 Mar 2023 22:34:29 +0000 (15:34 -0700)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Tue, 25 Apr 2023 22:02:33 +0000 (15:02 -0700)
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 <medismail.bennani@gmail.com>
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

index b7eb203..d1e15cc 100644 (file)
@@ -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,
index 8082260..b4b75e5 100644 (file)
@@ -2565,6 +2565,8 @@ void PruneThreadPlans();
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 
index ca47317..2004b66 100644 (file)
@@ -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<std::recursive_mutex> guard(
+        process_sp->GetTarget().GetAPIMutex());
+    process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 
index 60f42cb..9837f7f 100644 (file)
@@ -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);