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 (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, 44 error)) 45 return error.ToError(); 46 47 return obj->GetBooleanValue(); 48 } 49 50 llvm::Expected<bool> 51 ScriptedThreadPlanPythonInterface::ShouldStop(Event *event) { 52 Status error; 53 StructuredData::ObjectSP obj = Dispatch("should_stop", error, event); 54 55 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, 56 error)) 57 return error.ToError(); 58 59 return obj->GetBooleanValue(); 60 } 61 62 llvm::Expected<bool> ScriptedThreadPlanPythonInterface::IsStale() { 63 Status error; 64 StructuredData::ObjectSP obj = Dispatch("is_stale", error); 65 66 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, 67 error)) 68 return error.ToError(); 69 70 return obj->GetBooleanValue(); 71 } 72 73 lldb::StateType ScriptedThreadPlanPythonInterface::GetRunState() { 74 Status error; 75 StructuredData::ObjectSP obj = Dispatch("should_step", error); 76 77 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, 78 error)) 79 return lldb::eStateStepping; 80 81 return static_cast<lldb::StateType>(obj->GetUnsignedIntegerValue( 82 static_cast<uint32_t>(lldb::eStateStepping))); 83 } 84 85 llvm::Expected<bool> 86 ScriptedThreadPlanPythonInterface::GetStopDescription(lldb_private::Stream *s) { 87 Status error; 88 Dispatch("stop_description", error, s); 89 90 if (error.Fail()) 91 return error.ToError(); 92 93 return true; 94 } 95 96 #endif 97