1ac9a064cSDimitry Andric //===-- ScriptedThreadPlanPythonInterface.cpp -----------------------------===//
2ac9a064cSDimitry Andric //
3ac9a064cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ac9a064cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5ac9a064cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ac9a064cSDimitry Andric //
7ac9a064cSDimitry Andric //===----------------------------------------------------------------------===//
8ac9a064cSDimitry Andric
9ac9a064cSDimitry Andric #include "lldb/Host/Config.h"
10ac9a064cSDimitry Andric #include "lldb/Utility/Log.h"
11ac9a064cSDimitry Andric #include "lldb/lldb-enumerations.h"
12ac9a064cSDimitry Andric
13ac9a064cSDimitry Andric #if LLDB_ENABLE_PYTHON
14ac9a064cSDimitry Andric
15ac9a064cSDimitry Andric // LLDB Python header must be included first
16ac9a064cSDimitry Andric #include "../lldb-python.h"
17ac9a064cSDimitry Andric
18ac9a064cSDimitry Andric #include "../SWIGPythonBridge.h"
19ac9a064cSDimitry Andric #include "../ScriptInterpreterPythonImpl.h"
20ac9a064cSDimitry Andric #include "ScriptedThreadPlanPythonInterface.h"
21ac9a064cSDimitry Andric
22ac9a064cSDimitry Andric using namespace lldb;
23ac9a064cSDimitry Andric using namespace lldb_private;
24ac9a064cSDimitry Andric using namespace lldb_private::python;
25ac9a064cSDimitry Andric
ScriptedThreadPlanPythonInterface(ScriptInterpreterPythonImpl & interpreter)26ac9a064cSDimitry Andric ScriptedThreadPlanPythonInterface::ScriptedThreadPlanPythonInterface(
27ac9a064cSDimitry Andric ScriptInterpreterPythonImpl &interpreter)
28ac9a064cSDimitry Andric : ScriptedThreadPlanInterface(), ScriptedPythonInterface(interpreter) {}
29ac9a064cSDimitry Andric
30ac9a064cSDimitry Andric llvm::Expected<StructuredData::GenericSP>
CreatePluginObject(const llvm::StringRef class_name,lldb::ThreadPlanSP thread_plan_sp,const StructuredDataImpl & args_sp)31ac9a064cSDimitry Andric ScriptedThreadPlanPythonInterface::CreatePluginObject(
32ac9a064cSDimitry Andric const llvm::StringRef class_name, lldb::ThreadPlanSP thread_plan_sp,
33ac9a064cSDimitry Andric const StructuredDataImpl &args_sp) {
34ac9a064cSDimitry Andric return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
35ac9a064cSDimitry Andric thread_plan_sp, args_sp);
36ac9a064cSDimitry Andric }
37ac9a064cSDimitry Andric
38ac9a064cSDimitry Andric llvm::Expected<bool>
ExplainsStop(Event * event)39ac9a064cSDimitry Andric ScriptedThreadPlanPythonInterface::ExplainsStop(Event *event) {
40ac9a064cSDimitry Andric Status error;
41ac9a064cSDimitry Andric StructuredData::ObjectSP obj = Dispatch("explains_stop", error, event);
42ac9a064cSDimitry Andric
43ac9a064cSDimitry Andric if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
44ac9a064cSDimitry Andric error)) {
45ac9a064cSDimitry Andric if (!obj)
46ac9a064cSDimitry Andric return false;
47ac9a064cSDimitry Andric return error.ToError();
48ac9a064cSDimitry Andric }
49ac9a064cSDimitry Andric
50ac9a064cSDimitry Andric return obj->GetBooleanValue();
51ac9a064cSDimitry Andric }
52ac9a064cSDimitry Andric
53ac9a064cSDimitry Andric llvm::Expected<bool>
ShouldStop(Event * event)54ac9a064cSDimitry Andric ScriptedThreadPlanPythonInterface::ShouldStop(Event *event) {
55ac9a064cSDimitry Andric Status error;
56ac9a064cSDimitry Andric StructuredData::ObjectSP obj = Dispatch("should_stop", error, event);
57ac9a064cSDimitry Andric
58ac9a064cSDimitry Andric if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
59ac9a064cSDimitry Andric error)) {
60ac9a064cSDimitry Andric if (!obj)
61ac9a064cSDimitry Andric return false;
62ac9a064cSDimitry Andric return error.ToError();
63ac9a064cSDimitry Andric }
64ac9a064cSDimitry Andric
65ac9a064cSDimitry Andric return obj->GetBooleanValue();
66ac9a064cSDimitry Andric }
67ac9a064cSDimitry Andric
IsStale()68ac9a064cSDimitry Andric llvm::Expected<bool> ScriptedThreadPlanPythonInterface::IsStale() {
69ac9a064cSDimitry Andric Status error;
70ac9a064cSDimitry Andric StructuredData::ObjectSP obj = Dispatch("is_stale", error);
71ac9a064cSDimitry Andric
72ac9a064cSDimitry Andric if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
73ac9a064cSDimitry Andric error)) {
74ac9a064cSDimitry Andric if (!obj)
75ac9a064cSDimitry Andric return false;
76ac9a064cSDimitry Andric return error.ToError();
77ac9a064cSDimitry Andric }
78ac9a064cSDimitry Andric
79ac9a064cSDimitry Andric return obj->GetBooleanValue();
80ac9a064cSDimitry Andric }
81ac9a064cSDimitry Andric
GetRunState()82ac9a064cSDimitry Andric lldb::StateType ScriptedThreadPlanPythonInterface::GetRunState() {
83ac9a064cSDimitry Andric Status error;
84ac9a064cSDimitry Andric StructuredData::ObjectSP obj = Dispatch("should_step", error);
85ac9a064cSDimitry Andric
86ac9a064cSDimitry Andric if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
87ac9a064cSDimitry Andric error))
88ac9a064cSDimitry Andric return lldb::eStateStepping;
89ac9a064cSDimitry Andric
90ac9a064cSDimitry Andric return static_cast<lldb::StateType>(obj->GetUnsignedIntegerValue(
91ac9a064cSDimitry Andric static_cast<uint32_t>(lldb::eStateStepping)));
92ac9a064cSDimitry Andric }
93ac9a064cSDimitry Andric
94ac9a064cSDimitry Andric llvm::Error
GetStopDescription(lldb::StreamSP & stream)95ac9a064cSDimitry Andric ScriptedThreadPlanPythonInterface::GetStopDescription(lldb::StreamSP &stream) {
96ac9a064cSDimitry Andric Status error;
97ac9a064cSDimitry Andric Dispatch("stop_description", error, stream);
98ac9a064cSDimitry Andric
99ac9a064cSDimitry Andric if (error.Fail())
100ac9a064cSDimitry Andric return error.ToError();
101ac9a064cSDimitry Andric
102ac9a064cSDimitry Andric return llvm::Error::success();
103ac9a064cSDimitry Andric }
104ac9a064cSDimitry Andric
105ac9a064cSDimitry Andric #endif
106