1c946d462SZachary Turner //===-- PythonTestSuite.cpp -------------------------------------*- C++ -*-===// 2c946d462SZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c946d462SZachary Turner // 7c946d462SZachary Turner //===----------------------------------------------------------------------===// 8c946d462SZachary Turner 9b9c1b51eSKate Stone #include "gtest/gtest.h" 10c946d462SZachary Turner 11c946d462SZachary Turner #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" 126f8251fbSJonas Devlieghere #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h" 1346376966SJonas Devlieghere #include "Plugins/ScriptInterpreter/Python/lldb-python.h" 1446376966SJonas Devlieghere #include "lldb/Host/FileSystem.h" 15b9c1b51eSKate Stone #include "lldb/Host/HostInfo.h" 16c946d462SZachary Turner 17c946d462SZachary Turner #include "PythonTestSuite.h" 18c946d462SZachary Turner 19c946d462SZachary Turner using namespace lldb_private; 206f8251fbSJonas Devlieghere class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl { 21e3959de2SJonas Devlieghere public: 226f8251fbSJonas Devlieghere using ScriptInterpreterPythonImpl::Initialize; 236f8251fbSJonas Devlieghere using ScriptInterpreterPythonImpl::InitializePrivate; 24e3959de2SJonas Devlieghere }; 25c946d462SZachary Turner 26b9c1b51eSKate Stone void PythonTestSuite::SetUp() { 2746376966SJonas Devlieghere FileSystem::Initialize(); 28c946d462SZachary Turner HostInfoBase::Initialize(); 29c946d462SZachary Turner // ScriptInterpreterPython::Initialize() depends on HostInfo being 30c946d462SZachary Turner // initializedso it can compute the python directory etc. 31e3959de2SJonas Devlieghere TestScriptInterpreterPython::Initialize(); 32e3959de2SJonas Devlieghere TestScriptInterpreterPython::InitializePrivate(); 33c946d462SZachary Turner 34c946d462SZachary Turner // Although we don't care about concurrency for the purposes of running 35c946d462SZachary Turner // this test suite, Python requires the GIL to be locked even for 36c946d462SZachary Turner // deallocating memory, which can happen when you call Py_DECREF or 37c946d462SZachary Turner // Py_INCREF. So acquire the GIL for the entire duration of this 38c946d462SZachary Turner // test suite. 39c946d462SZachary Turner m_gil_state = PyGILState_Ensure(); 40c946d462SZachary Turner } 41c946d462SZachary Turner 42b9c1b51eSKate Stone void PythonTestSuite::TearDown() { 43c946d462SZachary Turner PyGILState_Release(m_gil_state); 44c946d462SZachary Turner 45e3959de2SJonas Devlieghere TestScriptInterpreterPython::Terminate(); 460bca15a3SJonas Devlieghere HostInfoBase::Terminate(); 470bca15a3SJonas Devlieghere FileSystem::Terminate(); 48c946d462SZachary Turner } 49282890d7SJonas Devlieghere 50282890d7SJonas Devlieghere // The following functions are the Pythonic implementations of the required 51282890d7SJonas Devlieghere // callbacks. Because they're defined in libLLDB which we cannot link for the 52282890d7SJonas Devlieghere // unit test, we have a 'default' implementation here. 53282890d7SJonas Devlieghere 54282890d7SJonas Devlieghere #if PY_MAJOR_VERSION >= 3 55282890d7SJonas Devlieghere extern "C" PyObject *PyInit__lldb(void) { return nullptr; } 56282890d7SJonas Devlieghere #define LLDBSwigPyInit PyInit__lldb 57282890d7SJonas Devlieghere #else 58282890d7SJonas Devlieghere extern "C" void init_lldb(void) {} 59282890d7SJonas Devlieghere #define LLDBSwigPyInit init_lldb 60282890d7SJonas Devlieghere #endif 61282890d7SJonas Devlieghere 62*a69bbe02SLawrence D'Anna extern "C" llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( 63282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 64282890d7SJonas Devlieghere const lldb::StackFrameSP &sb_frame, 65738af7a6SJim Ingham const lldb::BreakpointLocationSP &sb_bp_loc, 66738af7a6SJim Ingham StructuredDataImpl *args_impl) { 67282890d7SJonas Devlieghere return false; 68282890d7SJonas Devlieghere } 69282890d7SJonas Devlieghere 70282890d7SJonas Devlieghere extern "C" bool LLDBSwigPythonWatchpointCallbackFunction( 71282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 72282890d7SJonas Devlieghere const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) { 73282890d7SJonas Devlieghere return false; 74282890d7SJonas Devlieghere } 75282890d7SJonas Devlieghere 76282890d7SJonas Devlieghere extern "C" bool LLDBSwigPythonCallTypeScript( 77282890d7SJonas Devlieghere const char *python_function_name, void *session_dictionary, 78282890d7SJonas Devlieghere const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, 79282890d7SJonas Devlieghere const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) { 80282890d7SJonas Devlieghere return false; 81282890d7SJonas Devlieghere } 82282890d7SJonas Devlieghere 83282890d7SJonas Devlieghere extern "C" void * 84282890d7SJonas Devlieghere LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, 85282890d7SJonas Devlieghere const char *session_dictionary_name, 86282890d7SJonas Devlieghere const lldb::ValueObjectSP &valobj_sp) { 87282890d7SJonas Devlieghere return nullptr; 88282890d7SJonas Devlieghere } 89282890d7SJonas Devlieghere 90282890d7SJonas Devlieghere extern "C" void * 91282890d7SJonas Devlieghere LLDBSwigPythonCreateCommandObject(const char *python_class_name, 92282890d7SJonas Devlieghere const char *session_dictionary_name, 93282890d7SJonas Devlieghere const lldb::DebuggerSP debugger_sp) { 94282890d7SJonas Devlieghere return nullptr; 95282890d7SJonas Devlieghere } 96282890d7SJonas Devlieghere 97282890d7SJonas Devlieghere extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( 98282890d7SJonas Devlieghere const char *python_class_name, const char *session_dictionary_name, 9927a14f19SJim Ingham StructuredDataImpl *args_data, 10093c98346SJim Ingham std::string &error_string, 101282890d7SJonas Devlieghere const lldb::ThreadPlanSP &thread_plan_sp) { 102282890d7SJonas Devlieghere return nullptr; 103282890d7SJonas Devlieghere } 104282890d7SJonas Devlieghere 105282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, 106282890d7SJonas Devlieghere const char *method_name, 107282890d7SJonas Devlieghere Event *event_sp, bool &got_error) { 108282890d7SJonas Devlieghere return false; 109282890d7SJonas Devlieghere } 110282890d7SJonas Devlieghere 111282890d7SJonas Devlieghere extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver( 112282890d7SJonas Devlieghere const char *python_class_name, const char *session_dictionary_name, 113282890d7SJonas Devlieghere lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) { 114282890d7SJonas Devlieghere return nullptr; 115282890d7SJonas Devlieghere } 116282890d7SJonas Devlieghere 117282890d7SJonas Devlieghere extern "C" unsigned int 118282890d7SJonas Devlieghere LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, 119282890d7SJonas Devlieghere lldb_private::SymbolContext *sym_ctx) { 120282890d7SJonas Devlieghere return 0; 121282890d7SJonas Devlieghere } 122282890d7SJonas Devlieghere 123282890d7SJonas Devlieghere extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor, 124282890d7SJonas Devlieghere uint32_t max) { 125282890d7SJonas Devlieghere return 0; 126282890d7SJonas Devlieghere } 127282890d7SJonas Devlieghere 128282890d7SJonas Devlieghere extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor, 129282890d7SJonas Devlieghere uint32_t idx) { 130282890d7SJonas Devlieghere return nullptr; 131282890d7SJonas Devlieghere } 132282890d7SJonas Devlieghere 133282890d7SJonas Devlieghere extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor, 134282890d7SJonas Devlieghere const char *child_name) { 135282890d7SJonas Devlieghere return 0; 136282890d7SJonas Devlieghere } 137282890d7SJonas Devlieghere 138282890d7SJonas Devlieghere extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) { 139282890d7SJonas Devlieghere return nullptr; 140282890d7SJonas Devlieghere } 141282890d7SJonas Devlieghere 142282890d7SJonas Devlieghere extern lldb::ValueObjectSP 143282890d7SJonas Devlieghere LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { 144282890d7SJonas Devlieghere return nullptr; 145282890d7SJonas Devlieghere } 146282890d7SJonas Devlieghere 147282890d7SJonas Devlieghere extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor) { 148282890d7SJonas Devlieghere return false; 149282890d7SJonas Devlieghere } 150282890d7SJonas Devlieghere 151282890d7SJonas Devlieghere extern "C" bool 152282890d7SJonas Devlieghere LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor) { 153282890d7SJonas Devlieghere return false; 154282890d7SJonas Devlieghere } 155282890d7SJonas Devlieghere 156282890d7SJonas Devlieghere extern "C" void * 157282890d7SJonas Devlieghere LLDBSwigPython_GetValueSynthProviderInstance(void *implementor) { 158282890d7SJonas Devlieghere return nullptr; 159282890d7SJonas Devlieghere } 160282890d7SJonas Devlieghere 161282890d7SJonas Devlieghere extern "C" bool 162282890d7SJonas Devlieghere LLDBSwigPythonCallCommand(const char *python_function_name, 163282890d7SJonas Devlieghere const char *session_dictionary_name, 164282890d7SJonas Devlieghere lldb::DebuggerSP &debugger, const char *args, 165282890d7SJonas Devlieghere lldb_private::CommandReturnObject &cmd_retobj, 166282890d7SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 167282890d7SJonas Devlieghere return false; 168282890d7SJonas Devlieghere } 169282890d7SJonas Devlieghere 170282890d7SJonas Devlieghere extern "C" bool 171282890d7SJonas Devlieghere LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger, 172282890d7SJonas Devlieghere const char *args, 173282890d7SJonas Devlieghere lldb_private::CommandReturnObject &cmd_retobj, 174282890d7SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp) { 175282890d7SJonas Devlieghere return false; 176282890d7SJonas Devlieghere } 177282890d7SJonas Devlieghere 178282890d7SJonas Devlieghere extern "C" bool 179282890d7SJonas Devlieghere LLDBSwigPythonCallModuleInit(const char *python_module_name, 180282890d7SJonas Devlieghere const char *session_dictionary_name, 181282890d7SJonas Devlieghere lldb::DebuggerSP &debugger) { 182282890d7SJonas Devlieghere return false; 183282890d7SJonas Devlieghere } 184282890d7SJonas Devlieghere 185282890d7SJonas Devlieghere extern "C" void * 186282890d7SJonas Devlieghere LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 187282890d7SJonas Devlieghere const char *session_dictionary_name, 188282890d7SJonas Devlieghere const lldb::ProcessSP &process_sp) { 189282890d7SJonas Devlieghere return nullptr; 190282890d7SJonas Devlieghere } 191282890d7SJonas Devlieghere 192282890d7SJonas Devlieghere extern "C" void * 193282890d7SJonas Devlieghere LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, 194282890d7SJonas Devlieghere const char *session_dictionary_name) { 195282890d7SJonas Devlieghere return nullptr; 196282890d7SJonas Devlieghere } 197282890d7SJonas Devlieghere 198282890d7SJonas Devlieghere extern "C" void * 199282890d7SJonas Devlieghere LLDBSwigPython_GetRecognizedArguments(void *implementor, 200282890d7SJonas Devlieghere const lldb::StackFrameSP &frame_sp) { 201282890d7SJonas Devlieghere return nullptr; 202282890d7SJonas Devlieghere } 203282890d7SJonas Devlieghere 204282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess( 205282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 206282890d7SJonas Devlieghere lldb::ProcessSP &process, std::string &output) { 207282890d7SJonas Devlieghere return false; 208282890d7SJonas Devlieghere } 209282890d7SJonas Devlieghere 210282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordThread( 211282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 212282890d7SJonas Devlieghere lldb::ThreadSP &thread, std::string &output) { 213282890d7SJonas Devlieghere return false; 214282890d7SJonas Devlieghere } 215282890d7SJonas Devlieghere 216282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget( 217282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 218282890d7SJonas Devlieghere lldb::TargetSP &target, std::string &output) { 219282890d7SJonas Devlieghere return false; 220282890d7SJonas Devlieghere } 221282890d7SJonas Devlieghere 222282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame( 223282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 224282890d7SJonas Devlieghere lldb::StackFrameSP &frame, std::string &output) { 225282890d7SJonas Devlieghere return false; 226282890d7SJonas Devlieghere } 227282890d7SJonas Devlieghere 228282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordValue( 229282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name, 230282890d7SJonas Devlieghere lldb::ValueObjectSP &value, std::string &output) { 231282890d7SJonas Devlieghere return false; 232282890d7SJonas Devlieghere } 233282890d7SJonas Devlieghere 234282890d7SJonas Devlieghere extern "C" void * 235282890d7SJonas Devlieghere LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, 236282890d7SJonas Devlieghere const lldb::TargetSP &target_sp) { 237282890d7SJonas Devlieghere return nullptr; 238282890d7SJonas Devlieghere } 239