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
10#include "lldb/Utility/Log.h"
12
13// clang-format off
14// LLDB Python header must be included first
15#include "../lldb-python.h"
16//clang-format on
17
18#include "../SWIGPythonBridge.h"
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::python;
25
29
30llvm::Expected<StructuredData::GenericSP>
32 const llvm::StringRef class_name, lldb::ThreadPlanSP thread_plan_sp,
33 const StructuredDataImpl &args_sp) {
34 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
35 thread_plan_sp, args_sp);
36}
37
38llvm::Expected<bool>
41 StructuredData::ObjectSP obj = Dispatch("explains_stop", error, event);
42
43 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
44 error)) {
45 if (!obj)
46 return false;
47 return error.ToError();
48 }
49
50 return obj->GetBooleanValue();
51}
52
53llvm::Expected<bool>
56 StructuredData::ObjectSP obj = Dispatch("should_stop", error, event);
57
58 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
59 error)) {
60 if (!obj)
61 return false;
62 return error.ToError();
63 }
64
65 return obj->GetBooleanValue();
66}
67
70 StructuredData::ObjectSP obj = Dispatch("is_stale", error);
71
72 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
73 error)) {
74 if (!obj)
75 return false;
76 return error.ToError();
77 }
78
79 return obj->GetBooleanValue();
80}
81
84 StructuredData::ObjectSP obj = Dispatch("should_step", error);
85
86 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
87 error))
89
90 return static_cast<lldb::StateType>(obj->GetUnsignedIntegerValue(
91 static_cast<uint32_t>(lldb::eStateStepping)));
92}
93
94llvm::Error
97 Dispatch("stop_description", error, stream);
98
99 if (error.Fail())
100 return error.ToError();
101
102 return llvm::Error::success();
103}
104
106 const std::vector<llvm::StringRef> ci_usages = {
107 "thread step-scripted -C <script-name> [-k key -v value ...]"};
108 const std::vector<llvm::StringRef> api_usages = {
109 "SBThread.StepUsingScriptedThreadPlan"};
112 llvm::StringRef("Alter thread stepping logic and stop reason"),
113 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
114}
115
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)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Error GetStopDescription(lldb::StreamSP &stream) override
llvm::Expected< bool > ShouldStop(Event *event) override
ScriptedThreadPlanPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const llvm::StringRef class_name, lldb::ThreadPlanSP thread_plan_sp, const StructuredDataImpl &args_sp) override
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