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) {
43 "create_thread", error, tid, context);
44
45 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
46 error))
47 return {};
48
49 return dict;
50}
51
55 Dispatch<StructuredData::ArraySP>("get_thread_info", error);
56
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
58 error))
59 return {};
60
61 return arr;
62}
63
67
68std::optional<std::string>
71 StructuredData::ObjectSP obj = Dispatch("get_register_data", error, tid);
72
73 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
74 error))
75 return {};
76
77 return obj->GetAsString()->GetValue().str();
78}
79
82 StructuredData::ObjectSP obj = Dispatch("does_plugin_report_all_threads", error);
83 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
84 error))
85 return {};
86
87 return obj->GetAsBoolean()->GetValue();
88}
89
91 const std::vector<llvm::StringRef> ci_usages = {
92 "settings set target.process.python-os-plugin-path <script-path>",
93 "settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
94 const std::vector<llvm::StringRef> api_usages = {};
96 GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
97 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
98}
99
static llvm::raw_ostream & error(Stream &strm)
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 CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
StructuredData::DictionarySP GetRegisterInfo() override
ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter)
An error handling class.
Definition Status.h:118
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
uint64_t addr_t
Definition lldb-types.h:80
uint64_t tid_t
Definition lldb-types.h:84