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"
1246376966SJonas Devlieghere #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
1346376966SJonas Devlieghere #include "lldb/Host/FileSystem.h"
14b9c1b51eSKate Stone #include "lldb/Host/HostInfo.h"
15c946d462SZachary Turner 
16c946d462SZachary Turner #include "PythonTestSuite.h"
17c946d462SZachary Turner 
18c946d462SZachary Turner using namespace lldb_private;
19e3959de2SJonas Devlieghere class TestScriptInterpreterPython : public ScriptInterpreterPython {
20e3959de2SJonas Devlieghere public:
21e3959de2SJonas Devlieghere   using ScriptInterpreterPython::Initialize;
22e3959de2SJonas Devlieghere   using ScriptInterpreterPython::InitializePrivate;
23e3959de2SJonas Devlieghere };
24c946d462SZachary Turner 
25b9c1b51eSKate Stone void PythonTestSuite::SetUp() {
2646376966SJonas Devlieghere   FileSystem::Initialize();
27c946d462SZachary Turner   HostInfoBase::Initialize();
28c946d462SZachary Turner   // ScriptInterpreterPython::Initialize() depends on HostInfo being
29c946d462SZachary Turner   // initializedso it can compute the python directory etc.
30e3959de2SJonas Devlieghere   TestScriptInterpreterPython::Initialize();
31e3959de2SJonas Devlieghere   TestScriptInterpreterPython::InitializePrivate();
32c946d462SZachary Turner 
33c946d462SZachary Turner   // Although we don't care about concurrency for the purposes of running
34c946d462SZachary Turner   // this test suite, Python requires the GIL to be locked even for
35c946d462SZachary Turner   // deallocating memory, which can happen when you call Py_DECREF or
36c946d462SZachary Turner   // Py_INCREF.  So acquire the GIL for the entire duration of this
37c946d462SZachary Turner   // test suite.
38c946d462SZachary Turner   m_gil_state = PyGILState_Ensure();
39c946d462SZachary Turner }
40c946d462SZachary Turner 
41b9c1b51eSKate Stone void PythonTestSuite::TearDown() {
42c946d462SZachary Turner   PyGILState_Release(m_gil_state);
43c946d462SZachary Turner 
44e3959de2SJonas Devlieghere   TestScriptInterpreterPython::Terminate();
450bca15a3SJonas Devlieghere   HostInfoBase::Terminate();
460bca15a3SJonas Devlieghere   FileSystem::Terminate();
47c946d462SZachary Turner }
48*282890d7SJonas Devlieghere 
49*282890d7SJonas Devlieghere // The following functions are the Pythonic implementations of the required
50*282890d7SJonas Devlieghere // callbacks. Because they're defined in libLLDB which we cannot link for the
51*282890d7SJonas Devlieghere // unit test, we have a 'default' implementation here.
52*282890d7SJonas Devlieghere 
53*282890d7SJonas Devlieghere #if PY_MAJOR_VERSION >= 3
54*282890d7SJonas Devlieghere extern "C" PyObject *PyInit__lldb(void) { return nullptr; }
55*282890d7SJonas Devlieghere #define LLDBSwigPyInit PyInit__lldb
56*282890d7SJonas Devlieghere #else
57*282890d7SJonas Devlieghere extern "C" void init_lldb(void) {}
58*282890d7SJonas Devlieghere #define LLDBSwigPyInit init_lldb
59*282890d7SJonas Devlieghere #endif
60*282890d7SJonas Devlieghere 
61*282890d7SJonas Devlieghere extern "C" bool LLDBSwigPythonBreakpointCallbackFunction(
62*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
63*282890d7SJonas Devlieghere     const lldb::StackFrameSP &sb_frame,
64*282890d7SJonas Devlieghere     const lldb::BreakpointLocationSP &sb_bp_loc) {
65*282890d7SJonas Devlieghere   return false;
66*282890d7SJonas Devlieghere }
67*282890d7SJonas Devlieghere 
68*282890d7SJonas Devlieghere extern "C" bool LLDBSwigPythonWatchpointCallbackFunction(
69*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
70*282890d7SJonas Devlieghere     const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) {
71*282890d7SJonas Devlieghere   return false;
72*282890d7SJonas Devlieghere }
73*282890d7SJonas Devlieghere 
74*282890d7SJonas Devlieghere extern "C" bool LLDBSwigPythonCallTypeScript(
75*282890d7SJonas Devlieghere     const char *python_function_name, void *session_dictionary,
76*282890d7SJonas Devlieghere     const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper,
77*282890d7SJonas Devlieghere     const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) {
78*282890d7SJonas Devlieghere   return false;
79*282890d7SJonas Devlieghere }
80*282890d7SJonas Devlieghere 
81*282890d7SJonas Devlieghere extern "C" void *
82*282890d7SJonas Devlieghere LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name,
83*282890d7SJonas Devlieghere                                       const char *session_dictionary_name,
84*282890d7SJonas Devlieghere                                       const lldb::ValueObjectSP &valobj_sp) {
85*282890d7SJonas Devlieghere   return nullptr;
86*282890d7SJonas Devlieghere }
87*282890d7SJonas Devlieghere 
88*282890d7SJonas Devlieghere extern "C" void *
89*282890d7SJonas Devlieghere LLDBSwigPythonCreateCommandObject(const char *python_class_name,
90*282890d7SJonas Devlieghere                                   const char *session_dictionary_name,
91*282890d7SJonas Devlieghere                                   const lldb::DebuggerSP debugger_sp) {
92*282890d7SJonas Devlieghere   return nullptr;
93*282890d7SJonas Devlieghere }
94*282890d7SJonas Devlieghere 
95*282890d7SJonas Devlieghere extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan(
96*282890d7SJonas Devlieghere     const char *python_class_name, const char *session_dictionary_name,
97*282890d7SJonas Devlieghere     const lldb::ThreadPlanSP &thread_plan_sp) {
98*282890d7SJonas Devlieghere   return nullptr;
99*282890d7SJonas Devlieghere }
100*282890d7SJonas Devlieghere 
101*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor,
102*282890d7SJonas Devlieghere                                              const char *method_name,
103*282890d7SJonas Devlieghere                                              Event *event_sp, bool &got_error) {
104*282890d7SJonas Devlieghere   return false;
105*282890d7SJonas Devlieghere }
106*282890d7SJonas Devlieghere 
107*282890d7SJonas Devlieghere extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver(
108*282890d7SJonas Devlieghere     const char *python_class_name, const char *session_dictionary_name,
109*282890d7SJonas Devlieghere     lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) {
110*282890d7SJonas Devlieghere   return nullptr;
111*282890d7SJonas Devlieghere }
112*282890d7SJonas Devlieghere 
113*282890d7SJonas Devlieghere extern "C" unsigned int
114*282890d7SJonas Devlieghere LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
115*282890d7SJonas Devlieghere                                      lldb_private::SymbolContext *sym_ctx) {
116*282890d7SJonas Devlieghere   return 0;
117*282890d7SJonas Devlieghere }
118*282890d7SJonas Devlieghere 
119*282890d7SJonas Devlieghere extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor,
120*282890d7SJonas Devlieghere                                                       uint32_t max) {
121*282890d7SJonas Devlieghere   return 0;
122*282890d7SJonas Devlieghere }
123*282890d7SJonas Devlieghere 
124*282890d7SJonas Devlieghere extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor,
125*282890d7SJonas Devlieghere                                                 uint32_t idx) {
126*282890d7SJonas Devlieghere   return nullptr;
127*282890d7SJonas Devlieghere }
128*282890d7SJonas Devlieghere 
129*282890d7SJonas Devlieghere extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor,
130*282890d7SJonas Devlieghere                                                       const char *child_name) {
131*282890d7SJonas Devlieghere   return 0;
132*282890d7SJonas Devlieghere }
133*282890d7SJonas Devlieghere 
134*282890d7SJonas Devlieghere extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) {
135*282890d7SJonas Devlieghere   return nullptr;
136*282890d7SJonas Devlieghere }
137*282890d7SJonas Devlieghere 
138*282890d7SJonas Devlieghere extern lldb::ValueObjectSP
139*282890d7SJonas Devlieghere LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) {
140*282890d7SJonas Devlieghere   return nullptr;
141*282890d7SJonas Devlieghere }
142*282890d7SJonas Devlieghere 
143*282890d7SJonas Devlieghere extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor) {
144*282890d7SJonas Devlieghere   return false;
145*282890d7SJonas Devlieghere }
146*282890d7SJonas Devlieghere 
147*282890d7SJonas Devlieghere extern "C" bool
148*282890d7SJonas Devlieghere LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor) {
149*282890d7SJonas Devlieghere   return false;
150*282890d7SJonas Devlieghere }
151*282890d7SJonas Devlieghere 
152*282890d7SJonas Devlieghere extern "C" void *
153*282890d7SJonas Devlieghere LLDBSwigPython_GetValueSynthProviderInstance(void *implementor) {
154*282890d7SJonas Devlieghere   return nullptr;
155*282890d7SJonas Devlieghere }
156*282890d7SJonas Devlieghere 
157*282890d7SJonas Devlieghere extern "C" bool
158*282890d7SJonas Devlieghere LLDBSwigPythonCallCommand(const char *python_function_name,
159*282890d7SJonas Devlieghere                           const char *session_dictionary_name,
160*282890d7SJonas Devlieghere                           lldb::DebuggerSP &debugger, const char *args,
161*282890d7SJonas Devlieghere                           lldb_private::CommandReturnObject &cmd_retobj,
162*282890d7SJonas Devlieghere                           lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
163*282890d7SJonas Devlieghere   return false;
164*282890d7SJonas Devlieghere }
165*282890d7SJonas Devlieghere 
166*282890d7SJonas Devlieghere extern "C" bool
167*282890d7SJonas Devlieghere LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger,
168*282890d7SJonas Devlieghere                                 const char *args,
169*282890d7SJonas Devlieghere                                 lldb_private::CommandReturnObject &cmd_retobj,
170*282890d7SJonas Devlieghere                                 lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
171*282890d7SJonas Devlieghere   return false;
172*282890d7SJonas Devlieghere }
173*282890d7SJonas Devlieghere 
174*282890d7SJonas Devlieghere extern "C" bool
175*282890d7SJonas Devlieghere LLDBSwigPythonCallModuleInit(const char *python_module_name,
176*282890d7SJonas Devlieghere                              const char *session_dictionary_name,
177*282890d7SJonas Devlieghere                              lldb::DebuggerSP &debugger) {
178*282890d7SJonas Devlieghere   return false;
179*282890d7SJonas Devlieghere }
180*282890d7SJonas Devlieghere 
181*282890d7SJonas Devlieghere extern "C" void *
182*282890d7SJonas Devlieghere LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
183*282890d7SJonas Devlieghere                              const char *session_dictionary_name,
184*282890d7SJonas Devlieghere                              const lldb::ProcessSP &process_sp) {
185*282890d7SJonas Devlieghere   return nullptr;
186*282890d7SJonas Devlieghere }
187*282890d7SJonas Devlieghere 
188*282890d7SJonas Devlieghere extern "C" void *
189*282890d7SJonas Devlieghere LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
190*282890d7SJonas Devlieghere                                      const char *session_dictionary_name) {
191*282890d7SJonas Devlieghere   return nullptr;
192*282890d7SJonas Devlieghere }
193*282890d7SJonas Devlieghere 
194*282890d7SJonas Devlieghere extern "C" void *
195*282890d7SJonas Devlieghere LLDBSwigPython_GetRecognizedArguments(void *implementor,
196*282890d7SJonas Devlieghere                                       const lldb::StackFrameSP &frame_sp) {
197*282890d7SJonas Devlieghere   return nullptr;
198*282890d7SJonas Devlieghere }
199*282890d7SJonas Devlieghere 
200*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(
201*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
202*282890d7SJonas Devlieghere     lldb::ProcessSP &process, std::string &output) {
203*282890d7SJonas Devlieghere   return false;
204*282890d7SJonas Devlieghere }
205*282890d7SJonas Devlieghere 
206*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordThread(
207*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
208*282890d7SJonas Devlieghere     lldb::ThreadSP &thread, std::string &output) {
209*282890d7SJonas Devlieghere   return false;
210*282890d7SJonas Devlieghere }
211*282890d7SJonas Devlieghere 
212*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(
213*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
214*282890d7SJonas Devlieghere     lldb::TargetSP &target, std::string &output) {
215*282890d7SJonas Devlieghere   return false;
216*282890d7SJonas Devlieghere }
217*282890d7SJonas Devlieghere 
218*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame(
219*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
220*282890d7SJonas Devlieghere     lldb::StackFrameSP &frame, std::string &output) {
221*282890d7SJonas Devlieghere   return false;
222*282890d7SJonas Devlieghere }
223*282890d7SJonas Devlieghere 
224*282890d7SJonas Devlieghere extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(
225*282890d7SJonas Devlieghere     const char *python_function_name, const char *session_dictionary_name,
226*282890d7SJonas Devlieghere     lldb::ValueObjectSP &value, std::string &output) {
227*282890d7SJonas Devlieghere   return false;
228*282890d7SJonas Devlieghere }
229*282890d7SJonas Devlieghere 
230*282890d7SJonas Devlieghere extern "C" void *
231*282890d7SJonas Devlieghere LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
232*282890d7SJonas Devlieghere                                  const lldb::TargetSP &target_sp) {
233*282890d7SJonas Devlieghere   return nullptr;
234*282890d7SJonas Devlieghere }
235