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