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