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/ScriptInterpreterPythonImpl.h" 13 #include "Plugins/ScriptInterpreter/Python/lldb-python.h" 14 #include "lldb/Host/FileSystem.h" 15 #include "lldb/Host/HostInfo.h" 16 17 #include "PythonTestSuite.h" 18 19 using namespace lldb_private; 20 class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl { 21 public: 22 using ScriptInterpreterPythonImpl::Initialize; 23 using ScriptInterpreterPythonImpl::InitializePrivate; 24 }; 25 26 void PythonTestSuite::SetUp() { 27 FileSystem::Initialize(); 28 HostInfoBase::Initialize(); 29 // ScriptInterpreterPython::Initialize() depends on HostInfo being 30 // initializedso it can compute the python directory etc. 31 TestScriptInterpreterPython::Initialize(); 32 TestScriptInterpreterPython::InitializePrivate(); 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 #define LLDBSwigPyInit PyInit__lldb 57 #else 58 extern "C" void init_lldb(void) {} 59 #define LLDBSwigPyInit init_lldb 60 #endif 61 62 extern "C" bool LLDBSwigPythonBreakpointCallbackFunction( 63 const char *python_function_name, const char *session_dictionary_name, 64 const lldb::StackFrameSP &sb_frame, 65 const lldb::BreakpointLocationSP &sb_bp_loc) { 66 return false; 67 } 68 69 extern "C" bool LLDBSwigPythonWatchpointCallbackFunction( 70 const char *python_function_name, const char *session_dictionary_name, 71 const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) { 72 return false; 73 } 74 75 extern "C" bool LLDBSwigPythonCallTypeScript( 76 const char *python_function_name, void *session_dictionary, 77 const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, 78 const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) { 79 return false; 80 } 81 82 extern "C" void * 83 LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, 84 const char *session_dictionary_name, 85 const lldb::ValueObjectSP &valobj_sp) { 86 return nullptr; 87 } 88 89 extern "C" void * 90 LLDBSwigPythonCreateCommandObject(const char *python_class_name, 91 const char *session_dictionary_name, 92 const lldb::DebuggerSP debugger_sp) { 93 return nullptr; 94 } 95 96 extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( 97 const char *python_class_name, const char *session_dictionary_name, 98 std::string &error_string, 99 const lldb::ThreadPlanSP &thread_plan_sp) { 100 return nullptr; 101 } 102 103 extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, 104 const char *method_name, 105 Event *event_sp, bool &got_error) { 106 return false; 107 } 108 109 extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver( 110 const char *python_class_name, const char *session_dictionary_name, 111 lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) { 112 return nullptr; 113 } 114 115 extern "C" unsigned int 116 LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, 117 lldb_private::SymbolContext *sym_ctx) { 118 return 0; 119 } 120 121 extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor, 122 uint32_t max) { 123 return 0; 124 } 125 126 extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor, 127 uint32_t idx) { 128 return nullptr; 129 } 130 131 extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor, 132 const char *child_name) { 133 return 0; 134 } 135 136 extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) { 137 return nullptr; 138 } 139 140 extern lldb::ValueObjectSP 141 LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { 142 return nullptr; 143 } 144 145 extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor) { 146 return false; 147 } 148 149 extern "C" bool 150 LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor) { 151 return false; 152 } 153 154 extern "C" void * 155 LLDBSwigPython_GetValueSynthProviderInstance(void *implementor) { 156 return nullptr; 157 } 158 159 extern "C" bool 160 LLDBSwigPythonCallCommand(const char *python_function_name, 161 const char *session_dictionary_name, 162 lldb::DebuggerSP &debugger, const char *args, 163 lldb_private::CommandReturnObject &cmd_retobj, 164 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 165 return false; 166 } 167 168 extern "C" bool 169 LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger, 170 const char *args, 171 lldb_private::CommandReturnObject &cmd_retobj, 172 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 173 return false; 174 } 175 176 extern "C" bool 177 LLDBSwigPythonCallModuleInit(const char *python_module_name, 178 const char *session_dictionary_name, 179 lldb::DebuggerSP &debugger) { 180 return false; 181 } 182 183 extern "C" void * 184 LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 185 const char *session_dictionary_name, 186 const lldb::ProcessSP &process_sp) { 187 return nullptr; 188 } 189 190 extern "C" void * 191 LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, 192 const char *session_dictionary_name) { 193 return nullptr; 194 } 195 196 extern "C" void * 197 LLDBSwigPython_GetRecognizedArguments(void *implementor, 198 const lldb::StackFrameSP &frame_sp) { 199 return nullptr; 200 } 201 202 extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess( 203 const char *python_function_name, const char *session_dictionary_name, 204 lldb::ProcessSP &process, std::string &output) { 205 return false; 206 } 207 208 extern "C" bool LLDBSWIGPythonRunScriptKeywordThread( 209 const char *python_function_name, const char *session_dictionary_name, 210 lldb::ThreadSP &thread, std::string &output) { 211 return false; 212 } 213 214 extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget( 215 const char *python_function_name, const char *session_dictionary_name, 216 lldb::TargetSP &target, std::string &output) { 217 return false; 218 } 219 220 extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame( 221 const char *python_function_name, const char *session_dictionary_name, 222 lldb::StackFrameSP &frame, std::string &output) { 223 return false; 224 } 225 226 extern "C" bool LLDBSWIGPythonRunScriptKeywordValue( 227 const char *python_function_name, const char *session_dictionary_name, 228 lldb::ValueObjectSP &value, std::string &output) { 229 return false; 230 } 231 232 extern "C" void * 233 LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, 234 const lldb::TargetSP &target_sp) { 235 return nullptr; 236 } 237