LLDB mainline
ScriptedThreadPlanPythonInterface.cpp
Go to the documentation of this file.
1//===-- ScriptedThreadPlanPythonInterface.cpp -----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "../lldb-python.h"
10
13#include "lldb/Utility/Log.h"
15
16#include "../SWIGPythonBridge.h"
19
20using namespace lldb;
21using namespace lldb_private;
22using namespace lldb_private::python;
23
27
28llvm::Expected<StructuredData::GenericSP>
30 const ScriptedMetadata &scripted_metadata,
31 lldb::ThreadPlanSP thread_plan_sp) {
32 StructuredDataImpl args_sp(scripted_metadata.GetArgsSP());
33 return ScriptedPythonInterface::CreatePluginObject(scripted_metadata, nullptr,
34 thread_plan_sp, args_sp);
35}
36
37llvm::Expected<bool>
40 StructuredData::ObjectSP obj = Dispatch("explains_stop", error, event);
41
42 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
43 error)) {
44 if (!obj)
45 return false;
46 return error.ToError();
47 }
48
49 return obj->GetBooleanValue();
50}
51
52llvm::Expected<bool>
55 StructuredData::ObjectSP obj = Dispatch("should_stop", error, event);
56
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
58 error)) {
59 if (!obj)
60 return false;
61 return error.ToError();
62 }
63
64 return obj->GetBooleanValue();
65}
66
69 StructuredData::ObjectSP obj = Dispatch("is_stale", error);
70
71 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
72 error)) {
73 if (!obj)
74 return false;
75 return error.ToError();
76 }
77
78 return obj->GetBooleanValue();
79}
80
83 StructuredData::ObjectSP obj = Dispatch("should_step", error);
84
85 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
86 error))
88
89 return static_cast<lldb::StateType>(obj->GetUnsignedIntegerValue(
90 static_cast<uint32_t>(lldb::eStateStepping)));
91}
92
93llvm::Error
96 Dispatch("stop_description", error, stream);
97
98 if (error.Fail())
99 return error.ToError();
100
101 return llvm::Error::success();
102}
103
105 const std::vector<llvm::StringRef> ci_usages = {
106 "thread step-scripted -C <script-name> [-k key -v value ...]"};
107 const std::vector<llvm::StringRef> api_usages = {
108 "SBThread.StepUsingScriptedThreadPlan"};
111 llvm::StringRef("Alter thread stepping logic and stop reason"),
112 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
113}
114
static llvm::raw_ostream & error(Stream &strm)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
StructuredData::DictionarySP GetArgsSP() const
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
llvm::Error GetStopDescription(lldb::StreamSP &stream) override
llvm::Expected< bool > ShouldStop(Event *event) override
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, lldb::ThreadPlanSP thread_plan_sp) override
ScriptedThreadPlanPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< bool > ExplainsStop(Event *event) override
An error handling class.
Definition Status.h:118
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
@ eScriptLanguagePython
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
StateType
Process and Thread States.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
std::shared_ptr< lldb_private::Stream > StreamSP