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