LLDB mainline
ScriptedPlatformPythonInterface.cpp
Go to the documentation of this file.
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
10#include "lldb/Host/Config.h"
12#include "lldb/Utility/Log.h"
13#include "lldb/Utility/Status.h"
15
16#if LLDB_ENABLE_PYTHON
17
18// clang-format off
19// LLDB Python header must be included first
20#include "../lldb-python.h"
21//clang-format on
22
23#include "../SWIGPythonBridge.h"
24#include "../ScriptInterpreterPythonImpl.h"
26
27using namespace lldb;
28using namespace lldb_private;
29using namespace lldb_private::python;
30using Locker = ScriptInterpreterPythonImpl::Locker;
31
32ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
33 ScriptInterpreterPythonImpl &interpreter)
34 : ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
35
36llvm::Expected<StructuredData::GenericSP>
37ScriptedPlatformPythonInterface::CreatePluginObject(
38 llvm::StringRef class_name, ExecutionContext &exe_ctx,
40 ExecutionContextRefSP exe_ctx_ref_sp =
41 std::make_shared<ExecutionContextRef>(exe_ctx);
42 StructuredDataImpl sd_impl(args_sp);
43 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
44 exe_ctx_ref_sp, sd_impl);
45}
46
47StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
50 Dispatch<StructuredData::DictionarySP>("list_processes", error);
51
52 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
53 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
54 LLVM_PRETTY_FUNCTION,
55 llvm::Twine("Null or invalid object (" +
56 llvm::Twine(error.AsCString()) + llvm::Twine(")."))
57 .str(),
58 error);
59 }
60
61 return dict_sp;
62}
63
65ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) {
68 Dispatch<StructuredData::DictionarySP>("get_process_info", error, pid);
69
70 if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
71 return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
72 LLVM_PRETTY_FUNCTION,
73 llvm::Twine("Null or invalid object (" +
74 llvm::Twine(error.AsCString()) + llvm::Twine(")."))
75 .str(),
76 error);
77 }
78
79 return dict_sp;
80}
81
82Status ScriptedPlatformPythonInterface::AttachToProcess(
83 ProcessAttachInfoSP attach_info) {
84 // FIXME: Pass `attach_info` to method call
85 return GetStatusFromMethod("attach_to_process");
86}
87
88Status ScriptedPlatformPythonInterface::LaunchProcess(
89 ProcessLaunchInfoSP launch_info) {
90 // FIXME: Pass `launch_info` to method call
91 return GetStatusFromMethod("launch_process");
92}
93
94Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
95 return GetStatusFromMethod("kill_process", pid);
96}
97
98void ScriptedPlatformPythonInterface::Initialize() {
99 PluginManager::RegisterPlugin(
100 GetPluginNameStatic(), "Mock platform and interact with its processes.",
101 CreateInstance, eScriptLanguagePython, {});
102}
103
104void ScriptedPlatformPythonInterface::Terminate() {
105 PluginManager::UnregisterPlugin(CreateInstance);
106}
107
108#endif // LLDB_ENABLE_PYTHON
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
An error handling class.
Definition: Status.h:44
std::shared_ptr< Dictionary > DictionarySP
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ProcessAttachInfo > ProcessAttachInfoSP
Definition: lldb-forward.h:388
uint64_t pid_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::ProcessLaunchInfo > ProcessLaunchInfoSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition: lldb-forward.h:348