xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (revision 282890d7112a7c0aa03e5be0a7a33b8ef04f1d67)
1 //===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===//
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/ScriptInterpreterPython.h"
12 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
13 #include "lldb/Host/FileSystem.h"
14 #include "lldb/Host/HostInfo.h"
15 
16 #include "PythonTestSuite.h"
17 
18 using namespace lldb_private;
19 class TestScriptInterpreterPython : public ScriptInterpreterPython {
20 public:
21   using ScriptInterpreterPython::Initialize;
22   using ScriptInterpreterPython::InitializePrivate;
23 };
24 
25 void PythonTestSuite::SetUp() {
26   FileSystem::Initialize();
27   HostInfoBase::Initialize();
28   // ScriptInterpreterPython::Initialize() depends on HostInfo being
29   // initializedso it can compute the python directory etc.
30   TestScriptInterpreterPython::Initialize();
31   TestScriptInterpreterPython::InitializePrivate();
32 
33   // Although we don't care about concurrency for the purposes of running
34   // this test suite, Python requires the GIL to be locked even for
35   // deallocating memory, which can happen when you call Py_DECREF or
36   // Py_INCREF.  So acquire the GIL for the entire duration of this
37   // test suite.
38   m_gil_state = PyGILState_Ensure();
39 }
40 
41 void PythonTestSuite::TearDown() {
42   PyGILState_Release(m_gil_state);
43 
44   TestScriptInterpreterPython::Terminate();
45   HostInfoBase::Terminate();
46   FileSystem::Terminate();
47 }
48 
49 // The following functions are the Pythonic implementations of the required
50 // callbacks. Because they're defined in libLLDB which we cannot link for the
51 // unit test, we have a 'default' implementation here.
52 
53 #if PY_MAJOR_VERSION >= 3
54 extern "C" PyObject *PyInit__lldb(void) { return nullptr; }
55 #define LLDBSwigPyInit PyInit__lldb
56 #else
57 extern "C" void init_lldb(void) {}
58 #define LLDBSwigPyInit init_lldb
59 #endif
60 
61 extern "C" bool LLDBSwigPythonBreakpointCallbackFunction(
62     const char *python_function_name, const char *session_dictionary_name,
63     const lldb::StackFrameSP &sb_frame,
64     const lldb::BreakpointLocationSP &sb_bp_loc) {
65   return false;
66 }
67 
68 extern "C" bool 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 extern "C" bool LLDBSwigPythonCallTypeScript(
75     const char *python_function_name, 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 extern "C" void *
82 LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name,
83                                       const char *session_dictionary_name,
84                                       const lldb::ValueObjectSP &valobj_sp) {
85   return nullptr;
86 }
87 
88 extern "C" void *
89 LLDBSwigPythonCreateCommandObject(const char *python_class_name,
90                                   const char *session_dictionary_name,
91                                   const lldb::DebuggerSP debugger_sp) {
92   return nullptr;
93 }
94 
95 extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan(
96     const char *python_class_name, const char *session_dictionary_name,
97     const lldb::ThreadPlanSP &thread_plan_sp) {
98   return nullptr;
99 }
100 
101 extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor,
102                                              const char *method_name,
103                                              Event *event_sp, bool &got_error) {
104   return false;
105 }
106 
107 extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver(
108     const char *python_class_name, const char *session_dictionary_name,
109     lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) {
110   return nullptr;
111 }
112 
113 extern "C" unsigned int
114 LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
115                                      lldb_private::SymbolContext *sym_ctx) {
116   return 0;
117 }
118 
119 extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor,
120                                                       uint32_t max) {
121   return 0;
122 }
123 
124 extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor,
125                                                 uint32_t idx) {
126   return nullptr;
127 }
128 
129 extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor,
130                                                       const char *child_name) {
131   return 0;
132 }
133 
134 extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) {
135   return nullptr;
136 }
137 
138 extern lldb::ValueObjectSP
139 LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) {
140   return nullptr;
141 }
142 
143 extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor) {
144   return false;
145 }
146 
147 extern "C" bool
148 LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor) {
149   return false;
150 }
151 
152 extern "C" void *
153 LLDBSwigPython_GetValueSynthProviderInstance(void *implementor) {
154   return nullptr;
155 }
156 
157 extern "C" bool
158 LLDBSwigPythonCallCommand(const char *python_function_name,
159                           const char *session_dictionary_name,
160                           lldb::DebuggerSP &debugger, const char *args,
161                           lldb_private::CommandReturnObject &cmd_retobj,
162                           lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
163   return false;
164 }
165 
166 extern "C" bool
167 LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger,
168                                 const char *args,
169                                 lldb_private::CommandReturnObject &cmd_retobj,
170                                 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
171   return false;
172 }
173 
174 extern "C" bool
175 LLDBSwigPythonCallModuleInit(const char *python_module_name,
176                              const char *session_dictionary_name,
177                              lldb::DebuggerSP &debugger) {
178   return false;
179 }
180 
181 extern "C" void *
182 LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
183                              const char *session_dictionary_name,
184                              const lldb::ProcessSP &process_sp) {
185   return nullptr;
186 }
187 
188 extern "C" void *
189 LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
190                                      const char *session_dictionary_name) {
191   return nullptr;
192 }
193 
194 extern "C" void *
195 LLDBSwigPython_GetRecognizedArguments(void *implementor,
196                                       const lldb::StackFrameSP &frame_sp) {
197   return nullptr;
198 }
199 
200 extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(
201     const char *python_function_name, const char *session_dictionary_name,
202     lldb::ProcessSP &process, std::string &output) {
203   return false;
204 }
205 
206 extern "C" bool LLDBSWIGPythonRunScriptKeywordThread(
207     const char *python_function_name, const char *session_dictionary_name,
208     lldb::ThreadSP &thread, std::string &output) {
209   return false;
210 }
211 
212 extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(
213     const char *python_function_name, const char *session_dictionary_name,
214     lldb::TargetSP &target, std::string &output) {
215   return false;
216 }
217 
218 extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame(
219     const char *python_function_name, const char *session_dictionary_name,
220     lldb::StackFrameSP &frame, std::string &output) {
221   return false;
222 }
223 
224 extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(
225     const char *python_function_name, const char *session_dictionary_name,
226     lldb::ValueObjectSP &value, std::string &output) {
227   return false;
228 }
229 
230 extern "C" void *
231 LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
232                                  const lldb::TargetSP &target_sp) {
233   return nullptr;
234 }
235