[ELF] Internalize computeCacheDirectedSortOrder. NFC
[llvm-project.git] / lldb / source / Plugins / ScriptInterpreter / Python / Interfaces / ScriptedThreadPythonInterface.cpp
blob8af89d761764bc858caceede3c25169565e3088d
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/Host/Config.h"
10 #include "lldb/Target/ExecutionContext.h"
11 #include "lldb/Utility/Log.h"
12 #include "lldb/lldb-enumerations.h"
14 #if LLDB_ENABLE_PYTHON
16 // LLDB Python header must be included first
17 #include "../lldb-python.h"
19 #include "../SWIGPythonBridge.h"
20 #include "../ScriptInterpreterPythonImpl.h"
21 #include "ScriptedThreadPythonInterface.h"
22 #include <optional>
24 using namespace lldb;
25 using namespace lldb_private;
26 using namespace lldb_private::python;
27 using Locker = ScriptInterpreterPythonImpl::Locker;
29 ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
30 ScriptInterpreterPythonImpl &interpreter)
31 : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
33 llvm::Expected<StructuredData::GenericSP>
34 ScriptedThreadPythonInterface::CreatePluginObject(
35 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
36 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
37 ExecutionContextRefSP exe_ctx_ref_sp =
38 std::make_shared<ExecutionContextRef>(exe_ctx);
39 StructuredDataImpl sd_impl(args_sp);
40 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
41 exe_ctx_ref_sp, sd_impl);
44 lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
45 Status error;
46 StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
48 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
49 error))
50 return LLDB_INVALID_THREAD_ID;
52 return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
55 std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
56 Status error;
57 StructuredData::ObjectSP obj = Dispatch("get_name", error);
59 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
60 error))
61 return {};
63 return obj->GetStringValue().str();
66 lldb::StateType ScriptedThreadPythonInterface::GetState() {
67 Status error;
68 StructuredData::ObjectSP obj = Dispatch("get_state", error);
70 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
71 error))
72 return eStateInvalid;
74 return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
77 std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
78 Status error;
79 StructuredData::ObjectSP obj = Dispatch("get_queue", error);
81 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
82 error))
83 return {};
85 return obj->GetStringValue().str();
88 StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
89 Status error;
90 StructuredData::DictionarySP dict =
91 Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);
93 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
94 error))
95 return {};
97 return dict;
100 StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
101 Status error;
102 StructuredData::ArraySP arr =
103 Dispatch<StructuredData::ArraySP>("get_stackframes", error);
105 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
106 error))
107 return {};
109 return arr;
112 StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {
113 Status error;
114 StructuredData::DictionarySP dict =
115 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
117 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
118 error))
119 return {};
121 return dict;
124 std::optional<std::string> ScriptedThreadPythonInterface::GetRegisterContext() {
125 Status error;
126 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
128 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
129 error))
130 return {};
132 return obj->GetAsString()->GetValue().str();
135 StructuredData::ArraySP ScriptedThreadPythonInterface::GetExtendedInfo() {
136 Status error;
137 StructuredData::ArraySP arr =
138 Dispatch<StructuredData::ArraySP>("get_extended_info", error);
140 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
141 error))
142 return {};
144 return arr;
147 #endif