LLDB mainline
OperatingSystemPythonInterface.cpp
Go to the documentation of this file.
1//===-- ScriptedThreadPythonInterface.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"
14
15#if LLDB_ENABLE_PYTHON
16
17// clang-format off
18// LLDB Python header must be included first
19#include "../lldb-python.h"
20//clang-format on
21
22#include "../SWIGPythonBridge.h"
23#include "../ScriptInterpreterPythonImpl.h"
25
26using namespace lldb;
27using namespace lldb_private;
28using namespace lldb_private::python;
29using Locker = ScriptInterpreterPythonImpl::Locker;
30
31OperatingSystemPythonInterface::OperatingSystemPythonInterface(
32 ScriptInterpreterPythonImpl &interpreter)
33 : OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
34
35llvm::Expected<StructuredData::GenericSP>
36OperatingSystemPythonInterface::CreatePluginObject(
37 llvm::StringRef class_name, ExecutionContext &exe_ctx,
39 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
40 exe_ctx.GetProcessSP());
41}
42
44OperatingSystemPythonInterface::CreateThread(lldb::tid_t tid,
45 lldb::addr_t context) {
47 StructuredData::DictionarySP dict = Dispatch<StructuredData::DictionarySP>(
48 "create_thread", error, tid, context);
49
50 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
51 error))
52 return {};
53
54 return dict;
55}
56
57StructuredData::ArraySP OperatingSystemPythonInterface::GetThreadInfo() {
60 Dispatch<StructuredData::ArraySP>("get_thread_info", error);
61
62 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
63 error))
64 return {};
65
66 return arr;
67}
68
69StructuredData::DictionarySP OperatingSystemPythonInterface::GetRegisterInfo() {
70 return ScriptedThreadPythonInterface::GetRegisterInfo();
71}
72
73std::optional<std::string>
74OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
76 StructuredData::ObjectSP obj = Dispatch("get_register_data", error, tid);
77
78 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
79 error))
80 return {};
81
82 return obj->GetAsString()->GetValue().str();
83}
84
85void OperatingSystemPythonInterface::Initialize() {
86 const std::vector<llvm::StringRef> ci_usages = {
87 "settings set target.process.python-os-plugin-path <script-path>",
88 "settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
89 const std::vector<llvm::StringRef> api_usages = {};
90 PluginManager::RegisterPlugin(
91 GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
92 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
93}
94
95void OperatingSystemPythonInterface::Terminate() {
96 PluginManager::UnregisterPlugin(CreateInstance);
97}
98
99#endif
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
An error handling class.
Definition: Status.h:44
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t addr_t
Definition: lldb-types.h:80
uint64_t tid_t
Definition: lldb-types.h:84