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