Skip to content

Commit 82252b6

Browse files
committed
[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 <[email protected]>
1 parent 637f306 commit 82252b6

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

lldb/bindings/interface/SBProcess.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ public:
241241
void
242242
SendAsyncInterrupt();
243243

244+
void
245+
ForceScriptedState(StateType new_state);
246+
244247
%feature("autodoc", "
245248
Reads memory from the current process's address space and removes any
246249
traps that may have been inserted into the memory. It returns the byte

lldb/include/lldb/API/SBProcess.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ class LLDB_API SBProcess {
182182
/// The stop event corresponding to stop ID.
183183
lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
184184

185+
/// If the process is a scripted process, changes its state to the new state.
186+
/// No-op otherwise.
187+
///
188+
/// \param [in] new_state
189+
/// The new state that the scripted process should be set to.
190+
///
191+
void ForceScriptedState(StateType new_state);
192+
185193
size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
186194

187195
size_t WriteMemory(addr_t addr, const void *buf, size_t size,

lldb/include/lldb/Target/Process.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,8 @@ void PruneThreadPlans();
26002600

26012601
virtual void *GetImplementation() { return nullptr; }
26022602

2603+
virtual void ForceScriptedState(lldb::StateType state) {}
2604+
26032605
protected:
26042606
friend class Trace;
26052607

lldb/source/API/SBProcess.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,16 @@ SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) {
466466
return sb_event;
467467
}
468468

469+
void SBProcess::ForceScriptedState(StateType new_state) {
470+
LLDB_INSTRUMENT_VA(this, new_state);
471+
472+
if (ProcessSP process_sp = GetSP()) {
473+
std::lock_guard<std::recursive_mutex> guard(
474+
process_sp->GetTarget().GetAPIMutex());
475+
process_sp->ForceScriptedState(new_state);
476+
}
477+
}
478+
469479
StateType SBProcess::GetState() {
470480
LLDB_INSTRUMENT_VA(this);
471481

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class ScriptedProcess : public Process {
8888

8989
void *GetImplementation() override;
9090

91+
void ForceScriptedState(lldb::StateType state) override {
92+
SetPrivateState(state);
93+
}
94+
9195
protected:
9296
ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
9397
const ScriptedMetadata &scripted_metadata, Status &error);

0 commit comments

Comments
 (0)