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
9#include "lldb/Host/Config.h"
10#include "lldb/Utility/Log.h"
11#include "lldb/Utility/Status.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"
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,
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
43StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
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
61ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) {
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
78Status ScriptedPlatformPythonInterface::AttachToProcess(
79 ProcessAttachInfoSP attach_info) {
80 // FIXME: Pass `attach_info` to method call
81 return GetStatusFromMethod("attach_to_process");
82}
83
84Status ScriptedPlatformPythonInterface::LaunchProcess(
85 ProcessLaunchInfoSP launch_info) {
86 // FIXME: Pass `launch_info` to method call
87 return GetStatusFromMethod("launch_process");
88}
89
90Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
91 return GetStatusFromMethod("kill_process", pid);
92}
93
94#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: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ProcessAttachInfo > ProcessAttachInfoSP
Definition: lldb-forward.h:382
uint64_t pid_t
Definition: lldb-types.h:81
std::shared_ptr< lldb_private::ProcessLaunchInfo > ProcessLaunchInfoSP
Definition: lldb-forward.h:383
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition: lldb-forward.h:342