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 bool 111 lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor, 112 const char *method_name, 113 Stream *event_sp, 114 bool &got_error) { 115 return false; 116 } 117 118 python::PythonObject 119 lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver( 120 const char *python_class_name, const char *session_dictionary_name, 121 const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) { 122 return python::PythonObject(); 123 } 124 125 unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver( 126 void *implementor, const char *method_name, 127 lldb_private::SymbolContext *sym_ctx) { 128 return 0; 129 } 130 131 size_t lldb_private::LLDBSwigPython_CalculateNumChildren(PyObject *implementor, 132 uint32_t max) { 133 return 0; 134 } 135 136 PyObject *lldb_private::LLDBSwigPython_GetChildAtIndex(PyObject *implementor, 137 uint32_t idx) { 138 return nullptr; 139 } 140 141 int lldb_private::LLDBSwigPython_GetIndexOfChildWithName( 142 PyObject *implementor, const char *child_name) { 143 return 0; 144 } 145 146 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) { 147 return nullptr; 148 } 149 150 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data) { 151 return nullptr; 152 } 153 154 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) { 155 return nullptr; 156 } 157 158 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(PyObject *data) { 159 return nullptr; 160 } 161 162 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) { 163 return nullptr; 164 } 165 166 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) { 167 return nullptr; 168 } 169 170 void * 171 lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) { 172 return nullptr; 173 } 174 175 lldb::ValueObjectSP 176 lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { 177 return nullptr; 178 } 179 180 bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance( 181 PyObject *implementor) { 182 return false; 183 } 184 185 bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 186 PyObject *implementor) { 187 return false; 188 } 189 190 PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance( 191 PyObject *implementor) { 192 return nullptr; 193 } 194 195 bool lldb_private::LLDBSwigPythonCallCommand( 196 const char *python_function_name, const char *session_dictionary_name, 197 lldb::DebuggerSP debugger, const char *args, 198 lldb_private::CommandReturnObject &cmd_retobj, 199 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 200 return false; 201 } 202 203 bool lldb_private::LLDBSwigPythonCallCommandObject( 204 PyObject *implementor, lldb::DebuggerSP debugger, const char *args, 205 lldb_private::CommandReturnObject &cmd_retobj, 206 lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 207 return false; 208 } 209 210 bool lldb_private::LLDBSwigPythonCallModuleInit( 211 const char *python_module_name, const char *session_dictionary_name, 212 lldb::DebuggerSP debugger) { 213 return false; 214 } 215 216 python::PythonObject 217 lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 218 const char *session_dictionary_name, 219 const lldb::ProcessSP &process_sp) { 220 return python::PythonObject(); 221 } 222 223 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject( 224 const char *python_class_name, const char *session_dictionary_name, 225 lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl, 226 std::string &error_string) { 227 return python::PythonObject(); 228 } 229 230 python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer( 231 const char *python_class_name, const char *session_dictionary_name) { 232 return python::PythonObject(); 233 } 234 235 PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments( 236 PyObject *implementor, const lldb::StackFrameSP &frame_sp) { 237 return nullptr; 238 } 239 240 bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess( 241 const char *python_function_name, const char *session_dictionary_name, 242 const lldb::ProcessSP &process, std::string &output) { 243 return false; 244 } 245 246 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread( 247 const char *python_function_name, const char *session_dictionary_name, 248 lldb::ThreadSP thread) { 249 return std::nullopt; 250 } 251 252 bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget( 253 const char *python_function_name, const char *session_dictionary_name, 254 const lldb::TargetSP &target, std::string &output) { 255 return false; 256 } 257 258 std::optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame( 259 const char *python_function_name, const char *session_dictionary_name, 260 lldb::StackFrameSP frame) { 261 return std::nullopt; 262 } 263 264 bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue( 265 const char *python_function_name, const char *session_dictionary_name, 266 const lldb::ValueObjectSP &value, std::string &output) { 267 return false; 268 } 269 270 void *lldb_private::LLDBSWIGPython_GetDynamicSetting( 271 void *module, const char *setting, const lldb::TargetSP &target_sp) { 272 return nullptr; 273 } 274 275 python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook( 276 lldb::TargetSP target_sp, const char *python_class_name, 277 const char *session_dictionary_name, const StructuredDataImpl &args_impl, 278 Status &error) { 279 return python::PythonObject(); 280 } 281 282 bool lldb_private::LLDBSwigPythonStopHookCallHandleStop( 283 void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp, 284 lldb::StreamSP stream) { 285 return false; 286 } 287 288 python::PythonObject lldb_private::python::ToSWIGWrapper(const Status &status) { 289 return python::PythonObject(); 290 } 291 292 python::PythonObject 293 lldb_private::python::ToSWIGWrapper(lldb::ProcessAttachInfoSP) { 294 return python::PythonObject(); 295 } 296 297 python::PythonObject 298 lldb_private::python::ToSWIGWrapper(lldb::ProcessLaunchInfoSP) { 299 return python::PythonObject(); 300 } 301 302 python::PythonObject 303 lldb_private::python::ToSWIGWrapper(lldb::DataExtractorSP) { 304 return python::PythonObject(); 305 } 306