1//===-- PythonTestSuite.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 "gtest/gtest.h"
10
11#include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h"
12#include "Plugins/ScriptInterpreter/Python/lldb-python.h"
13
14#include "PythonTestSuite.h"
15#include <optional>
16
17void PythonTestSuite::SetUp() {
18 // Although we don't care about concurrency for the purposes of running
19 // this test suite, Python requires the GIL to be locked even for
20 // deallocating memory, which can happen when you call Py_DECREF or
21 // Py_INCREF. So acquire the GIL for the entire duration of this
22 // test suite.
23 Py_InitializeEx(0);
24 m_gil_state = PyGILState_Ensure();
25 PyRun_SimpleString("import sys");
26}
27
28void PythonTestSuite::TearDown() {
29 PyGILState_Release(m_gil_state);
30
31 // We could call Py_FinalizeEx here, but initializing and finalizing Python is
32 // pretty slow, so just keep Python initialized across tests.
33}
34
35// The following functions are the Pythonic implementations of the required
36// callbacks. Because they're defined in libLLDB which we cannot link for the
37// unit test, we have a 'default' implementation here.
38
39extern "C" PyObject *PyInit__lldb(void) { return nullptr; }
40
41llvm::Expected<bool>
42lldb_private::python::SWIGBridge::LLDBSwigPythonBreakpointCallbackFunction(
43 const char *python_function_name, const char *session_dictionary_name,
44 const lldb::StackFrameSP &sb_frame,
45 const lldb::BreakpointLocationSP &sb_bp_loc,
46 const StructuredDataImpl &args_impl) {
47 return false;
48}
49
50bool lldb_private::python::SWIGBridge::LLDBSwigPythonWatchpointCallbackFunction(
51 const char *python_function_name, const char *session_dictionary_name,
52 const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) {
53 return false;
54}
55
56bool lldb_private::python::SWIGBridge::LLDBSwigPythonFormatterCallbackFunction(
57 const char *python_function_name, const char *session_dictionary_name,
58 lldb::TypeImplSP type_impl_sp) {
59 return false;
60}
61
62bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallTypeScript(
63 const char *python_function_name, const void *session_dictionary,
64 const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
65 const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) {
66 return false;
67}
68
69python::PythonObject
70lldb_private::python::SWIGBridge::LLDBSwigPythonCreateSyntheticProvider(
71 const char *python_class_name, const char *session_dictionary_name,
72 const lldb::ValueObjectSP &valobj_sp) {
73 return python::PythonObject();
74}
75
76python::PythonObject
77lldb_private::python::SWIGBridge::LLDBSwigPythonCreateCommandObject(
78 const char *python_class_name, const char *session_dictionary_name,
79 lldb::DebuggerSP debugger_sp) {
80 return python::PythonObject();
81}
82
83python::PythonObject lldb_private::python::SWIGBridge::
84 LLDBSwigPythonCreateScriptedBreakpointResolver(
85 const char *python_class_name, const char *session_dictionary_name,
86 const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
87 return python::PythonObject();
88}
89
90unsigned int
91lldb_private::python::SWIGBridge::LLDBSwigPythonCallBreakpointResolver(
92 void *implementor, const char *method_name,
93 lldb_private::SymbolContext *sym_ctx) {
94 return 0;
95}
96
97size_t lldb_private::python::SWIGBridge::LLDBSwigPython_CalculateNumChildren(
98 PyObject *implementor, uint32_t max) {
99 return 0;
100}
101
102PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(
103 PyObject *implementor, uint32_t idx) {
104 return nullptr;
105}
106
107int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
108 PyObject *implementor, const char *child_name) {
109 return 0;
110}
111
112void *
113lldb_private::python::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) {
114 return nullptr;
115}
116
117void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(
118 PyObject *data) {
119 return nullptr;
120}
121
122void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(
123 PyObject *data) {
124 return nullptr;
125}
126
127void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(
128 PyObject *data) {
129 return nullptr;
130}
131
132void *
133lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) {
134 return nullptr;
135}
136
137void *
138lldb_private::python::LLDBSWIGPython_CastPyObjectToSBEvent(PyObject *data) {
139 return nullptr;
140}
141
142void *
143lldb_private::python::LLDBSWIGPython_CastPyObjectToSBStream(PyObject *data) {
144 return nullptr;
145}
146
147void *
148lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) {
149 return nullptr;
150}
151
152void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(
153 PyObject *data) {
154 return nullptr;
155}
156
157void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBExecutionContext(
158 PyObject *data) {
159 return nullptr;
160}
161
162lldb::ValueObjectSP
163lldb_private::python::SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue(
164 void *data) {
165 return nullptr;
166}
167
168bool lldb_private::python::SWIGBridge::
169 LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor) {
170 return false;
171}
172
173bool lldb_private::python::SWIGBridge::
174 LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
175 PyObject *implementor) {
176 return false;
177}
178
179PyObject *
180lldb_private::python::SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance(
181 PyObject *implementor) {
182 return nullptr;
183}
184
185bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand(
186 const char *python_function_name, const char *session_dictionary_name,
187 lldb::DebuggerSP debugger, const char *args,
188 lldb_private::CommandReturnObject &cmd_retobj,
189 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
190 return false;
191}
192
193bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
194 PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
195 lldb_private::CommandReturnObject &cmd_retobj,
196 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
197 return false;
198}
199
200bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
201 PyObject *implementor, lldb::DebuggerSP debugger,
202 StructuredDataImpl &args_impl,
203 lldb_private::CommandReturnObject &cmd_retobj,
204 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
205 return false;
206}
207
208std::optional<std::string>
209LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor,
210 std::string &command) {
211 return std::nullopt;
212}
213
214StructuredData::DictionarySP
215LLDBSwigPythonHandleArgumentCompletionForScriptedCommand(
216 PyObject *implementor, std::vector<llvm::StringRef> &args, size_t args_pos,
217 size_t pos_in_arg) {
218 return {};
219}
220
221StructuredData::DictionarySP
222LLDBSwigPythonHandleOptionArgumentCompletionForScriptedCommand(
223 PyObject *implementor, llvm::StringRef &long_options, size_t char_in_arg) {
224 return {};
225}
226
227bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
228 const char *python_module_name, const char *session_dictionary_name,
229 lldb::DebuggerSP debugger) {
230 return false;
231}
232
233bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
234 const char *python_module_name, const char *session_dictionary_name,
235 lldb::TargetSP target) {
236 return false;
237}
238
239python::PythonObject
240lldb_private::python::SWIGBridge::LLDBSWIGPythonCreateOSPlugin(
241 const char *python_class_name, const char *session_dictionary_name,
242 const lldb::ProcessSP &process_sp) {
243 return python::PythonObject();
244}
245
246python::PythonObject
247lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer(
248 const char *python_class_name, const char *session_dictionary_name) {
249 return python::PythonObject();
250}
251
252PyObject *
253lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments(
254 PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
255 return nullptr;
256}
257
258bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess(
259 const char *python_function_name, const char *session_dictionary_name,
260 const lldb::ProcessSP &process, std::string &output) {
261 return false;
262}
263
264std::optional<std::string>
265lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread(
266 const char *python_function_name, const char *session_dictionary_name,
267 lldb::ThreadSP thread) {
268 return std::nullopt;
269}
270
271bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget(
272 const char *python_function_name, const char *session_dictionary_name,
273 const lldb::TargetSP &target, std::string &output) {
274 return false;
275}
276
277std::optional<std::string>
278lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame(
279 const char *python_function_name, const char *session_dictionary_name,
280 lldb::StackFrameSP frame) {
281 return std::nullopt;
282}
283
284bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
285 const char *python_function_name, const char *session_dictionary_name,
286 const lldb::ValueObjectSP &value, std::string &output) {
287 return false;
288}
289
290void *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting(
291 void *module, const char *setting, const lldb::TargetSP &target_sp) {
292 return nullptr;
293}
294
295python::PythonObject
296lldb_private::python::SWIGBridge::ToSWIGWrapper(Status &&status) {
297 return python::PythonObject();
298}
299
300python::PythonObject
301lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessAttachInfoSP) {
302 return python::PythonObject();
303}
304
305python::PythonObject
306lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) {
307 return python::PythonObject();
308}
309
310python::PythonObject
311lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP) {
312 return python::PythonObject();
313}
314
315python::PythonObject
316lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ExecutionContextRefSP) {
317 return python::PythonObject();
318}
319
320python::PythonObject
321lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ThreadPlanSP) {
322 return python::PythonObject();
323}
324
325python::PythonObject
326lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessSP) {
327 return python::PythonObject();
328}
329
330python::PythonObject lldb_private::python::SWIGBridge::ToSWIGWrapper(
331 const lldb_private::StructuredDataImpl &) {
332 return python::PythonObject();
333}
334
335python::PythonObject
336lldb_private::python::SWIGBridge::ToSWIGWrapper(Event *event) {
337 return python::PythonObject();
338}
339
340python::PythonObject
341lldb_private::python::SWIGBridge::ToSWIGWrapper(const Stream *stream) {
342 return python::PythonObject();
343}
344
345python::PythonObject lldb_private::python::SWIGBridge::ToSWIGWrapper(
346 std::shared_ptr<lldb::SBStream> stream_sb) {
347 return python::PythonObject();
348}
349

source code of lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp