Debian Codegraph @

llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

raw
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 #include <optional>
21
22 using namespace lldb_private;
23 class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl {
24 public:
25 using ScriptInterpreterPythonImpl::Initialize;
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
35 // Although we don't care about concurrency for the purposes of running
36 // this test suite, Python requires the GIL to be locked even for
37 // deallocating memory, which can happen when you call Py_DECREF or
38 // Py_INCREF. So acquire the GIL for the entire duration of this
39 // test suite.
40 m_gil_state = PyGILState_Ensure();
41 }
42
43 void PythonTestSuite::TearDown() {
44 PyGILState_Release(m_gil_state);
45
46 TestScriptInterpreterPython::Terminate();
47 HostInfoBase::Terminate();
48 FileSystem::Terminate();
49 }
50
51 // The following functions are the Pythonic implementations of the required
52 // callbacks. Because they're defined in libLLDB which we cannot link for the
53 // unit test, we have a 'default' implementation here.
54
55 extern "C" PyObject *PyInit__lldb(void) { return nullptr; }
56
57 llvm::Expected<bool> lldb_private::LLDBSwigPythonBreakpointCallbackFunction(
58 const char *python_function_name, const char *session_dictionary_name,
59 const lldb::StackFrameSP &sb_frame,
60 const lldb::BreakpointLocationSP &sb_bp_loc,
61 const StructuredDataImpl &args_impl) {
62 return false;
63 }
64
65 bool lldb_private::LLDBSwigPythonWatchpointCallbackFunction(
66 const char *python_function_name, const char *session_dictionary_name,
67 const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) {
68 return false;
69 }
70
71 bool lldb_private::LLDBSwigPythonFormatterCallbackFunction(
72 const char *python_function_name, const char *session_dictionary_name,
73 lldb::TypeImplSP type_impl_sp) {
74 return false;
75 }
76
77 bool lldb_private::LLDBSwigPythonCallTypeScript(
78 const char *python_function_name, const void *session_dictionary,
79 const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
80 const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) {
81 return false;
82 }
83
84 python::PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
85 const char *python_class_name, const char *session_dictionary_name,
86 const lldb::ValueObjectSP &valobj_sp) {
87 return python::PythonObject();
88 }
89
90 python::PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
91 const char *python_class_name, const char *session_dictionary_name,
92 lldb::DebuggerSP debugger_sp) {
93 return python::PythonObject();
94 }
95
96 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
97 const char *python_class_name, const char *session_dictionary_name,
98 const StructuredDataImpl &args_data, std::string &error_string,
99 const lldb::ThreadPlanSP &thread_plan_sp) {
100 return python::PythonObject();
101 }
102
103 bool lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor,
104 const char *method_name,
105 Event *event_sp,
106 bool &got_error) {
107 return false;
108 }
109
110 python::PythonObject
111 lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
112 const char *python_class_name, const char *session_dictionary_name,
113 const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
114 return python::PythonObject();
115 }
116
117 unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
118 void *implementor, const char *method_name,
119 lldb_private::SymbolContext *sym_ctx) {
120 return 0;
121 }
122
123 size_t lldb_private::LLDBSwigPython_CalculateNumChildren(PyObject *implementor,
124 uint32_t max) {
125 return 0;
126 }
127
128 PyObject *lldb_private::LLDBSwigPython_GetChildAtIndex(PyObject *implementor,
129 uint32_t idx) {
130 return nullptr;
131 }
132
133 int lldb_private::LLDBSwigPython_GetIndexOfChildWithName(
134 PyObject *implementor, const char *child_name) {
135 return 0;
136 }
137
138 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) {
139 return nullptr;
140 }
141
142 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) {
143 return nullptr;
144 }
145
146 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) {
147 return nullptr;
148 }
149
150 void *
151 lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) {
152 return nullptr;
153 }
154
155 lldb::ValueObjectSP
156 lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) {
157 return nullptr;
158 }
159
160 bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance(
161 PyObject *implementor) {
162 return false;
163 }
164
165 bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
166 PyObject *implementor) {
167 return false;
168 }
169
170 PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance(
171 PyObject *implementor) {
172 return nullptr;
173 }
174
175 bool lldb_private::LLDBSwigPythonCallCommand(
176 const char *python_function_name, const char *session_dictionary_name,
177 lldb::DebuggerSP debugger, const char *args,
178 lldb_private::CommandReturnObject &cmd_retobj,
179 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
180 return false;
181 }
182
183 bool lldb_private::LLDBSwigPythonCallCommandObject(
184 PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
185 lldb_private::CommandReturnObject &cmd_retobj,
186 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
187 return false;
188 }
189
190 bool lldb_private::LLDBSwigPythonCallModuleInit(
191 const char *python_module_name, const char *session_dictionary_name,
192 lldb::DebuggerSP debugger) {
193 return false;
194 }
195
196 python::PythonObject
197 lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
198 const char *session_dictionary_name,
199 const lldb::ProcessSP &process_sp) {
200 return python::PythonObject();
201 }
202
203 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject(
204 const char *python_class_name, const char *session_dictionary_name,
205 lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl,
206 std::string &error_string) {
207 return python::PythonObject();
208 }
209
210 python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
211 const char *python_class_name, const char *session_dictionary_name) {
212 return python::PythonObject();
213 }
214
215 PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments(
216 PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
217 return nullptr;
218 }
219
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
226 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
227 const char *python_function_name, const char *session_dictionary_name,
228 lldb::ThreadSP thread) {
229 return std::nullopt;
230 }
231
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
238 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
239 const char *python_function_name, const char *session_dictionary_name,
240 lldb::StackFrameSP frame) {
241 return std::nullopt;
242 }
243
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
250 void *lldb_private::LLDBSWIGPython_GetDynamicSetting(
251 void *module, const char *setting, const lldb::TargetSP &target_sp) {
252 return nullptr;
253 }
254
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
262 bool lldb_private::LLDBSwigPythonStopHookCallHandleStop(
263 void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp,
264 lldb::StreamSP stream) {
265 return false;
266 }
267
268 python::PythonObject lldb_private::python::ToSWIGWrapper(const Status &status) {
269 return python::PythonObject();
270 }