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
23using namespace lldb;
24using namespace lldb_private;
25using namespace lldb_private::python;
26using Locker = ScriptInterpreterPythonImpl::Locker;
27
28ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
29 ScriptInterpreterPythonImpl &interpreter)
30 : ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
31
32llvm::Expected<StructuredData::GenericSP>
33ScriptedPlatformPythonInterface::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>(args&: exe_ctx);
38 StructuredDataImpl sd_impl(args_sp);
39 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
40 args: exe_ctx_ref_sp, args: sd_impl);
41}
42
43StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
44 Status error;
45 StructuredData::DictionarySP dict_sp =
46 Dispatch<StructuredData::DictionarySP>(method_name: "list_processes", error);
47
48 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
49 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
50 LLVM_PRETTY_FUNCTION,
51 error_msg: 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
60StructuredData::DictionarySP
61ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) {
62 Status error;
63 StructuredData::DictionarySP dict_sp =
64 Dispatch<StructuredData::DictionarySP>(method_name: "get_process_info", error, args&: pid);
65
66 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
67 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
68 LLVM_PRETTY_FUNCTION,
69 error_msg: 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
78Status ScriptedPlatformPythonInterface::AttachToProcess(
79 ProcessAttachInfoSP attach_info) {
80 // FIXME: Pass `attach_info` to method call
81 return GetStatusFromMethod(method_name: "attach_to_process");
82}
83
84Status ScriptedPlatformPythonInterface::LaunchProcess(
85 ProcessLaunchInfoSP launch_info) {
86 // FIXME: Pass `launch_info` to method call
87 return GetStatusFromMethod(method_name: "launch_process");
88}
89
90Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
91 return GetStatusFromMethod(method_name: "kill_process", args&: pid);
92}
93
94#endif // LLDB_ENABLE_PYTHON
95

source code of lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp