1fe6060f1SDimitry Andric //===-- ScriptInterpreterPython.h -------------------------------*- C++ -*-===//
2fe6060f1SDimitry Andric //
3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fe6060f1SDimitry Andric //
7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
8fe6060f1SDimitry Andric 
9fe6060f1SDimitry Andric #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
10fe6060f1SDimitry Andric #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
11fe6060f1SDimitry Andric 
12fe6060f1SDimitry Andric #include <string>
13fe6060f1SDimitry Andric 
14fe6060f1SDimitry Andric #include "lldb/Host/Config.h"
15fe6060f1SDimitry Andric 
16fe6060f1SDimitry Andric #if LLDB_ENABLE_PYTHON
17fe6060f1SDimitry Andric 
184824e7fdSDimitry Andric // LLDB Python header must be included first
194824e7fdSDimitry Andric #include "lldb-python.h"
204824e7fdSDimitry Andric 
21fe6060f1SDimitry Andric #include "lldb/lldb-forward.h"
22fe6060f1SDimitry Andric #include "lldb/lldb-types.h"
234824e7fdSDimitry Andric #include "llvm/Support/Error.h"
24fe6060f1SDimitry Andric 
25fe6060f1SDimitry Andric namespace lldb_private {
26fe6060f1SDimitry Andric 
27fe6060f1SDimitry Andric // GetPythonValueFormatString provides a system independent type safe way to
28fe6060f1SDimitry Andric // convert a variable's type into a python value format. Python value formats
29fe6060f1SDimitry Andric // are defined in terms of builtin C types and could change from system to as
30fe6060f1SDimitry Andric // the underlying typedef for uint* types, size_t, off_t and other values
31fe6060f1SDimitry Andric // change.
32fe6060f1SDimitry Andric 
33fe6060f1SDimitry Andric template <typename T> const char *GetPythonValueFormatString(T t);
34fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(char *);
35fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(char);
36fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned char);
37fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(short);
38fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned short);
39fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(int);
40fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned int);
41fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(long);
42fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned long);
43fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(long long);
44fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned long long);
45fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(float t);
46fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(double t);
47fe6060f1SDimitry Andric 
484824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data);
494824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data);
504824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data);
514824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);
524824e7fdSDimitry Andric 
534824e7fdSDimitry Andric // These prototypes are the Pythonic implementations of the required callbacks.
544824e7fdSDimitry Andric // Although these are scripting-language specific, their definition depends on
554824e7fdSDimitry Andric // the public API.
564824e7fdSDimitry Andric 
574824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedProcess(const char *python_class_name,
584824e7fdSDimitry Andric                                           const char *session_dictionary_name,
594824e7fdSDimitry Andric                                           const lldb::TargetSP &target_sp,
604824e7fdSDimitry Andric                                           StructuredDataImpl *args_impl,
61fe6060f1SDimitry Andric                                           std::string &error_string);
62fe6060f1SDimitry Andric 
634824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedThread(const char *python_class_name,
644824e7fdSDimitry Andric                                          const char *session_dictionary_name,
654824e7fdSDimitry Andric                                          const lldb::ProcessSP &process_sp,
664824e7fdSDimitry Andric                                          StructuredDataImpl *args_impl,
67349cc55cSDimitry Andric                                          std::string &error_string);
68349cc55cSDimitry Andric 
694824e7fdSDimitry Andric llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction(
704824e7fdSDimitry Andric     const char *python_function_name, const char *session_dictionary_name,
714824e7fdSDimitry Andric     const lldb::StackFrameSP &sb_frame,
724824e7fdSDimitry Andric     const lldb::BreakpointLocationSP &sb_bp_loc,
734824e7fdSDimitry Andric     lldb_private::StructuredDataImpl *args_impl);
744824e7fdSDimitry Andric 
754824e7fdSDimitry Andric bool LLDBSwigPythonWatchpointCallbackFunction(
764824e7fdSDimitry Andric     const char *python_function_name, const char *session_dictionary_name,
774824e7fdSDimitry Andric     const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp);
784824e7fdSDimitry Andric 
794824e7fdSDimitry Andric bool LLDBSwigPythonCallTypeScript(const char *python_function_name,
804824e7fdSDimitry Andric                                   const void *session_dictionary,
814824e7fdSDimitry Andric                                   const lldb::ValueObjectSP &valobj_sp,
824824e7fdSDimitry Andric                                   void **pyfunct_wrapper,
834824e7fdSDimitry Andric                                   const lldb::TypeSummaryOptionsSP &options_sp,
844824e7fdSDimitry Andric                                   std::string &retval);
854824e7fdSDimitry Andric 
864824e7fdSDimitry Andric void *
874824e7fdSDimitry Andric LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name,
884824e7fdSDimitry Andric                                       const char *session_dictionary_name,
894824e7fdSDimitry Andric                                       const lldb::ValueObjectSP &valobj_sp);
904824e7fdSDimitry Andric 
914824e7fdSDimitry Andric void *LLDBSwigPythonCreateCommandObject(const char *python_class_name,
924824e7fdSDimitry Andric                                         const char *session_dictionary_name,
934824e7fdSDimitry Andric                                         const lldb::DebuggerSP debugger_sp);
944824e7fdSDimitry Andric 
954824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedThreadPlan(
964824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
974824e7fdSDimitry Andric     lldb_private::StructuredDataImpl *args_data, std::string &error_string,
984824e7fdSDimitry Andric     const lldb::ThreadPlanSP &thread_plan_sp);
994824e7fdSDimitry Andric 
1004824e7fdSDimitry Andric bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name,
1014824e7fdSDimitry Andric                                   lldb_private::Event *event_sp,
1024824e7fdSDimitry Andric                                   bool &got_error);
1034824e7fdSDimitry Andric 
1044824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedBreakpointResolver(
1054824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
1064824e7fdSDimitry Andric     lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp);
1074824e7fdSDimitry Andric 
1084824e7fdSDimitry Andric unsigned int
1094824e7fdSDimitry Andric LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
1104824e7fdSDimitry Andric                                      lldb_private::SymbolContext *sym_ctx);
1114824e7fdSDimitry Andric 
1124824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedStopHook(
1134824e7fdSDimitry Andric     lldb::TargetSP target_sp, const char *python_class_name,
1144824e7fdSDimitry Andric     const char *session_dictionary_name, lldb_private::StructuredDataImpl *args,
1154824e7fdSDimitry Andric     lldb_private::Status &error);
1164824e7fdSDimitry Andric 
1174824e7fdSDimitry Andric bool LLDBSwigPythonStopHookCallHandleStop(void *implementor,
1184824e7fdSDimitry Andric                                           lldb::ExecutionContextRefSP exc_ctx,
1194824e7fdSDimitry Andric                                           lldb::StreamSP stream);
1204824e7fdSDimitry Andric 
1214824e7fdSDimitry Andric size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max);
1224824e7fdSDimitry Andric 
1234824e7fdSDimitry Andric PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx);
1244824e7fdSDimitry Andric 
1254824e7fdSDimitry Andric int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
1264824e7fdSDimitry Andric                                            const char *child_name);
1274824e7fdSDimitry Andric 
1284824e7fdSDimitry Andric lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data);
1294824e7fdSDimitry Andric 
1304824e7fdSDimitry Andric bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor);
1314824e7fdSDimitry Andric 
1324824e7fdSDimitry Andric bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
1334824e7fdSDimitry Andric     PyObject *implementor);
1344824e7fdSDimitry Andric 
1354824e7fdSDimitry Andric PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor);
1364824e7fdSDimitry Andric 
1374824e7fdSDimitry Andric bool LLDBSwigPythonCallCommand(const char *python_function_name,
1384824e7fdSDimitry Andric                                const char *session_dictionary_name,
1394824e7fdSDimitry Andric                                lldb::DebuggerSP &debugger, const char *args,
1404824e7fdSDimitry Andric                                lldb_private::CommandReturnObject &cmd_retobj,
1414824e7fdSDimitry Andric                                lldb::ExecutionContextRefSP exe_ctx_ref_sp);
1424824e7fdSDimitry Andric 
1434824e7fdSDimitry Andric bool LLDBSwigPythonCallCommandObject(
1444824e7fdSDimitry Andric     PyObject *implementor, lldb::DebuggerSP &debugger, const char *args,
1454824e7fdSDimitry Andric     lldb_private::CommandReturnObject &cmd_retobj,
1464824e7fdSDimitry Andric     lldb::ExecutionContextRefSP exe_ctx_ref_sp);
1474824e7fdSDimitry Andric 
1484824e7fdSDimitry Andric bool LLDBSwigPythonCallModuleInit(const char *python_module_name,
1494824e7fdSDimitry Andric                                   const char *session_dictionary_name,
1504824e7fdSDimitry Andric                                   lldb::DebuggerSP &debugger);
1514824e7fdSDimitry Andric 
1524824e7fdSDimitry Andric void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
1534824e7fdSDimitry Andric                                    const char *session_dictionary_name,
1544824e7fdSDimitry Andric                                    const lldb::ProcessSP &process_sp);
1554824e7fdSDimitry Andric 
1564824e7fdSDimitry Andric void *LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
1574824e7fdSDimitry Andric                                            const char *session_dictionary_name);
1584824e7fdSDimitry Andric 
1594824e7fdSDimitry Andric PyObject *
1604824e7fdSDimitry Andric LLDBSwigPython_GetRecognizedArguments(PyObject *implementor,
1614824e7fdSDimitry Andric                                       const lldb::StackFrameSP &frame_sp);
1624824e7fdSDimitry Andric 
1634824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name,
1644824e7fdSDimitry Andric                                            const char *session_dictionary_name,
1654824e7fdSDimitry Andric                                            const lldb::ProcessSP &process,
1664824e7fdSDimitry Andric                                            std::string &output);
1674824e7fdSDimitry Andric 
1684824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name,
1694824e7fdSDimitry Andric                                           const char *session_dictionary_name,
1704824e7fdSDimitry Andric                                           lldb::ThreadSP &thread,
1714824e7fdSDimitry Andric                                           std::string &output);
1724824e7fdSDimitry Andric 
1734824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name,
1744824e7fdSDimitry Andric                                           const char *session_dictionary_name,
1754824e7fdSDimitry Andric                                           const lldb::TargetSP &target,
1764824e7fdSDimitry Andric                                           std::string &output);
1774824e7fdSDimitry Andric 
1784824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name,
1794824e7fdSDimitry Andric                                          const char *session_dictionary_name,
1804824e7fdSDimitry Andric                                          lldb::StackFrameSP &frame,
1814824e7fdSDimitry Andric                                          std::string &output);
1824824e7fdSDimitry Andric 
1834824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name,
1844824e7fdSDimitry Andric                                          const char *session_dictionary_name,
1854824e7fdSDimitry Andric                                          const lldb::ValueObjectSP &value,
1864824e7fdSDimitry Andric                                          std::string &output);
1874824e7fdSDimitry Andric 
1884824e7fdSDimitry Andric void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
1894824e7fdSDimitry Andric                                        const lldb::TargetSP &target_sp);
190fe6060f1SDimitry Andric 
191fe6060f1SDimitry Andric } // namespace lldb_private
192fe6060f1SDimitry Andric 
193fe6060f1SDimitry Andric #endif // LLDB_ENABLE_PYTHON
194fe6060f1SDimitry Andric #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
195