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