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_CastPyObjectToSBBreakpoint(PyObject *data) { 143 return nullptr; 144 } 145 146 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) { 147 return nullptr; 148 } 149 150 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject *data) { 151 return nullptr; 152 } 153 154 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) { 155 return nullptr; 156 } 157 158 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) { 159 return nullptr; 160 } 161 162 void * 163 lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) { 164 return nullptr; 165 } 166 167 lldb::ValueObjectSP 168 lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { 169 return nullptr; 170 } 171 172 bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance( 173 PyObject *implementor) { 174 return false; 175 } 176 177 bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 178 PyObject *implementor) { 179 return false; 180 } 181 182 PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance( 183 PyObject *implementor) { 184 return nullptr; 185 } 186 187 bool lldb_private::LLDBSwigPythonCallCommand( 188 const char *python_function_name, const char *session_dictionary_name, 189 lldb::DebuggerSP debugger, const char *args, 190 lldb_private::CommandReturnObject &cmd_retobj, 191 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 192 return false; 193 } 194 195 bool lldb_private::LLDBSwigPythonCallCommandObject( 196 PyObject *implementor, lldb::DebuggerSP debugger, const char *args, 197 lldb_private::CommandReturnObject &cmd_retobj, 198 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 199 return false; 200 } 201 202 bool lldb_private::LLDBSwigPythonCallModuleInit( 203 const char *python_module_name, const char *session_dictionary_name, 204 lldb::DebuggerSP debugger) { 205 return false; 206 } 207 208 python::PythonObject 209 lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 210 const char *session_dictionary_name, 211 const lldb::ProcessSP &process_sp) { 212 return python::PythonObject(); 213 } 214 215 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject( 216 const char *python_class_name, const char *session_dictionary_name, 217 lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl, 218 std::string &error_string) { 219 return python::PythonObject(); 220 } 221 222 python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer( 223 const char *python_class_name, const char *session_dictionary_name) { 224 return python::PythonObject(); 225 } 226 227 PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments( 228 PyObject *implementor, const lldb::StackFrameSP &frame_sp) { 229 return nullptr; 230 } 231 232 bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess( 233 const char *python_function_name, const char *session_dictionary_name, 234 const lldb::ProcessSP &process, std::string &output) { 235 return false; 236 } 237 238 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread( 239 const char *python_function_name, const char *session_dictionary_name, 240 lldb::ThreadSP thread) { 241 return std::nullopt; 242 } 243 244 bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget( 245 const char *python_function_name, const char *session_dictionary_name, 246 const lldb::TargetSP &target, std::string &output) { 247 return false; 248 } 249 250 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame( 251 const char *python_function_name, const char *session_dictionary_name, 252 lldb::StackFrameSP frame) { 253 return std::nullopt; 254 } 255 256 bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue( 257 const char *python_function_name, const char *session_dictionary_name, 258 const lldb::ValueObjectSP &value, std::string &output) { 259 return false; 260 } 261 262 void *lldb_private::LLDBSWIGPython_GetDynamicSetting( 263 void *module, const char *setting, const lldb::TargetSP &target_sp) { 264 return nullptr; 265 } 266 267 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook( 268 lldb::TargetSP target_sp, const char *python_class_name, 269 const char *session_dictionary_name, const StructuredDataImpl &args_impl, 270 Status &error) { 271 return python::PythonObject(); 272 } 273 274 bool lldb_private::LLDBSwigPythonStopHookCallHandleStop( 275 void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp, 276 lldb::StreamSP stream) { 277 return false; 278 } 279 280 python::PythonObject lldb_private::python::ToSWIGWrapper(const Status &status) { 281 return python::PythonObject(); 282 } 283 284 python::PythonObject 285 lldb_private::python::ToSWIGWrapper(lldb::ProcessAttachInfoSP) { 286 return python::PythonObject(); 287 } 288 289 python::PythonObject 290 lldb_private::python::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) { 291 return python::PythonObject(); 292 } 293 294 python::PythonObject 295 lldb_private::python::ToSWIGWrapper(lldb::DataExtractorSP) { 296 return python::PythonObject(); 297 } 298