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
84lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedThreadPlan(
85 const char *python_class_name, const char *session_dictionary_name,
86 const StructuredDataImpl &args_data, std::string &error_string,
87 const lldb::ThreadPlanSP &thread_plan_sp) {
88 return python::PythonObject();
89}
90
91bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
92 void *implementor, const char *method_name, Event *event_sp,
93 bool &got_error) {
94 return false;
95}
96
97bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
98 void *implementor, const char *method_name, Stream *event_sp,
99 bool &got_error) {
100 return false;
101}
102
103python::PythonObject lldb_private::python::SWIGBridge::
104 LLDBSwigPythonCreateScriptedBreakpointResolver(
105 const char *python_class_name, const char *session_dictionary_name,
106 const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
107 return python::PythonObject();
108}
109
110unsigned int
111lldb_private::python::SWIGBridge::LLDBSwigPythonCallBreakpointResolver(
112 void *implementor, const char *method_name,
113 lldb_private::SymbolContext *sym_ctx) {
114 return 0;
115}
116
117size_t lldb_private::python::SWIGBridge::LLDBSwigPython_CalculateNumChildren(
118 PyObject *implementor, uint32_t max) {
119 return 0;
120}
121
122PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(
123 PyObject *implementor, uint32_t idx) {
124 return nullptr;
125}
126
127int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
128 PyObject *implementor, const char *child_name) {
129 return 0;
130}
131
132void *
133lldb_private::python::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) {
134 return nullptr;
135}
136
137void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(
138 PyObject *data) {
139 return nullptr;
140}
141
142void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(
143 PyObject *data) {
144 return nullptr;
145}
146
147void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(
148 PyObject *data) {
149 return nullptr;
150}
151
152void *
153lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) {
154 return nullptr;
155}
156
157void *
158lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) {
159 return nullptr;
160}
161
162void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(
163 PyObject *data) {
164 return nullptr;
165}
166
167lldb::ValueObjectSP
168lldb_private::python::SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue(
169 void *data) {
170 return nullptr;
171}
172
173bool lldb_private::python::SWIGBridge::
174 LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor) {
175 return false;
176}
177
178bool lldb_private::python::SWIGBridge::
179 LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
180 PyObject *implementor) {
181 return false;
182}
183
184PyObject *
185lldb_private::python::SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance(
186 PyObject *implementor) {
187 return nullptr;
188}
189
190bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand(
191 const char *python_function_name, const char *session_dictionary_name,
192 lldb::DebuggerSP debugger, const char *args,
193 lldb_private::CommandReturnObject &cmd_retobj,
194 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
195 return false;
196}
197
198bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
199 PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
200 lldb_private::CommandReturnObject &cmd_retobj,
201 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
202 return false;
203}
204
205bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
206 PyObject *implementor, lldb::DebuggerSP debugger,
207 StructuredDataImpl &args_impl,
208 lldb_private::CommandReturnObject &cmd_retobj,
209 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
210 return false;
211}
212
213bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
214 const char *python_module_name, const char *session_dictionary_name,
215 lldb::DebuggerSP debugger) {
216 return false;
217}
218
219python::PythonObject
220lldb_private::python::SWIGBridge::LLDBSWIGPythonCreateOSPlugin(
221 const char *python_class_name, const char *session_dictionary_name,
222 const lldb::ProcessSP &process_sp) {
223 return python::PythonObject();
224}
225
226python::PythonObject
227lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer(
228 const char *python_class_name, const char *session_dictionary_name) {
229 return python::PythonObject();
230}
231
232PyObject *
233lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments(
234 PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
235 return nullptr;
236}
237
238bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess(
239 const char *python_function_name, const char *session_dictionary_name,
240 const lldb::ProcessSP &process, std::string &output) {
241 return false;
242}
243
244std::optional<std::string>
245lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread(
246 const char *python_function_name, const char *session_dictionary_name,
247 lldb::ThreadSP thread) {
248 return std::nullopt;
249}
250
251bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget(
252 const char *python_function_name, const char *session_dictionary_name,
253 const lldb::TargetSP &target, std::string &output) {
254 return false;
255}
256
257std::optional<std::string>
258lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame(
259 const char *python_function_name, const char *session_dictionary_name,
260 lldb::StackFrameSP frame) {
261 return std::nullopt;
262}
263
264bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
265 const char *python_function_name, const char *session_dictionary_name,
266 const lldb::ValueObjectSP &value, std::string &output) {
267 return false;
268}
269
270void *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting(
271 void *module, const char *setting, const lldb::TargetSP &target_sp) {
272 return nullptr;
273}
274
275python::PythonObject
276lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopHook(
277 lldb::TargetSP target_sp, const char *python_class_name,
278 const char *session_dictionary_name, const StructuredDataImpl &args_impl,
279 Status &error) {
280 return python::PythonObject();
281}
282
283bool lldb_private::python::SWIGBridge::LLDBSwigPythonStopHookCallHandleStop(
284 void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp,
285 lldb::StreamSP stream) {
286 return false;
287}
288
289python::PythonObject
290lldb_private::python::SWIGBridge::ToSWIGWrapper(const Status &status) {
291 return python::PythonObject();
292}
293
294python::PythonObject
295lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessAttachInfoSP) {
296 return python::PythonObject();
297}
298
299python::PythonObject
300lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) {
301 return python::PythonObject();
302}
303
304python::PythonObject
305lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP) {
306 return python::PythonObject();
307}
308
309python::PythonObject
310lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ExecutionContextRefSP) {
311 return python::PythonObject();
312}
313
314python::PythonObject
315lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessSP) {
316 return python::PythonObject();
317}
318
319python::PythonObject lldb_private::python::SWIGBridge::ToSWIGWrapper(
320 const lldb_private::StructuredDataImpl &) {
321 return python::PythonObject();
322}
323

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