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"
10#include "lldb/Utility/Log.h"
12
13#if LLDB_ENABLE_PYTHON
14
15// LLDB Python header must be included first
16#include "../lldb-python.h"
17
18#include "../SWIGPythonBridge.h"
19#include "../ScriptInterpreterPythonImpl.h"
21#include <optional>
22
23using namespace lldb;
24using namespace lldb_private;
25using namespace lldb_private::python;
26using Locker = ScriptInterpreterPythonImpl::Locker;
27
28ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
29 ScriptInterpreterPythonImpl &interpreter)
30 : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
31
32llvm::Expected<StructuredData::GenericSP>
33ScriptedThreadPythonInterface::CreatePluginObject(
34 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
36 ExecutionContextRefSP exe_ctx_ref_sp =
37 std::make_shared<ExecutionContextRef>(exe_ctx);
38 StructuredDataImpl sd_impl(args_sp);
39 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
40 exe_ctx_ref_sp, sd_impl);
41}
42
43lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
45 StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
46
47 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
49
50 return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
51}
52
53std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
55 StructuredData::ObjectSP obj = Dispatch("get_name", error);
56
57 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
58 return {};
59
60 return obj->GetStringValue().str();
61}
62
63lldb::StateType ScriptedThreadPythonInterface::GetState() {
65 StructuredData::ObjectSP obj = Dispatch("get_state", error);
66
67 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
68 return eStateInvalid;
69
70 return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
71}
72
73std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
75 StructuredData::ObjectSP obj = Dispatch("get_queue", error);
76
77 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
78 return {};
79
80 return obj->GetStringValue().str();
81}
82
83StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
86 Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);
87
88 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
89 return {};
90
91 return dict;
92}
93
94StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
97 Dispatch<StructuredData::ArraySP>("get_stackframes", error);
98
99 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr, error))
100 return {};
101
102 return arr;
103}
104
105StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {
108 Dispatch<StructuredData::DictionarySP>("get_register_info", error);
109
110 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
111 return {};
112
113 return dict;
114}
115
116std::optional<std::string> ScriptedThreadPythonInterface::GetRegisterContext() {
118 StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
119
120 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
121 return {};
122
123 return obj->GetAsString()->GetValue().str();
124}
125
126StructuredData::ArraySP ScriptedThreadPythonInterface::GetExtendedInfo() {
129 Dispatch<StructuredData::ArraySP>("get_extended_info", error);
130
131 if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr, error))
132 return {};
133
134 return arr;
135}
136
137#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: SBAttachInfo.h:14
Definition: SBAddress.h:15
StateType
Process and Thread States.
uint64_t tid_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition: lldb-forward.h:342