LLDB mainline
ScriptedThreadPythonInterface.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/Host/Config.h"
11#include "lldb/Utility/Log.h"
13
14#if LLDB_ENABLE_PYTHON
15
16// LLDB Python header must be included first
17#include "../lldb-python.h"
18
19#include "../SWIGPythonBridge.h"
20#include "../ScriptInterpreterPythonImpl.h"
22#include <optional>
23
24using namespace lldb;
25using namespace lldb_private;
26using namespace lldb_private::python;
27using Locker = ScriptInterpreterPythonImpl::Locker;
28
29ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
30 ScriptInterpreterPythonImpl &interpreter)
31 : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
32
33llvm::Expected<StructuredData::GenericSP>
34ScriptedThreadPythonInterface::CreatePluginObject(
35 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
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);
42}
43
44lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
46 StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
47
48 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
49 error))
51
52 return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
53}
54
55std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
57 StructuredData::ObjectSP obj = Dispatch("get_name", error);
58
59 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
60 error))
61 return {};
62
63 return obj->GetStringValue().str();
64}
65
66lldb::StateType ScriptedThreadPythonInterface::GetState() {
68 StructuredData::ObjectSP obj = Dispatch("get_state", error);
69
70 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
71 error))
72 return eStateInvalid;
73
74 return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
75}
76
77std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
79 StructuredData::ObjectSP obj = Dispatch("get_queue", error);
80
81 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
82 error))
83 return {};
84
85 return obj->GetStringValue().str();
86}
87
88StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
91 Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);
92
93 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
94 error))
95 return {};
96
97 return dict;
98}
99
100StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
103 Dispatch<StructuredData::ArraySP>("get_stackframes", error);
104
105 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
106 error))
107 return {};
108
109 return arr;
110}
111
112StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {
115 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
116
117 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
118 error))
119 return {};
120
121 return dict;
122}
123
124std::optional<std::string> ScriptedThreadPythonInterface::GetRegisterContext() {
126 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
127
128 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
129 error))
130 return {};
131
132 return obj->GetAsString()->GetValue().str();
133}
134
135StructuredData::ArraySP ScriptedThreadPythonInterface::GetExtendedInfo() {
138 Dispatch<StructuredData::ArraySP>("get_extended_info", error);
139
140 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,
141 error))
142 return {};
143
144 return arr;
145}
146
147#endif
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
An error handling class.
Definition: Status.h:44
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:90
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
StateType
Process and Thread States.
uint64_t tid_t
Definition: lldb-types.h:84
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition: lldb-forward.h:348