xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
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 
21*04eeddc0SDimitry Andric #include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
22fe6060f1SDimitry Andric #include "lldb/lldb-forward.h"
23fe6060f1SDimitry Andric #include "lldb/lldb-types.h"
244824e7fdSDimitry Andric #include "llvm/Support/Error.h"
25fe6060f1SDimitry Andric 
26fe6060f1SDimitry Andric namespace lldb_private {
27fe6060f1SDimitry Andric 
28fe6060f1SDimitry Andric // GetPythonValueFormatString provides a system independent type safe way to
29fe6060f1SDimitry Andric // convert a variable's type into a python value format. Python value formats
30fe6060f1SDimitry Andric // are defined in terms of builtin C types and could change from system to as
31fe6060f1SDimitry Andric // the underlying typedef for uint* types, size_t, off_t and other values
32fe6060f1SDimitry Andric // change.
33fe6060f1SDimitry Andric 
34fe6060f1SDimitry Andric template <typename T> const char *GetPythonValueFormatString(T t);
35fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(char *);
36fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(char);
37fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned char);
38fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(short);
39fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned short);
40fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(int);
41fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned int);
42fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(long);
43fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned long);
44fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(long long);
45fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(unsigned long long);
46fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(float t);
47fe6060f1SDimitry Andric template <> const char *GetPythonValueFormatString(double t);
48fe6060f1SDimitry Andric 
494824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data);
504824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data);
514824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data);
524824e7fdSDimitry Andric void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);
534824e7fdSDimitry Andric 
544824e7fdSDimitry Andric // These prototypes are the Pythonic implementations of the required callbacks.
554824e7fdSDimitry Andric // Although these are scripting-language specific, their definition depends on
564824e7fdSDimitry Andric // the public API.
574824e7fdSDimitry Andric 
58*04eeddc0SDimitry Andric python::PythonObject LLDBSwigPythonCreateScriptedProcess(
59*04eeddc0SDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
60*04eeddc0SDimitry Andric     const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
61fe6060f1SDimitry Andric     std::string &error_string);
62fe6060f1SDimitry Andric 
63*04eeddc0SDimitry Andric python::PythonObject LLDBSwigPythonCreateScriptedThread(
64*04eeddc0SDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
65*04eeddc0SDimitry Andric     const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
66349cc55cSDimitry Andric     std::string &error_string);
67349cc55cSDimitry Andric 
684824e7fdSDimitry Andric llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction(
694824e7fdSDimitry Andric     const char *python_function_name, const char *session_dictionary_name,
704824e7fdSDimitry Andric     const lldb::StackFrameSP &sb_frame,
714824e7fdSDimitry Andric     const lldb::BreakpointLocationSP &sb_bp_loc,
720eae32dcSDimitry Andric     const lldb_private::StructuredDataImpl &args_impl);
734824e7fdSDimitry Andric 
744824e7fdSDimitry Andric bool LLDBSwigPythonWatchpointCallbackFunction(
754824e7fdSDimitry Andric     const char *python_function_name, const char *session_dictionary_name,
764824e7fdSDimitry Andric     const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp);
774824e7fdSDimitry Andric 
784824e7fdSDimitry Andric bool LLDBSwigPythonCallTypeScript(const char *python_function_name,
794824e7fdSDimitry Andric                                   const void *session_dictionary,
804824e7fdSDimitry Andric                                   const lldb::ValueObjectSP &valobj_sp,
814824e7fdSDimitry Andric                                   void **pyfunct_wrapper,
824824e7fdSDimitry Andric                                   const lldb::TypeSummaryOptionsSP &options_sp,
834824e7fdSDimitry Andric                                   std::string &retval);
844824e7fdSDimitry Andric 
85*04eeddc0SDimitry Andric python::PythonObject
864824e7fdSDimitry Andric LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name,
874824e7fdSDimitry Andric                                       const char *session_dictionary_name,
884824e7fdSDimitry Andric                                       const lldb::ValueObjectSP &valobj_sp);
894824e7fdSDimitry Andric 
90*04eeddc0SDimitry Andric python::PythonObject
91*04eeddc0SDimitry Andric LLDBSwigPythonCreateCommandObject(const char *python_class_name,
924824e7fdSDimitry Andric                                   const char *session_dictionary_name,
930eae32dcSDimitry Andric                                   lldb::DebuggerSP debugger_sp);
944824e7fdSDimitry Andric 
95*04eeddc0SDimitry Andric python::PythonObject LLDBSwigPythonCreateScriptedThreadPlan(
964824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
970eae32dcSDimitry Andric     const 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 
104*04eeddc0SDimitry Andric python::PythonObject LLDBSwigPythonCreateScriptedBreakpointResolver(
1054824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
1060eae32dcSDimitry Andric     const 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 
112*04eeddc0SDimitry Andric python::PythonObject LLDBSwigPythonCreateScriptedStopHook(
113*04eeddc0SDimitry Andric     lldb::TargetSP target_sp, const char *python_class_name,
114*04eeddc0SDimitry Andric     const char *session_dictionary_name, const 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,
1390eae32dcSDimitry 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(
1440eae32dcSDimitry 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,
1500eae32dcSDimitry Andric                                   lldb::DebuggerSP debugger);
1514824e7fdSDimitry Andric 
152*04eeddc0SDimitry Andric python::PythonObject
153*04eeddc0SDimitry Andric LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
1544824e7fdSDimitry Andric                              const char *session_dictionary_name,
1554824e7fdSDimitry Andric                              const lldb::ProcessSP &process_sp);
1564824e7fdSDimitry Andric 
157*04eeddc0SDimitry Andric python::PythonObject
158*04eeddc0SDimitry Andric LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
1594824e7fdSDimitry Andric                                      const char *session_dictionary_name);
1604824e7fdSDimitry Andric 
1614824e7fdSDimitry Andric PyObject *
1624824e7fdSDimitry Andric LLDBSwigPython_GetRecognizedArguments(PyObject *implementor,
1634824e7fdSDimitry Andric                                       const lldb::StackFrameSP &frame_sp);
1644824e7fdSDimitry Andric 
1654824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name,
1664824e7fdSDimitry Andric                                            const char *session_dictionary_name,
1674824e7fdSDimitry Andric                                            const lldb::ProcessSP &process,
1684824e7fdSDimitry Andric                                            std::string &output);
1694824e7fdSDimitry Andric 
1700eae32dcSDimitry Andric llvm::Optional<std::string>
1710eae32dcSDimitry Andric LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name,
1724824e7fdSDimitry Andric                                      const char *session_dictionary_name,
1730eae32dcSDimitry Andric                                      lldb::ThreadSP thread);
1744824e7fdSDimitry Andric 
1754824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name,
1764824e7fdSDimitry Andric                                           const char *session_dictionary_name,
1774824e7fdSDimitry Andric                                           const lldb::TargetSP &target,
1784824e7fdSDimitry Andric                                           std::string &output);
1794824e7fdSDimitry Andric 
1800eae32dcSDimitry Andric llvm::Optional<std::string>
1810eae32dcSDimitry Andric LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name,
1824824e7fdSDimitry Andric                                     const char *session_dictionary_name,
1830eae32dcSDimitry Andric                                     lldb::StackFrameSP frame);
1844824e7fdSDimitry Andric 
1854824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name,
1864824e7fdSDimitry Andric                                          const char *session_dictionary_name,
1874824e7fdSDimitry Andric                                          const lldb::ValueObjectSP &value,
1884824e7fdSDimitry Andric                                          std::string &output);
1894824e7fdSDimitry Andric 
1904824e7fdSDimitry Andric void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
1914824e7fdSDimitry Andric                                        const lldb::TargetSP &target_sp);
192fe6060f1SDimitry Andric 
193fe6060f1SDimitry Andric } // namespace lldb_private
194fe6060f1SDimitry Andric 
195fe6060f1SDimitry Andric #endif // LLDB_ENABLE_PYTHON
196fe6060f1SDimitry Andric #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
197