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