LLDB mainline
ScriptedPythonInterface.cpp
Go to the documentation of this file.
1//===-- ScriptedPythonInterface.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
11#include "lldb/Host/Config.h"
12#include "lldb/Utility/Log.h"
14
19#include <optional>
20
21using namespace lldb;
22using namespace lldb_private;
23
27
28template <>
35
36template <>
43
44template <>
47 if (lldb::SBError *sb_error = reinterpret_cast<lldb::SBError *>(
49 return m_interpreter.GetStatusFromSBError(*sb_error);
50 error =
51 Status::FromErrorString("Couldn't cast lldb::SBError to lldb::Status.");
52
53 return {};
54}
55
56template <>
59 if (lldb::SBEvent *sb_event = reinterpret_cast<lldb::SBEvent *>(
61 return m_interpreter.GetOpaqueTypeFromSBEvent(*sb_event);
63 "Couldn't cast lldb::SBEvent to lldb_private::Event.");
64
65 return nullptr;
66}
67
68template <>
72 if (lldb::SBStream *sb_stream = reinterpret_cast<lldb::SBStream *>(
74 return m_interpreter.GetOpaqueTypeFromSBStream(*sb_stream);
76 "Couldn't cast lldb::SBStream to lldb_private::Stream.");
77
78 return nullptr;
79}
80
81template <>
85 if (lldb::SBFrame *sb_frame = reinterpret_cast<lldb::SBFrame *>(
87 return m_interpreter.GetOpaqueTypeFromSBFrame(*sb_frame);
89 "Couldn't cast lldb::SBFrame to lldb_private::StackFrame.");
90
91 return nullptr;
92}
93
94template <>
98 if (lldb::SBThread *sb_thread = reinterpret_cast<lldb::SBThread *>(
100 return m_interpreter.GetOpaqueTypeFromSBThread(*sb_thread);
102 "Couldn't cast lldb::SBThread to lldb_private::Thread.");
103
104 return nullptr;
105}
106
107template <>
111 if (lldb::SBSymbolContext *sb_symbol_context =
112 reinterpret_cast<lldb::SBSymbolContext *>(
114 return m_interpreter.GetOpaqueTypeFromSBSymbolContext(*sb_symbol_context);
116 "Couldn't cast lldb::SBSymbolContext to lldb_private::SymbolContext.");
117
118 return {};
119}
120
121template <>
125 lldb::SBData *sb_data = reinterpret_cast<lldb::SBData *>(
127
128 if (!sb_data) {
130 "Couldn't cast lldb::SBData to lldb::DataExtractorSP.");
131 return nullptr;
132 }
133
134 return m_interpreter.GetDataExtractorFromSBData(*sb_data);
135}
136
137template <>
141 lldb::SBBreakpoint *sb_breakpoint = reinterpret_cast<lldb::SBBreakpoint *>(
143
144 if (!sb_breakpoint) {
146 "Couldn't cast lldb::SBBreakpoint to lldb::BreakpointSP.");
147 return nullptr;
148 }
149
150 return m_interpreter.GetOpaqueTypeFromSBBreakpoint(*sb_breakpoint);
151}
152
153template <>
157 lldb::SBBreakpointLocation *sb_break_loc =
158 reinterpret_cast<lldb::SBBreakpointLocation *>(
160
161 if (!sb_break_loc) {
163 "Couldn't cast lldb::SBBreakpointLocation to "
164 "lldb::BreakpointLocationSP.");
165 return nullptr;
166 }
167
168 return m_interpreter.GetOpaqueTypeFromSBBreakpointLocation(*sb_break_loc);
169}
170
171template <>
174 lldb::SBAttachInfo *sb_attach_info = reinterpret_cast<lldb::SBAttachInfo *>(
176
177 if (!sb_attach_info) {
179 "Couldn't cast lldb::SBAttachInfo to lldb::ProcessAttachInfoSP.");
180 return nullptr;
181 }
182
183 return m_interpreter.GetOpaqueTypeFromSBAttachInfo(*sb_attach_info);
184}
185
186template <>
189 lldb::SBLaunchInfo *sb_launch_info = reinterpret_cast<lldb::SBLaunchInfo *>(
191
192 if (!sb_launch_info) {
194 "Couldn't cast lldb::SBLaunchInfo to lldb::ProcessLaunchInfoSP.");
195 return nullptr;
196 }
197
198 return m_interpreter.GetOpaqueTypeFromSBLaunchInfo(*sb_launch_info);
199}
200
201template <>
202std::optional<MemoryRegionInfo>
204 std::optional<MemoryRegionInfo>>(python::PythonObject &p, Status &error) {
205
206 lldb::SBMemoryRegionInfo *sb_mem_reg_info =
207 reinterpret_cast<lldb::SBMemoryRegionInfo *>(
209
210 if (!sb_mem_reg_info) {
212 "Couldn't cast lldb::SBMemoryRegionInfo to "
213 "lldb_private::MemoryRegionInfo.");
214 return {};
215 }
216
217 return m_interpreter.GetOpaqueTypeFromSBMemoryRegionInfo(*sb_mem_reg_info);
218}
219
220template <>
224
225 lldb::SBExecutionContext *sb_exe_ctx =
226 reinterpret_cast<lldb::SBExecutionContext *>(
228
229 if (!sb_exe_ctx) {
231 "Couldn't cast lldb::SBExecutionContext to "
232 "lldb::ExecutionContextRefSP.");
233 return {};
234 }
235
236 return m_interpreter.GetOpaqueTypeFromSBExecutionContext(*sb_exe_ctx);
237}
238
239template <>
244 llvm::Expected<unsigned long long> unsigned_or_err = p.AsUnsignedLongLong();
245 if (!unsigned_or_err) {
246 error = (Status::FromError(unsigned_or_err.takeError()));
247 return ret_val;
248 }
249 unsigned long long unsigned_val = *unsigned_or_err;
251 error = Status("value too large for lldb::DescriptionLevel.");
252 return ret_val;
253 }
254 return static_cast<lldb::DescriptionLevel>(unsigned_val);
255}
256
257template <>
261
262 lldb::SBFrameList *sb_frame_list = reinterpret_cast<lldb::SBFrameList *>(
264
265 if (!sb_frame_list) {
267 "couldn't cast lldb::SBFrameList to lldb::StackFrameListSP.");
268 return {};
269 }
270
271 return m_interpreter.GetOpaqueTypeFromSBFrameList(*sb_frame_list);
272}
273
274template <>
278 lldb::SBValue *sb_value = reinterpret_cast<lldb::SBValue *>(
280 if (!sb_value) {
282 "couldn't cast lldb::SBValue to lldb::ValueObjectSP");
283 return {};
284 }
285
286 return m_interpreter.GetOpaqueTypeFromSBValue(*sb_value);
287}
288
289template <>
293 lldb::SBTarget *sb_target = reinterpret_cast<lldb::SBTarget *>(
295 if (!sb_target) {
297 "couldn't cast lldb::SBTarget to lldb::TargetSP");
298 return {};
299 }
300
301 return m_interpreter.GetOpaqueTypeFromSBTarget(*sb_target);
302}
303
304template <>
308 lldb::SBValueList *sb_value_list = reinterpret_cast<lldb::SBValueList *>(
310
311 if (!sb_value_list) {
313 "couldn't cast lldb::SBValueList to lldb::ValueObjectListSP");
314 return {};
315 }
316
317 lldb::ValueObjectListSP out = std::make_shared<ValueObjectList>();
318 for (uint32_t i = 0, e = sb_value_list->GetSize(); i < e; ++i) {
319 SBValue value = sb_value_list->GetValueAtIndex(i);
320 out->Append(m_interpreter.GetOpaqueTypeFromSBValue(value));
321 }
322
323 return out;
324}
static llvm::raw_ostream & error(Stream &strm)
uint32_t GetSize()
lldb::SBValue GetValueAtIndex(uint32_t index)
Represents a list of SBFrame objects.
Definition SBFrameList.h:31
ScriptInterpreterPythonImpl & m_interpreter
T ExtractValueFromPythonObject(python::PythonObject &p, Status &error)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Array > ArraySP
Defines a symbol context baton that can be handed other debug core functions.
StructuredData::DictionarySP CreateStructuredDictionary() const
StructuredData::ArraySP CreateStructuredArray() const
llvm::Expected< unsigned long long > AsUnsignedLongLong() const
void * LLDBSWIGPython_CastPyObjectToSBExecutionContext(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBFrameList(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBThread(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBData(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBTarget(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBSymbolContext(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBStream(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBBreakpointLocation(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBError(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBValueList(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBEvent(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data)
void * LLDBSWIGPython_CastPyObjectToSBFrame(PyObject *data)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ kNumDescriptionLevels
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ProcessAttachInfo > ProcessAttachInfoSP
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
class LLDB_API SBMemoryRegionInfo
Definition SBDefines.h:88
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::ProcessLaunchInfo > ProcessLaunchInfoSP
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP