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> 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) { 63 return false; 64 } 65 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) { 69 return false; 70 } 71 72 bool lldb_private::python::SWIGBridge::LLDBSwigPythonFormatterCallbackFunction( 73 const char *python_function_name, const char *session_dictionary_name, 74 lldb::TypeImplSP type_impl_sp) { 75 return false; 76 } 77 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) { 82 return false; 83 } 84 85 python::PythonObject 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(); 90 } 91 92 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(); 97 } 98 99 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(); 105 } 106 107 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan( 108 void *implementor, const char *method_name, Event *event_sp, 109 bool &got_error) { 110 return false; 111 } 112 113 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonCallThreadPlan( 114 void *implementor, const char *method_name, Stream *event_sp, 115 bool &got_error) { 116 return false; 117 } 118 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(); 124 } 125 126 unsigned int 127 lldb_private::python::SWIGBridge::LLDBSwigPythonCallBreakpointResolver( 128 void *implementor, const char *method_name, 129 lldb_private::SymbolContext *sym_ctx) { 130 return 0; 131 } 132 133 size_t lldb_private::python::SWIGBridge::LLDBSwigPython_CalculateNumChildren( 134 PyObject *implementor, uint32_t max) { 135 return 0; 136 } 137 138 PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex( 139 PyObject *implementor, uint32_t idx) { 140 return nullptr; 141 } 142 143 int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName( 144 PyObject *implementor, const char *child_name) { 145 return 0; 146 } 147 148 void * 149 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) { 150 return nullptr; 151 } 152 153 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBBreakpoint( 154 PyObject *data) { 155 return nullptr; 156 } 157 158 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBAttachInfo( 159 PyObject *data) { 160 return nullptr; 161 } 162 163 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo( 164 PyObject *data) { 165 return nullptr; 166 } 167 168 void * 169 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) { 170 return nullptr; 171 } 172 173 void * 174 lldb_private::python::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) { 175 return nullptr; 176 } 177 178 void *lldb_private::python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo( 179 PyObject *data) { 180 return nullptr; 181 } 182 183 lldb::ValueObjectSP 184 lldb_private::python::SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue( 185 void *data) { 186 return nullptr; 187 } 188 189 bool lldb_private::python::SWIGBridge:: 190 LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor) { 191 return false; 192 } 193 194 bool lldb_private::python::SWIGBridge:: 195 LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 196 PyObject *implementor) { 197 return false; 198 } 199 200 PyObject * 201 lldb_private::python::SWIGBridge::LLDBSwigPython_GetValueSynthProviderInstance( 202 PyObject *implementor) { 203 return nullptr; 204 } 205 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) { 211 return false; 212 } 213 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) { 218 return false; 219 } 220 221 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit( 222 const char *python_module_name, const char *session_dictionary_name, 223 lldb::DebuggerSP debugger) { 224 return false; 225 } 226 227 python::PythonObject 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(); 232 } 233 234 python::PythonObject 235 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedObject( 236 const char *python_class_name, const char *session_dictionary_name, 237 lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl, 238 std::string &error_string) { 239 return python::PythonObject(); 240 } 241 242 python::PythonObject 243 lldb_private::python::SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer( 244 const char *python_class_name, const char *session_dictionary_name) { 245 return python::PythonObject(); 246 } 247 248 PyObject * 249 lldb_private::python::SWIGBridge::LLDBSwigPython_GetRecognizedArguments( 250 PyObject *implementor, const lldb::StackFrameSP &frame_sp) { 251 return nullptr; 252 } 253 254 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordProcess( 255 const char *python_function_name, const char *session_dictionary_name, 256 const lldb::ProcessSP &process, std::string &output) { 257 return false; 258 } 259 260 std::optional<std::string> 261 lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordThread( 262 const char *python_function_name, const char *session_dictionary_name, 263 lldb::ThreadSP thread) { 264 return std::nullopt; 265 } 266 267 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordTarget( 268 const char *python_function_name, const char *session_dictionary_name, 269 const lldb::TargetSP &target, std::string &output) { 270 return false; 271 } 272 273 std::optional<std::string> 274 lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordFrame( 275 const char *python_function_name, const char *session_dictionary_name, 276 lldb::StackFrameSP frame) { 277 return std::nullopt; 278 } 279 280 bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue( 281 const char *python_function_name, const char *session_dictionary_name, 282 const lldb::ValueObjectSP &value, std::string &output) { 283 return false; 284 } 285 286 void *lldb_private::python::SWIGBridge::LLDBSWIGPython_GetDynamicSetting( 287 void *module, const char *setting, const lldb::TargetSP &target_sp) { 288 return nullptr; 289 } 290 291 python::PythonObject 292 lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopHook( 293 lldb::TargetSP target_sp, const char *python_class_name, 294 const char *session_dictionary_name, const StructuredDataImpl &args_impl, 295 Status &error) { 296 return python::PythonObject(); 297 } 298 299 bool lldb_private::python::SWIGBridge::LLDBSwigPythonStopHookCallHandleStop( 300 void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp, 301 lldb::StreamSP stream) { 302 return false; 303 } 304 305 python::PythonObject 306 lldb_private::python::SWIGBridge::ToSWIGWrapper(const Status &status) { 307 return python::PythonObject(); 308 } 309 310 python::PythonObject 311 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessAttachInfoSP) { 312 return python::PythonObject(); 313 } 314 315 python::PythonObject 316 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) { 317 return python::PythonObject(); 318 } 319 320 python::PythonObject 321 lldb_private::python::SWIGBridge::ToSWIGWrapper(lldb::DataExtractorSP) { 322 return python::PythonObject(); 323 } 324