Skip to content

Commit

Permalink
[lldb/API] Introduce SBProcess::ForceScriptedState method
Browse files Browse the repository at this point in the history
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 private 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]>
  • Loading branch information
medismailben committed Mar 6, 2023
1 parent a02c3af commit 3675e0b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lldb/include/lldb/API/SBProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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 private state.
/// No-op otherwise.
///
/// \param [in] new_state
/// The new private 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,
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,8 @@ void PruneThreadPlans();

virtual void *GetImplementation() { return nullptr; }

virtual void ForceScriptedState(lldb::StateType state) {}

protected:
friend class Trace;

Expand Down
10 changes: 10 additions & 0 deletions lldb/source/API/SBProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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);
Expand Down

0 comments on commit 3675e0b

Please sign in to comment.