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
9#include "../lldb-python.h"
10
13#include "lldb/Target/Process.h"
14#include "lldb/Utility/Log.h"
16
17#include "../SWIGPythonBridge.h"
20
21using namespace lldb;
22using namespace lldb_private;
23using namespace lldb_private::python;
25
29
30llvm::Expected<StructuredData::GenericSP>
32 const ScriptedMetadata &scripted_metadata, ExecutionContext &exe_ctx,
33 StructuredData::Generic *script_obj) {
34 return ScriptedPythonInterface::CreatePluginObject(scripted_metadata, nullptr,
35 exe_ctx.GetProcessSP());
36}
37
40 lldb::addr_t context) {
42 Dispatch<StructuredData::DictionarySP>("create_thread", tid, context),
43 LLVM_PRETTY_FUNCTION);
44 if (!dict)
45 return {};
46
47 return dict;
48}
49
53 LLVM_PRETTY_FUNCTION);
54 if (!arr)
55 return {};
56
57 return arr;
58}
59
63
64std::optional<std::string>
67 LogAndDefault(Dispatch("get_register_data", tid), LLVM_PRETTY_FUNCTION);
68 if (!obj)
69 return {};
70
71 return obj->GetStringValue().str();
72}
73
76 Dispatch("does_plugin_report_all_threads"), LLVM_PRETTY_FUNCTION);
77 if (!obj)
78 return {};
79
80 return obj->GetBooleanValue();
81}
82
84 const std::vector<llvm::StringRef> ci_usages = {
85 "settings set target.process.python-os-plugin-path <script-path>",
86 "settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
87 const std::vector<llvm::StringRef> api_usages = {};
89 GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
91 {ci_usages, api_usages});
92}
93
ScriptInterpreterPythonImpl::Locker Locker
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
StructuredData::DictionarySP GetRegisterInfo() override
std::optional< std::string > GetRegisterContextForTID(lldb::tid_t tid) override
OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, ExecutionContext &exe_ctx, StructuredData::Generic *script_obj=nullptr) override
StructuredData::DictionarySP CreateThread(lldb::tid_t tid, lldb::addr_t context) override
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
static T LogAndDefault(llvm::Expected< T > value_or_err, llvm::StringRef caller)
Log the failure in value_or_err and fall back to a default-constructed T.
llvm::Expected< T > Dispatch(llvm::StringRef method_name, Args &&...args)
Call method_name on the scripted object.
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
StructuredData::DictionarySP GetRegisterInfo() override
ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter)
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.
@ eScriptLanguagePython
@ eScriptedExtensionOperatingSystem
uint64_t addr_t
Definition lldb-types.h:80
uint64_t tid_t
Definition lldb-types.h:85