180814287SRaphael Isemann //===-- PythonTestSuite.cpp -----------------------------------------------===//
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
119a14adeaSPavel Labath #include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h"
12c946d462SZachary Turner #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
136f8251fbSJonas Devlieghere #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h"
149a14adeaSPavel Labath #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
153925204cSMed Ismail Bennani
1646376966SJonas Devlieghere #include "lldb/Host/FileSystem.h"
17b9c1b51eSKate Stone #include "lldb/Host/HostInfo.h"
18c946d462SZachary Turner
19c946d462SZachary Turner #include "PythonTestSuite.h"
20c946d462SZachary Turner
21c946d462SZachary Turner using namespace lldb_private;
226f8251fbSJonas Devlieghere class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl {
23e3959de2SJonas Devlieghere public:
246f8251fbSJonas Devlieghere using ScriptInterpreterPythonImpl::Initialize;
25e3959de2SJonas Devlieghere };
26c946d462SZachary Turner
SetUp()27b9c1b51eSKate Stone void PythonTestSuite::SetUp() {
2846376966SJonas Devlieghere FileSystem::Initialize();
29c946d462SZachary Turner HostInfoBase::Initialize();
30c946d462SZachary Turner // ScriptInterpreterPython::Initialize() depends on HostInfo being
31c946d462SZachary Turner // initializedso it can compute the python directory etc.
32e3959de2SJonas Devlieghere TestScriptInterpreterPython::Initialize();
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
TearDown()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
PyInit__lldb(void)54282890d7SJonas Devlieghere extern "C" PyObject *PyInit__lldb(void) { return nullptr; }
55282890d7SJonas Devlieghere
LLDBSwigPythonBreakpointCallbackFunction(const char * python_function_name,const char * session_dictionary_name,const lldb::StackFrameSP & sb_frame,const lldb::BreakpointLocationSP & sb_bp_loc,const StructuredDataImpl & args_impl)569a14adeaSPavel Labath llvm::Expected<bool> lldb_private::LLDBSwigPythonBreakpointCallbackFunction(
57282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
58282890d7SJonas Devlieghere const lldb::StackFrameSP &sb_frame,
59738af7a6SJim Ingham const lldb::BreakpointLocationSP &sb_bp_loc,
6082de8df2SPavel Labath const StructuredDataImpl &args_impl) {
61282890d7SJonas Devlieghere return false;
62282890d7SJonas Devlieghere }
63282890d7SJonas Devlieghere
LLDBSwigPythonWatchpointCallbackFunction(const char * python_function_name,const char * session_dictionary_name,const lldb::StackFrameSP & sb_frame,const lldb::WatchpointSP & sb_wp)649a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonWatchpointCallbackFunction(
65282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
66282890d7SJonas Devlieghere const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) {
67282890d7SJonas Devlieghere return false;
68282890d7SJonas Devlieghere }
69282890d7SJonas Devlieghere
LLDBSwigPythonCallTypeScript(const char * python_function_name,const void * session_dictionary,const lldb::ValueObjectSP & valobj_sp,void ** pyfunct_wrapper,const lldb::TypeSummaryOptionsSP & options_sp,std::string & retval)709a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonCallTypeScript(
719a14adeaSPavel Labath const char *python_function_name, const void *session_dictionary,
72282890d7SJonas Devlieghere const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
73282890d7SJonas Devlieghere const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) {
74282890d7SJonas Devlieghere return false;
75282890d7SJonas Devlieghere }
76282890d7SJonas Devlieghere
LLDBSwigPythonCreateSyntheticProvider(const char * python_class_name,const char * session_dictionary_name,const lldb::ValueObjectSP & valobj_sp)77*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
789a14adeaSPavel Labath const char *python_class_name, const char *session_dictionary_name,
79282890d7SJonas Devlieghere const lldb::ValueObjectSP &valobj_sp) {
80*c154f397SPavel Labath return python::PythonObject();
81282890d7SJonas Devlieghere }
82282890d7SJonas Devlieghere
LLDBSwigPythonCreateCommandObject(const char * python_class_name,const char * session_dictionary_name,lldb::DebuggerSP debugger_sp)83*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
849a14adeaSPavel Labath const char *python_class_name, const char *session_dictionary_name,
857406d236SPavel Labath lldb::DebuggerSP debugger_sp) {
86*c154f397SPavel Labath return python::PythonObject();
87282890d7SJonas Devlieghere }
88282890d7SJonas Devlieghere
LLDBSwigPythonCreateScriptedThreadPlan(const char * python_class_name,const char * session_dictionary_name,const StructuredDataImpl & args_data,std::string & error_string,const lldb::ThreadPlanSP & thread_plan_sp)89*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
90282890d7SJonas Devlieghere const char *python_class_name, const char *session_dictionary_name,
9182de8df2SPavel Labath const StructuredDataImpl &args_data, std::string &error_string,
92282890d7SJonas Devlieghere const lldb::ThreadPlanSP &thread_plan_sp) {
93*c154f397SPavel Labath return python::PythonObject();
94282890d7SJonas Devlieghere }
95282890d7SJonas Devlieghere
LLDBSWIGPythonCallThreadPlan(void * implementor,const char * method_name,Event * event_sp,bool & got_error)969a14adeaSPavel Labath bool lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor,
97282890d7SJonas Devlieghere const char *method_name,
989a14adeaSPavel Labath Event *event_sp,
999a14adeaSPavel Labath bool &got_error) {
100282890d7SJonas Devlieghere return false;
101282890d7SJonas Devlieghere }
102282890d7SJonas Devlieghere
103*c154f397SPavel Labath python::PythonObject
LLDBSwigPythonCreateScriptedBreakpointResolver(const char * python_class_name,const char * session_dictionary_name,const StructuredDataImpl & args,const lldb::BreakpointSP & bkpt_sp)104*c154f397SPavel Labath lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
105282890d7SJonas Devlieghere const char *python_class_name, const char *session_dictionary_name,
10682de8df2SPavel Labath const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
107*c154f397SPavel Labath return python::PythonObject();
108282890d7SJonas Devlieghere }
109282890d7SJonas Devlieghere
LLDBSwigPythonCallBreakpointResolver(void * implementor,const char * method_name,lldb_private::SymbolContext * sym_ctx)1109a14adeaSPavel Labath unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
1119a14adeaSPavel Labath void *implementor, const char *method_name,
112282890d7SJonas Devlieghere lldb_private::SymbolContext *sym_ctx) {
113282890d7SJonas Devlieghere return 0;
114282890d7SJonas Devlieghere }
115282890d7SJonas Devlieghere
LLDBSwigPython_CalculateNumChildren(PyObject * implementor,uint32_t max)1169a14adeaSPavel Labath size_t lldb_private::LLDBSwigPython_CalculateNumChildren(PyObject *implementor,
117282890d7SJonas Devlieghere uint32_t max) {
118282890d7SJonas Devlieghere return 0;
119282890d7SJonas Devlieghere }
120282890d7SJonas Devlieghere
LLDBSwigPython_GetChildAtIndex(PyObject * implementor,uint32_t idx)1219a14adeaSPavel Labath PyObject *lldb_private::LLDBSwigPython_GetChildAtIndex(PyObject *implementor,
122282890d7SJonas Devlieghere uint32_t idx) {
123282890d7SJonas Devlieghere return nullptr;
124282890d7SJonas Devlieghere }
125282890d7SJonas Devlieghere
LLDBSwigPython_GetIndexOfChildWithName(PyObject * implementor,const char * child_name)1269a14adeaSPavel Labath int lldb_private::LLDBSwigPython_GetIndexOfChildWithName(
1279a14adeaSPavel Labath PyObject *implementor, const char *child_name) {
128282890d7SJonas Devlieghere return 0;
129282890d7SJonas Devlieghere }
130282890d7SJonas Devlieghere
LLDBSWIGPython_CastPyObjectToSBData(PyObject * data)1319a14adeaSPavel Labath void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) {
1321f6a57c1SMed Ismail Bennani return nullptr;
1331f6a57c1SMed Ismail Bennani }
1341f6a57c1SMed Ismail Bennani
LLDBSWIGPython_CastPyObjectToSBError(PyObject * data)1359a14adeaSPavel Labath void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) {
1361f6a57c1SMed Ismail Bennani return nullptr;
1371f6a57c1SMed Ismail Bennani }
1381f6a57c1SMed Ismail Bennani
LLDBSWIGPython_CastPyObjectToSBValue(PyObject * data)1399a14adeaSPavel Labath void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) {
140282890d7SJonas Devlieghere return nullptr;
141282890d7SJonas Devlieghere }
142282890d7SJonas Devlieghere
1439a14adeaSPavel Labath void *
LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject * data)1449a14adeaSPavel Labath lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) {
145a758c9f7SMed Ismail Bennani return nullptr;
146a758c9f7SMed Ismail Bennani }
147a758c9f7SMed Ismail Bennani
1489a14adeaSPavel Labath lldb::ValueObjectSP
LLDBSWIGPython_GetValueObjectSPFromSBValue(void * data)1499a14adeaSPavel Labath lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) {
150282890d7SJonas Devlieghere return nullptr;
151282890d7SJonas Devlieghere }
152282890d7SJonas Devlieghere
LLDBSwigPython_UpdateSynthProviderInstance(PyObject * implementor)1539a14adeaSPavel Labath bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance(
1549a14adeaSPavel Labath PyObject *implementor) {
155282890d7SJonas Devlieghere return false;
156282890d7SJonas Devlieghere }
157282890d7SJonas Devlieghere
LLDBSwigPython_MightHaveChildrenSynthProviderInstance(PyObject * implementor)1589a14adeaSPavel Labath bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
1599a14adeaSPavel Labath PyObject *implementor) {
160282890d7SJonas Devlieghere return false;
161282890d7SJonas Devlieghere }
162282890d7SJonas Devlieghere
LLDBSwigPython_GetValueSynthProviderInstance(PyObject * implementor)1639a14adeaSPavel Labath PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance(
1649a14adeaSPavel Labath PyObject *implementor) {
165282890d7SJonas Devlieghere return nullptr;
166282890d7SJonas Devlieghere }
167282890d7SJonas Devlieghere
LLDBSwigPythonCallCommand(const char * python_function_name,const char * session_dictionary_name,lldb::DebuggerSP debugger,const char * args,lldb_private::CommandReturnObject & cmd_retobj,lldb::ExecutionContextRefSP exe_ctx_ref_sp)1689a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonCallCommand(
1699a14adeaSPavel Labath const char *python_function_name, const char *session_dictionary_name,
1707406d236SPavel Labath lldb::DebuggerSP debugger, const char *args,
171282890d7SJonas Devlieghere lldb_private::CommandReturnObject &cmd_retobj,
172282890d7SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
173282890d7SJonas Devlieghere return false;
174282890d7SJonas Devlieghere }
175282890d7SJonas Devlieghere
LLDBSwigPythonCallCommandObject(PyObject * implementor,lldb::DebuggerSP debugger,const char * args,lldb_private::CommandReturnObject & cmd_retobj,lldb::ExecutionContextRefSP exe_ctx_ref_sp)1769a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonCallCommandObject(
1777406d236SPavel Labath PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
178282890d7SJonas Devlieghere lldb_private::CommandReturnObject &cmd_retobj,
179282890d7SJonas Devlieghere lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
180282890d7SJonas Devlieghere return false;
181282890d7SJonas Devlieghere }
182282890d7SJonas Devlieghere
LLDBSwigPythonCallModuleInit(const char * python_module_name,const char * session_dictionary_name,lldb::DebuggerSP debugger)1839a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonCallModuleInit(
1849a14adeaSPavel Labath const char *python_module_name, const char *session_dictionary_name,
1857406d236SPavel Labath lldb::DebuggerSP debugger) {
186282890d7SJonas Devlieghere return false;
187282890d7SJonas Devlieghere }
188282890d7SJonas Devlieghere
189*c154f397SPavel Labath python::PythonObject
LLDBSWIGPythonCreateOSPlugin(const char * python_class_name,const char * session_dictionary_name,const lldb::ProcessSP & process_sp)1909a14adeaSPavel Labath lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
191282890d7SJonas Devlieghere const char *session_dictionary_name,
192282890d7SJonas Devlieghere const lldb::ProcessSP &process_sp) {
193*c154f397SPavel Labath return python::PythonObject();
194282890d7SJonas Devlieghere }
195282890d7SJonas Devlieghere
LLDBSwigPythonCreateScriptedProcess(const char * python_class_name,const char * session_dictionary_name,const lldb::TargetSP & target_sp,const StructuredDataImpl & args_impl,std::string & error_string)196*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
1971f6a57c1SMed Ismail Bennani const char *python_class_name, const char *session_dictionary_name,
19882de8df2SPavel Labath const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
1991f6a57c1SMed Ismail Bennani std::string &error_string) {
200*c154f397SPavel Labath return python::PythonObject();
2011f6a57c1SMed Ismail Bennani }
2021f6a57c1SMed Ismail Bennani
LLDBSwigPythonCreateScriptedThread(const char * python_class_name,const char * session_dictionary_name,const lldb::ProcessSP & process_sp,const StructuredDataImpl & args_impl,std::string & error_string)203*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
20459d8dd79SMed Ismail Bennani const char *python_class_name, const char *session_dictionary_name,
20582de8df2SPavel Labath const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
206738621d0SMed Ismail Bennani std::string &error_string) {
207*c154f397SPavel Labath return python::PythonObject();
20859d8dd79SMed Ismail Bennani }
20959d8dd79SMed Ismail Bennani
LLDBSWIGPython_CreateFrameRecognizer(const char * python_class_name,const char * session_dictionary_name)210*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
2119a14adeaSPavel Labath const char *python_class_name, const char *session_dictionary_name) {
212*c154f397SPavel Labath return python::PythonObject();
213282890d7SJonas Devlieghere }
214282890d7SJonas Devlieghere
LLDBSwigPython_GetRecognizedArguments(PyObject * implementor,const lldb::StackFrameSP & frame_sp)2159a14adeaSPavel Labath PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments(
2169a14adeaSPavel Labath PyObject *implementor, const lldb::StackFrameSP &frame_sp) {
217282890d7SJonas Devlieghere return nullptr;
218282890d7SJonas Devlieghere }
219282890d7SJonas Devlieghere
LLDBSWIGPythonRunScriptKeywordProcess(const char * python_function_name,const char * session_dictionary_name,const lldb::ProcessSP & process,std::string & output)2209a14adeaSPavel Labath bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess(
221282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
2227f09ab08SPavel Labath const lldb::ProcessSP &process, std::string &output) {
223282890d7SJonas Devlieghere return false;
224282890d7SJonas Devlieghere }
225282890d7SJonas Devlieghere
LLDBSWIGPythonRunScriptKeywordThread(const char * python_function_name,const char * session_dictionary_name,lldb::ThreadSP thread)2267406d236SPavel Labath llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
227282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
2287406d236SPavel Labath lldb::ThreadSP thread) {
2297406d236SPavel Labath return llvm::None;
230282890d7SJonas Devlieghere }
231282890d7SJonas Devlieghere
LLDBSWIGPythonRunScriptKeywordTarget(const char * python_function_name,const char * session_dictionary_name,const lldb::TargetSP & target,std::string & output)2329a14adeaSPavel Labath bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
233282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
2347f09ab08SPavel Labath const lldb::TargetSP &target, std::string &output) {
235282890d7SJonas Devlieghere return false;
236282890d7SJonas Devlieghere }
237282890d7SJonas Devlieghere
LLDBSWIGPythonRunScriptKeywordFrame(const char * python_function_name,const char * session_dictionary_name,lldb::StackFrameSP frame)2387406d236SPavel Labath llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
239282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
2407406d236SPavel Labath lldb::StackFrameSP frame) {
2417406d236SPavel Labath return llvm::None;
242282890d7SJonas Devlieghere }
243282890d7SJonas Devlieghere
LLDBSWIGPythonRunScriptKeywordValue(const char * python_function_name,const char * session_dictionary_name,const lldb::ValueObjectSP & value,std::string & output)2449a14adeaSPavel Labath bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue(
245282890d7SJonas Devlieghere const char *python_function_name, const char *session_dictionary_name,
2467f09ab08SPavel Labath const lldb::ValueObjectSP &value, std::string &output) {
247282890d7SJonas Devlieghere return false;
248282890d7SJonas Devlieghere }
249282890d7SJonas Devlieghere
LLDBSWIGPython_GetDynamicSetting(void * module,const char * setting,const lldb::TargetSP & target_sp)2509a14adeaSPavel Labath void *lldb_private::LLDBSWIGPython_GetDynamicSetting(
2519a14adeaSPavel Labath void *module, const char *setting, const lldb::TargetSP &target_sp) {
252282890d7SJonas Devlieghere return nullptr;
253282890d7SJonas Devlieghere }
2541b1d9815SJim Ingham
LLDBSwigPythonCreateScriptedStopHook(lldb::TargetSP target_sp,const char * python_class_name,const char * session_dictionary_name,const StructuredDataImpl & args_impl,Status & error)255*c154f397SPavel Labath python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook(
2561b1d9815SJim Ingham lldb::TargetSP target_sp, const char *python_class_name,
25782de8df2SPavel Labath const char *session_dictionary_name, const StructuredDataImpl &args_impl,
25882de8df2SPavel Labath Status &error) {
259*c154f397SPavel Labath return python::PythonObject();
2601b1d9815SJim Ingham }
2611b1d9815SJim Ingham
LLDBSwigPythonStopHookCallHandleStop(void * implementor,lldb::ExecutionContextRefSP exc_ctx_sp,lldb::StreamSP stream)2629a14adeaSPavel Labath bool lldb_private::LLDBSwigPythonStopHookCallHandleStop(
2639a14adeaSPavel Labath void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp,
2641b1d9815SJim Ingham lldb::StreamSP stream) {
2651b1d9815SJim Ingham return false;
2661b1d9815SJim Ingham }
267