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