xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (revision b9d4c94a603d3cc1f44ab7dd1d4f3ae9c80da98b)
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> lldb_private::LLDBSwigPythonBreakpointCallbackFunction(
58     const char *python_function_name, const char *session_dictionary_name,
59     const lldb::StackFrameSP &sb_frame,
60     const lldb::BreakpointLocationSP &sb_bp_loc,
61     const StructuredDataImpl &args_impl) {
62   return false;
63 }
64 
65 bool lldb_private::LLDBSwigPythonWatchpointCallbackFunction(
66     const char *python_function_name, const char *session_dictionary_name,
67     const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) {
68   return false;
69 }
70 
71 bool lldb_private::LLDBSwigPythonFormatterCallbackFunction(
72     const char *python_function_name, const char *session_dictionary_name,
73     lldb::TypeImplSP type_impl_sp) {
74   return false;
75 }
76 
77 bool lldb_private::LLDBSwigPythonCallTypeScript(
78     const char *python_function_name, const void *session_dictionary,
79     const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
80     const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) {
81   return false;
82 }
83 
84 python::PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
85     const char *python_class_name, const char *session_dictionary_name,
86     const lldb::ValueObjectSP &valobj_sp) {
87   return python::PythonObject();
88 }
89 
90 python::PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
91     const char *python_class_name, const char *session_dictionary_name,
92     lldb::DebuggerSP debugger_sp) {
93   return python::PythonObject();
94 }
95 
96 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
97     const char *python_class_name, const char *session_dictionary_name,
98     const StructuredDataImpl &args_data, std::string &error_string,
99     const lldb::ThreadPlanSP &thread_plan_sp) {
100   return python::PythonObject();
101 }
102 
103 bool lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor,
104                                                 const char *method_name,
105                                                 Event *event_sp,
106                                                 bool &got_error) {
107   return false;
108 }
109 
110 python::PythonObject
111 lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
112     const char *python_class_name, const char *session_dictionary_name,
113     const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
114   return python::PythonObject();
115 }
116 
117 unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
118     void *implementor, const char *method_name,
119     lldb_private::SymbolContext *sym_ctx) {
120   return 0;
121 }
122 
123 size_t lldb_private::LLDBSwigPython_CalculateNumChildren(PyObject *implementor,
124                                                          uint32_t max) {
125   return 0;
126 }
127 
128 PyObject *lldb_private::LLDBSwigPython_GetChildAtIndex(PyObject *implementor,
129                                                        uint32_t idx) {
130   return nullptr;
131 }
132 
133 int lldb_private::LLDBSwigPython_GetIndexOfChildWithName(
134     PyObject *implementor, const char *child_name) {
135   return 0;
136 }
137 
138 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) {
139   return nullptr;
140 }
141 
142 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) {
143   return nullptr;
144 }
145 
146 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject *data) {
147   return nullptr;
148 }
149 
150 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) {
151   return nullptr;
152 }
153 
154 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) {
155   return nullptr;
156 }
157 
158 void *
159 lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) {
160   return nullptr;
161 }
162 
163 lldb::ValueObjectSP
164 lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) {
165   return nullptr;
166 }
167 
168 bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance(
169     PyObject *implementor) {
170   return false;
171 }
172 
173 bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
174     PyObject *implementor) {
175   return false;
176 }
177 
178 PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance(
179     PyObject *implementor) {
180   return nullptr;
181 }
182 
183 bool lldb_private::LLDBSwigPythonCallCommand(
184     const char *python_function_name, const char *session_dictionary_name,
185     lldb::DebuggerSP debugger, const char *args,
186     lldb_private::CommandReturnObject &cmd_retobj,
187     lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
188   return false;
189 }
190 
191 bool lldb_private::LLDBSwigPythonCallCommandObject(
192     PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
193     lldb_private::CommandReturnObject &cmd_retobj,
194     lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
195   return false;
196 }
197 
198 bool lldb_private::LLDBSwigPythonCallModuleInit(
199     const char *python_module_name, const char *session_dictionary_name,
200     lldb::DebuggerSP debugger) {
201   return false;
202 }
203 
204 python::PythonObject
205 lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
206                                            const char *session_dictionary_name,
207                                            const lldb::ProcessSP &process_sp) {
208   return python::PythonObject();
209 }
210 
211 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject(
212     const char *python_class_name, const char *session_dictionary_name,
213     lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl,
214     std::string &error_string) {
215   return python::PythonObject();
216 }
217 
218 python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
219     const char *python_class_name, const char *session_dictionary_name) {
220   return python::PythonObject();
221 }
222 
223 PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments(
224     PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
225   return nullptr;
226 }
227 
228 bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess(
229     const char *python_function_name, const char *session_dictionary_name,
230     const lldb::ProcessSP &process, std::string &output) {
231   return false;
232 }
233 
234 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
235     const char *python_function_name, const char *session_dictionary_name,
236     lldb::ThreadSP thread) {
237   return std::nullopt;
238 }
239 
240 bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
241     const char *python_function_name, const char *session_dictionary_name,
242     const lldb::TargetSP &target, std::string &output) {
243   return false;
244 }
245 
246 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
247     const char *python_function_name, const char *session_dictionary_name,
248     lldb::StackFrameSP frame) {
249   return std::nullopt;
250 }
251 
252 bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue(
253     const char *python_function_name, const char *session_dictionary_name,
254     const lldb::ValueObjectSP &value, std::string &output) {
255   return false;
256 }
257 
258 void *lldb_private::LLDBSWIGPython_GetDynamicSetting(
259     void *module, const char *setting, const lldb::TargetSP &target_sp) {
260   return nullptr;
261 }
262 
263 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook(
264     lldb::TargetSP target_sp, const char *python_class_name,
265     const char *session_dictionary_name, const StructuredDataImpl &args_impl,
266     Status &error) {
267   return python::PythonObject();
268 }
269 
270 bool lldb_private::LLDBSwigPythonStopHookCallHandleStop(
271     void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp,
272     lldb::StreamSP stream) {
273   return false;
274 }
275 
276 python::PythonObject lldb_private::python::ToSWIGWrapper(const Status &status) {
277   return python::PythonObject();
278 }
279 
280 python::PythonObject
281 lldb_private::python::ToSWIGWrapper(lldb::ProcessAttachInfoSP) {
282   return python::PythonObject();
283 }
284 
285 python::PythonObject
286 lldb_private::python::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) {
287   return python::PythonObject();
288 }
289