1 //===-- PythonTestSuite.cpp -----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
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"
16 #include "lldb/Host/FileSystem.h"
17 #include "lldb/Host/HostInfo.h"
19 #include "PythonTestSuite.h"
22 using namespace lldb_private
;
23 class TestScriptInterpreterPython
: public ScriptInterpreterPythonImpl
{
25 using ScriptInterpreterPythonImpl::Initialize
;
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();
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
40 m_gil_state
= PyGILState_Ensure();
43 void PythonTestSuite::TearDown() {
44 PyGILState_Release(m_gil_state
);
46 TestScriptInterpreterPython::Terminate();
47 HostInfoBase::Terminate();
48 FileSystem::Terminate();
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.
55 extern "C" PyObject
*PyInit__lldb(void) { return nullptr; }
58 lldb_private::python::SWIGBridge::LLDBSwigPythonBreakpointCallbackFunction(
59 const char *python_function_name
, const char *session_dictionary_name
,
60 const lldb::StackFrameSP
&sb_frame
,
61 const lldb::BreakpointLocationSP
&sb_bp_loc
,
62 const StructuredDataImpl
&args_impl
) {
66 bool lldb_private::python::SWIGBridge::LLDBSwigPythonWatchpointCallbackFunction(
67 const char *python_function_name
, const char *session_dictionary_name
,
68 const lldb::StackFrameSP
&sb_frame
, const lldb::WatchpointSP
&sb_wp
) {
72 bool lldb_private::python::SWIGBridge::LLDBSwigPythonFormatterCallbackFunction(
73 const char *python_function_name
, const char *session_dictionary_name
,
74 lldb::TypeImplSP type_impl_sp
) {
78 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallTypeScript(
79 const char *python_function_name
, const void *session_dictionary
,
80 const lldb::ValueObjectSP
&valobj_sp
, void **pyfunct_wrapper
,
81 const lldb::TypeSummaryOptionsSP
&options_sp
, std::string
&retval
) {
86 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateSyntheticProvider(
87 const char *python_class_name
, const char *session_dictionary_name
,
88 const lldb::ValueObjectSP
&valobj_sp
) {
89 return python::PythonObject();
93 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateCommandObject(
94 const char *python_class_name
, const char *session_dictionary_name
,
95 lldb::DebuggerSP debugger_sp
) {
96 return python::PythonObject();
100 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedThreadPlan(
101 const char *python_class_name
, const char *session_dictionary_name
,
102 const StructuredDataImpl
&args_data
, std::string
&error_string
,
103 const lldb::ThreadPlanSP
&thread_plan_sp
) {
104 return python::PythonObject();
107 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
108 void *implementor
, const char *method_name
, Event
*event_sp
,
113 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan(
114 void *implementor
, const char *method_name
, Stream
*event_sp
,
119 python::PythonObject
lldb_private::python::SWIGBridge::
120 LLDBSwigPythonCreateScriptedBreakpointResolver(
121 const char *python_class_name
, const char *session_dictionary_name
,
122 const StructuredDataImpl
&args
, const lldb::BreakpointSP
&bkpt_sp
) {
123 return python::PythonObject();
127 lldb_private::python::SWIGBridge::LLDBSwigPythonCallBreakpointResolver(
128 void *implementor
, const char *method_name
,
129 lldb_private::SymbolContext
*sym_ctx
) {
133 size_t lldb_private::python::SWIGBridge::LLDBSwigPython_CalculateNumChildren(
134 PyObject
*implementor
, uint32_t max
) {
138 PyObject
*lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(
139 PyObject
*implementor
, uint32_t idx
) {
143 int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
144 PyObject
*implementor
, const char *child_name
) {
149 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBData(PyObject
*data
) {
153 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(
158 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(
163 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(
169 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject
*data
) {
174 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject
*data
) {
178 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(
184 lldb_private::python::SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue(
189 bool lldb_private::python::SWIGBridge::
190 LLDBSwigPython_UpdateSynthProviderInstance(PyObject
*implementor
) {
194 bool lldb_private::python::SWIGBridge::
195 LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
196 PyObject
*implementor
) {
201 lldb_private::python::SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance(
202 PyObject
*implementor
) {
206 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommand(
207 const char *python_function_name
, const char *session_dictionary_name
,
208 lldb::DebuggerSP debugger
, const char *args
,
209 lldb_private::CommandReturnObject
&cmd_retobj
,
210 lldb::ExecutionContextRefSP exe_ctx_ref_sp
) {
214 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
215 PyObject
*implementor
, lldb::DebuggerSP debugger
, const char *args
,
216 lldb_private::CommandReturnObject
&cmd_retobj
,
217 lldb::ExecutionContextRefSP exe_ctx_ref_sp
) {
221 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
222 const char *python_module_name
, const char *session_dictionary_name
,
223 lldb::DebuggerSP debugger
) {
228 lldb_private::python::SWIGBridge::LLDBSWIGPythonCreateOSPlugin(
229 const char *python_class_name
, const char *session_dictionary_name
,
230 const lldb::ProcessSP
&process_sp
) {
231 return python::PythonObject();
235 lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer(
236 const char *python_class_name
, const char *session_dictionary_name
) {
237 return python::PythonObject();
241 lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments(
242 PyObject
*implementor
, const lldb::StackFrameSP
&frame_sp
) {
246 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess(
247 const char *python_function_name
, const char *session_dictionary_name
,
248 const lldb::ProcessSP
&process
, std::string
&output
) {
252 std::optional
<std::string
>
253 lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread(
254 const char *python_function_name
, const char *session_dictionary_name
,
255 lldb::ThreadSP thread
) {
259 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget(
260 const char *python_function_name
, const char *session_dictionary_name
,
261 const lldb::TargetSP
&target
, std::string
&output
) {
265 std::optional
<std::string
>
266 lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame(
267 const char *python_function_name
, const char *session_dictionary_name
,
268 lldb::StackFrameSP frame
) {
272 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
273 const char *python_function_name
, const char *session_dictionary_name
,
274 const lldb::ValueObjectSP
&value
, std::string
&output
) {
278 void *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting(
279 void *module
, const char *setting
, const lldb::TargetSP
&target_sp
) {
284 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopHook(
285 lldb::TargetSP target_sp
, const char *python_class_name
,
286 const char *session_dictionary_name
, const StructuredDataImpl
&args_impl
,
288 return python::PythonObject();
291 bool lldb_private::python::SWIGBridge::LLDBSwigPythonStopHookCallHandleStop(
292 void *implementor
, lldb::ExecutionContextRefSP exc_ctx_sp
,
293 lldb::StreamSP stream
) {
298 lldb_private::python::SWIGBridge::ToSWIGWrapper(const Status
&status
) {
299 return python::PythonObject();
303 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessAttachInfoSP
) {
304 return python::PythonObject();
308 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessLaunchInfoSP
) {
309 return python::PythonObject();
313 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP
) {
314 return python::PythonObject();
318 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ExecutionContextRefSP
) {
319 return python::PythonObject();
323 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessSP
) {
324 return python::PythonObject();
327 python::PythonObject
lldb_private::python::SWIGBridge::ToSWIGWrapper(
328 const lldb_private::StructuredDataImpl
&) {
329 return python::PythonObject();