1 //===-- ScriptedThreadPlanPythonInterface.cpp -----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/PluginManager.h"
10 #include "lldb/Host/Config.h"
11 #include "lldb/Utility/Log.h"
12 #include "lldb/lldb-enumerations.h"
14 #if LLDB_ENABLE_PYTHON
17 // LLDB Python header must be included first
18 #include "../lldb-python.h"
21 #include "../SWIGPythonBridge.h"
22 #include "../ScriptInterpreterPythonImpl.h"
23 #include "ScriptedThreadPlanPythonInterface.h"
26 using namespace lldb_private
;
27 using namespace lldb_private::python
;
29 ScriptedThreadPlanPythonInterface::ScriptedThreadPlanPythonInterface(
30 ScriptInterpreterPythonImpl
&interpreter
)
31 : ScriptedThreadPlanInterface(), ScriptedPythonInterface(interpreter
) {}
33 llvm::Expected
<StructuredData::GenericSP
>
34 ScriptedThreadPlanPythonInterface::CreatePluginObject(
35 const llvm::StringRef class_name
, lldb::ThreadPlanSP thread_plan_sp
,
36 const StructuredDataImpl
&args_sp
) {
37 return ScriptedPythonInterface::CreatePluginObject(class_name
, nullptr,
38 thread_plan_sp
, args_sp
);
42 ScriptedThreadPlanPythonInterface::ExplainsStop(Event
*event
) {
44 StructuredData::ObjectSP obj
= Dispatch("explains_stop", error
, event
);
46 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION
, obj
,
50 return error
.ToError();
53 return obj
->GetBooleanValue();
57 ScriptedThreadPlanPythonInterface::ShouldStop(Event
*event
) {
59 StructuredData::ObjectSP obj
= Dispatch("should_stop", error
, event
);
61 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION
, obj
,
65 return error
.ToError();
68 return obj
->GetBooleanValue();
71 llvm::Expected
<bool> ScriptedThreadPlanPythonInterface::IsStale() {
73 StructuredData::ObjectSP obj
= Dispatch("is_stale", error
);
75 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION
, obj
,
79 return error
.ToError();
82 return obj
->GetBooleanValue();
85 lldb::StateType
ScriptedThreadPlanPythonInterface::GetRunState() {
87 StructuredData::ObjectSP obj
= Dispatch("should_step", error
);
89 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION
, obj
,
91 return lldb::eStateStepping
;
93 return static_cast<lldb::StateType
>(obj
->GetUnsignedIntegerValue(
94 static_cast<uint32_t>(lldb::eStateStepping
)));
98 ScriptedThreadPlanPythonInterface::GetStopDescription(lldb::StreamSP
&stream
) {
100 Dispatch("stop_description", error
, stream
);
103 return error
.ToError();
105 return llvm::Error::success();
108 void ScriptedThreadPlanPythonInterface::Initialize() {
109 const std::vector
<llvm::StringRef
> ci_usages
= {
110 "thread step-scripted -C <script-name> [-k key -v value ...]"};
111 const std::vector
<llvm::StringRef
> api_usages
= {
112 "SBThread.StepUsingScriptedThreadPlan"};
113 PluginManager::RegisterPlugin(
114 GetPluginNameStatic(),
115 llvm::StringRef("Alter thread stepping logic and stop reason"),
116 CreateInstance
, eScriptLanguagePython
, {ci_usages
, api_usages
});
119 void ScriptedThreadPlanPythonInterface::Terminate() {
120 PluginManager::UnregisterPlugin(CreateInstance
);