xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
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,
60*0eae32dcSDimitry Andric                                           const 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,
66*0eae32dcSDimitry Andric                                          const 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,
73*0eae32dcSDimitry Andric     const 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,
93*0eae32dcSDimitry Andric                                         lldb::DebuggerSP debugger_sp);
944824e7fdSDimitry Andric 
954824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedThreadPlan(
964824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
97*0eae32dcSDimitry 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 
1044824e7fdSDimitry Andric void *LLDBSwigPythonCreateScriptedBreakpointResolver(
1054824e7fdSDimitry Andric     const char *python_class_name, const char *session_dictionary_name,
106*0eae32dcSDimitry 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*0eae32dcSDimitry Andric void *LLDBSwigPythonCreateScriptedStopHook(lldb::TargetSP target_sp,
113*0eae32dcSDimitry Andric                                            const char *python_class_name,
114*0eae32dcSDimitry Andric                                            const char *session_dictionary_name,
115*0eae32dcSDimitry Andric                                            const StructuredDataImpl &args,
1164824e7fdSDimitry Andric                                            lldb_private::Status &error);
1174824e7fdSDimitry Andric 
1184824e7fdSDimitry Andric bool LLDBSwigPythonStopHookCallHandleStop(void *implementor,
1194824e7fdSDimitry Andric                                           lldb::ExecutionContextRefSP exc_ctx,
1204824e7fdSDimitry Andric                                           lldb::StreamSP stream);
1214824e7fdSDimitry Andric 
1224824e7fdSDimitry Andric size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max);
1234824e7fdSDimitry Andric 
1244824e7fdSDimitry Andric PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx);
1254824e7fdSDimitry Andric 
1264824e7fdSDimitry Andric int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
1274824e7fdSDimitry Andric                                            const char *child_name);
1284824e7fdSDimitry Andric 
1294824e7fdSDimitry Andric lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data);
1304824e7fdSDimitry Andric 
1314824e7fdSDimitry Andric bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor);
1324824e7fdSDimitry Andric 
1334824e7fdSDimitry Andric bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
1344824e7fdSDimitry Andric     PyObject *implementor);
1354824e7fdSDimitry Andric 
1364824e7fdSDimitry Andric PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor);
1374824e7fdSDimitry Andric 
1384824e7fdSDimitry Andric bool LLDBSwigPythonCallCommand(const char *python_function_name,
1394824e7fdSDimitry Andric                                const char *session_dictionary_name,
140*0eae32dcSDimitry Andric                                lldb::DebuggerSP debugger, const char *args,
1414824e7fdSDimitry Andric                                lldb_private::CommandReturnObject &cmd_retobj,
1424824e7fdSDimitry Andric                                lldb::ExecutionContextRefSP exe_ctx_ref_sp);
1434824e7fdSDimitry Andric 
1444824e7fdSDimitry Andric bool LLDBSwigPythonCallCommandObject(
145*0eae32dcSDimitry Andric     PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
1464824e7fdSDimitry Andric     lldb_private::CommandReturnObject &cmd_retobj,
1474824e7fdSDimitry Andric     lldb::ExecutionContextRefSP exe_ctx_ref_sp);
1484824e7fdSDimitry Andric 
1494824e7fdSDimitry Andric bool LLDBSwigPythonCallModuleInit(const char *python_module_name,
1504824e7fdSDimitry Andric                                   const char *session_dictionary_name,
151*0eae32dcSDimitry Andric                                   lldb::DebuggerSP debugger);
1524824e7fdSDimitry Andric 
1534824e7fdSDimitry Andric void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
1544824e7fdSDimitry Andric                                    const char *session_dictionary_name,
1554824e7fdSDimitry Andric                                    const lldb::ProcessSP &process_sp);
1564824e7fdSDimitry Andric 
1574824e7fdSDimitry Andric void *LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
1584824e7fdSDimitry Andric                                            const char *session_dictionary_name);
1594824e7fdSDimitry Andric 
1604824e7fdSDimitry Andric PyObject *
1614824e7fdSDimitry Andric LLDBSwigPython_GetRecognizedArguments(PyObject *implementor,
1624824e7fdSDimitry Andric                                       const lldb::StackFrameSP &frame_sp);
1634824e7fdSDimitry Andric 
1644824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name,
1654824e7fdSDimitry Andric                                            const char *session_dictionary_name,
1664824e7fdSDimitry Andric                                            const lldb::ProcessSP &process,
1674824e7fdSDimitry Andric                                            std::string &output);
1684824e7fdSDimitry Andric 
169*0eae32dcSDimitry Andric llvm::Optional<std::string>
170*0eae32dcSDimitry Andric LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name,
1714824e7fdSDimitry Andric                                      const char *session_dictionary_name,
172*0eae32dcSDimitry Andric                                      lldb::ThreadSP thread);
1734824e7fdSDimitry Andric 
1744824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name,
1754824e7fdSDimitry Andric                                           const char *session_dictionary_name,
1764824e7fdSDimitry Andric                                           const lldb::TargetSP &target,
1774824e7fdSDimitry Andric                                           std::string &output);
1784824e7fdSDimitry Andric 
179*0eae32dcSDimitry Andric llvm::Optional<std::string>
180*0eae32dcSDimitry Andric LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name,
1814824e7fdSDimitry Andric                                     const char *session_dictionary_name,
182*0eae32dcSDimitry Andric                                     lldb::StackFrameSP frame);
1834824e7fdSDimitry Andric 
1844824e7fdSDimitry Andric bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name,
1854824e7fdSDimitry Andric                                          const char *session_dictionary_name,
1864824e7fdSDimitry Andric                                          const lldb::ValueObjectSP &value,
1874824e7fdSDimitry Andric                                          std::string &output);
1884824e7fdSDimitry Andric 
1894824e7fdSDimitry Andric void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
1904824e7fdSDimitry Andric                                        const lldb::TargetSP &target_sp);
191fe6060f1SDimitry Andric 
192fe6060f1SDimitry Andric } // namespace lldb_private
193fe6060f1SDimitry Andric 
194fe6060f1SDimitry Andric #endif // LLDB_ENABLE_PYTHON
195fe6060f1SDimitry Andric #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
196