Reland [OffloadBundler] Compress bundles over 4GB (#122307)
[llvm-project.git] / lldb / source / Plugins / ScriptInterpreter / Python / Interfaces / OperatingSystemPythonInterface.cpp
blobd8b2ea984fd88e60415d9c30f5ec03c6349a2ace
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/PluginManager.h"
10 #include "lldb/Host/Config.h"
11 #include "lldb/Target/ExecutionContext.h"
12 #include "lldb/Utility/Log.h"
13 #include "lldb/lldb-enumerations.h"
15 #if LLDB_ENABLE_PYTHON
17 // clang-format off
18 // LLDB Python header must be included first
19 #include "../lldb-python.h"
20 //clang-format on
22 #include "../SWIGPythonBridge.h"
23 #include "../ScriptInterpreterPythonImpl.h"
24 #include "OperatingSystemPythonInterface.h"
26 using namespace lldb;
27 using namespace lldb_private;
28 using namespace lldb_private::python;
29 using Locker = ScriptInterpreterPythonImpl::Locker;
31 OperatingSystemPythonInterface::OperatingSystemPythonInterface(
32 ScriptInterpreterPythonImpl &interpreter)
33 : OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
35 llvm::Expected<StructuredData::GenericSP>
36 OperatingSystemPythonInterface::CreatePluginObject(
37 llvm::StringRef class_name, ExecutionContext &exe_ctx,
38 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
39 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
40 exe_ctx.GetProcessSP());
43 StructuredData::DictionarySP
44 OperatingSystemPythonInterface::CreateThread(lldb::tid_t tid,
45 lldb::addr_t context) {
46 Status error;
47 StructuredData::DictionarySP dict = Dispatch<StructuredData::DictionarySP>(
48 "create_thread", error, tid, context);
50 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
51 error))
52 return {};
54 return dict;
57 StructuredData::ArraySP OperatingSystemPythonInterface::GetThreadInfo() {
58 Status error;
59 StructuredData::ArraySP arr =
60 Dispatch<StructuredData::ArraySP>("get_thread_info", error);
62 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
63 error))
64 return {};
66 return arr;
69 StructuredData::DictionarySP OperatingSystemPythonInterface::GetRegisterInfo() {
70 return ScriptedThreadPythonInterface::GetRegisterInfo();
73 std::optional<std::string>
74 OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
75 Status error;
76 StructuredData::ObjectSP obj = Dispatch("get_register_data", error, tid);
78 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
79 error))
80 return {};
82 return obj->GetAsString()->GetValue().str();
85 std::optional<bool> OperatingSystemPythonInterface::DoesPluginReportAllThreads() {
86 Status error;
87 StructuredData::ObjectSP obj = Dispatch("does_plugin_report_all_threads", error);
88 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
89 error))
90 return {};
92 return obj->GetAsBoolean()->GetValue();
95 void OperatingSystemPythonInterface::Initialize() {
96 const std::vector<llvm::StringRef> ci_usages = {
97 "settings set target.process.python-os-plugin-path <script-path>",
98 "settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
99 const std::vector<llvm::StringRef> api_usages = {};
100 PluginManager::RegisterPlugin(
101 GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
102 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
105 void OperatingSystemPythonInterface::Terminate() {
106 PluginManager::UnregisterPlugin(CreateInstance);
109 #endif