1 //===-- ScriptedPlatformPythonInterface.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/Utility/Status.h" 12 #include "lldb/lldb-enumerations.h" 13 14 #if LLDB_ENABLE_PYTHON 15 16 // LLDB Python header must be included first 17 #include "../lldb-python.h" 18 19 #include "../SWIGPythonBridge.h" 20 #include "../ScriptInterpreterPythonImpl.h" 21 #include "ScriptedPlatformPythonInterface.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 using namespace lldb_private::python; 26 using Locker = ScriptInterpreterPythonImpl::Locker; 27 28 ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface( 29 ScriptInterpreterPythonImpl &interpreter) 30 : ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {} 31 32 llvm::Expected<StructuredData::GenericSP> 33 ScriptedPlatformPythonInterface::CreatePluginObject( 34 llvm::StringRef class_name, ExecutionContext &exe_ctx, 35 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) { 36 ExecutionContextRefSP exe_ctx_ref_sp = 37 std::make_shared<ExecutionContextRef>(exe_ctx); 38 StructuredDataImpl sd_impl(args_sp); 39 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj, 40 exe_ctx_ref_sp, sd_impl); 41 } 42 43 StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() { 44 Status error; 45 StructuredData::DictionarySP dict_sp = 46 Dispatch<StructuredData::DictionarySP>("list_processes", error); 47 48 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) { 49 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>( 50 LLVM_PRETTY_FUNCTION, 51 llvm::Twine("Null or invalid object (" + 52 llvm::Twine(error.AsCString()) + llvm::Twine(").")) 53 .str(), 54 error); 55 } 56 57 return dict_sp; 58 } 59 60 StructuredData::DictionarySP 61 ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) { 62 Status error; 63 StructuredData::DictionarySP dict_sp = 64 Dispatch<StructuredData::DictionarySP>("get_process_info", error, pid); 65 66 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) { 67 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>( 68 LLVM_PRETTY_FUNCTION, 69 llvm::Twine("Null or invalid object (" + 70 llvm::Twine(error.AsCString()) + llvm::Twine(").")) 71 .str(), 72 error); 73 } 74 75 return dict_sp; 76 } 77 78 Status ScriptedPlatformPythonInterface::AttachToProcess( 79 ProcessAttachInfoSP attach_info) { 80 // FIXME: Pass `attach_info` to method call 81 return GetStatusFromMethod("attach_to_process"); 82 } 83 84 Status ScriptedPlatformPythonInterface::LaunchProcess( 85 ProcessLaunchInfoSP launch_info) { 86 // FIXME: Pass `launch_info` to method call 87 return GetStatusFromMethod("launch_process"); 88 } 89 90 Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) { 91 return GetStatusFromMethod("kill_process", pid); 92 } 93 94 #endif // LLDB_ENABLE_PYTHON 95