[Lldb-commits] [lldb] 0d77e03 - [lldb/API] Introduce SBProcess::ForceScriptedState method

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 25 15:04:17 PDT 2023


Author: Med Ismail Bennani
Date: 2023-04-25T15:02:33-07:00
New Revision: 0d77e034749f57676fd79e4a5b560be4d5b52b48

URL: https://github.com/llvm/llvm-project/commit/0d77e034749f57676fd79e4a5b560be4d5b52b48
DIFF: https://github.com/llvm/llvm-project/commit/0d77e034749f57676fd79e4a5b560be4d5b52b48.diff

LOG: [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 <medismail.bennani at gmail.com>

Added: 
    

Modified: 
    lldb/include/lldb/API/SBProcess.h
    lldb/include/lldb/Target/Process.h
    lldb/source/API/SBProcess.cpp
    lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h
index b7eb2036dbe47..d1e15cc5c1f71 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -186,6 +186,14 @@ class LLDB_API SBProcess {
   ///   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 808226067d5a6..b4b75e52d572a 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 ca473175f18f0..2004b66eafe34 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<std::recursive_mutex> 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 60f42cbaf7f2c..9837f7f2c7c00 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -90,6 +90,10 @@ class ScriptedProcess : public Process {
 
   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);


        


More information about the lldb-commits mailing list