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/Host/Config.h"
10 #include "lldb/Utility/Log.h"
11 #include "lldb/lldb-enumerations.h"
12 
13 #if LLDB_ENABLE_PYTHON
14 
15 // LLDB Python header must be included first
16 #include "../lldb-python.h"
17 
18 #include "../SWIGPythonBridge.h"
19 #include "../ScriptInterpreterPythonImpl.h"
20 #include "ScriptedThreadPlanPythonInterface.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 using namespace lldb_private::python;
25 
26 ScriptedThreadPlanPythonInterface::ScriptedThreadPlanPythonInterface(
27     ScriptInterpreterPythonImpl &interpreter)
28     : ScriptedThreadPlanInterface(), ScriptedPythonInterface(interpreter) {}
29 
30 llvm::Expected<StructuredData::GenericSP>
31 ScriptedThreadPlanPythonInterface::CreatePluginObject(
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 
38 llvm::Expected<bool>
39 ScriptedThreadPlanPythonInterface::ExplainsStop(Event *event) {
40   Status error;
41   StructuredData::ObjectSP obj = Dispatch("explains_stop", error, event);
42 
43   if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
44     return error.ToError();
45 
46   return obj->GetBooleanValue();
47 }
48 
49 llvm::Expected<bool>
50 ScriptedThreadPlanPythonInterface::ShouldStop(Event *event) {
51   Status error;
52   StructuredData::ObjectSP obj = Dispatch("should_stop", error, event);
53 
54   if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
55     return error.ToError();
56 
57   return obj->GetBooleanValue();
58 }
59 
60 llvm::Expected<bool> ScriptedThreadPlanPythonInterface::IsStale() {
61   Status error;
62   StructuredData::ObjectSP obj = Dispatch("is_stale", error);
63 
64   if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
65     return error.ToError();
66 
67   return obj->GetBooleanValue();
68 }
69 
70 lldb::StateType ScriptedThreadPlanPythonInterface::GetRunState() {
71   Status error;
72   StructuredData::ObjectSP obj = Dispatch("should_step", error);
73 
74   if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
75     return lldb::eStateStepping;
76 
77   return static_cast<lldb::StateType>(obj->GetUnsignedIntegerValue(
78       static_cast<uint32_t>(lldb::eStateStepping)));
79 }
80 
81 llvm::Expected<bool>
82 ScriptedThreadPlanPythonInterface::GetStopDescription(lldb_private::Stream *s) {
83   Status error;
84   Dispatch("stop_description", error, s);
85 
86   if (error.Fail())
87     return error.ToError();
88 
89   return true;
90 }
91 
92 #endif
93