xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1 //===-- ScriptInterpreterPython.h -------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
10 #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
11 
12 #include <string>
13 
14 #include "lldb/Host/Config.h"
15 
16 #if LLDB_ENABLE_PYTHON
17 
18 // LLDB Python header must be included first
19 #include "lldb-python.h"
20 
21 #include "lldb/lldb-forward.h"
22 #include "lldb/lldb-types.h"
23 #include "llvm/Support/Error.h"
24 
25 namespace lldb_private {
26 
27 // GetPythonValueFormatString provides a system independent type safe way to
28 // convert a variable's type into a python value format. Python value formats
29 // are defined in terms of builtin C types and could change from system to as
30 // the underlying typedef for uint* types, size_t, off_t and other values
31 // change.
32 
33 template <typename T> const char *GetPythonValueFormatString(T t);
34 template <> const char *GetPythonValueFormatString(char *);
35 template <> const char *GetPythonValueFormatString(char);
36 template <> const char *GetPythonValueFormatString(unsigned char);
37 template <> const char *GetPythonValueFormatString(short);
38 template <> const char *GetPythonValueFormatString(unsigned short);
39 template <> const char *GetPythonValueFormatString(int);
40 template <> const char *GetPythonValueFormatString(unsigned int);
41 template <> const char *GetPythonValueFormatString(long);
42 template <> const char *GetPythonValueFormatString(unsigned long);
43 template <> const char *GetPythonValueFormatString(long long);
44 template <> const char *GetPythonValueFormatString(unsigned long long);
45 template <> const char *GetPythonValueFormatString(float t);
46 template <> const char *GetPythonValueFormatString(double t);
47 
48 void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data);
49 void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data);
50 void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data);
51 void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);
52 
53 // These prototypes are the Pythonic implementations of the required callbacks.
54 // Although these are scripting-language specific, their definition depends on
55 // the public API.
56 
57 void *LLDBSwigPythonCreateScriptedProcess(const char *python_class_name,
58                                           const char *session_dictionary_name,
59                                           const lldb::TargetSP &target_sp,
60                                           const StructuredDataImpl &args_impl,
61                                           std::string &error_string);
62 
63 void *LLDBSwigPythonCreateScriptedThread(const char *python_class_name,
64                                          const char *session_dictionary_name,
65                                          const lldb::ProcessSP &process_sp,
66                                          const StructuredDataImpl &args_impl,
67                                          std::string &error_string);
68 
69 llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction(
70     const char *python_function_name, const char *session_dictionary_name,
71     const lldb::StackFrameSP &sb_frame,
72     const lldb::BreakpointLocationSP &sb_bp_loc,
73     const lldb_private::StructuredDataImpl &args_impl);
74 
75 bool LLDBSwigPythonWatchpointCallbackFunction(
76     const char *python_function_name, const char *session_dictionary_name,
77     const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp);
78 
79 bool LLDBSwigPythonCallTypeScript(const char *python_function_name,
80                                   const void *session_dictionary,
81                                   const lldb::ValueObjectSP &valobj_sp,
82                                   void **pyfunct_wrapper,
83                                   const lldb::TypeSummaryOptionsSP &options_sp,
84                                   std::string &retval);
85 
86 void *
87 LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name,
88                                       const char *session_dictionary_name,
89                                       const lldb::ValueObjectSP &valobj_sp);
90 
91 void *LLDBSwigPythonCreateCommandObject(const char *python_class_name,
92                                         const char *session_dictionary_name,
93                                         lldb::DebuggerSP debugger_sp);
94 
95 void *LLDBSwigPythonCreateScriptedThreadPlan(
96     const char *python_class_name, const char *session_dictionary_name,
97     const StructuredDataImpl &args_data, std::string &error_string,
98     const lldb::ThreadPlanSP &thread_plan_sp);
99 
100 bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name,
101                                   lldb_private::Event *event_sp,
102                                   bool &got_error);
103 
104 void *LLDBSwigPythonCreateScriptedBreakpointResolver(
105     const char *python_class_name, const char *session_dictionary_name,
106     const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp);
107 
108 unsigned int
109 LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
110                                      lldb_private::SymbolContext *sym_ctx);
111 
112 void *LLDBSwigPythonCreateScriptedStopHook(lldb::TargetSP target_sp,
113                                            const char *python_class_name,
114                                            const char *session_dictionary_name,
115                                            const StructuredDataImpl &args,
116                                            lldb_private::Status &error);
117 
118 bool LLDBSwigPythonStopHookCallHandleStop(void *implementor,
119                                           lldb::ExecutionContextRefSP exc_ctx,
120                                           lldb::StreamSP stream);
121 
122 size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max);
123 
124 PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx);
125 
126 int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
127                                            const char *child_name);
128 
129 lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data);
130 
131 bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor);
132 
133 bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance(
134     PyObject *implementor);
135 
136 PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor);
137 
138 bool LLDBSwigPythonCallCommand(const char *python_function_name,
139                                const char *session_dictionary_name,
140                                lldb::DebuggerSP debugger, const char *args,
141                                lldb_private::CommandReturnObject &cmd_retobj,
142                                lldb::ExecutionContextRefSP exe_ctx_ref_sp);
143 
144 bool LLDBSwigPythonCallCommandObject(
145     PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
146     lldb_private::CommandReturnObject &cmd_retobj,
147     lldb::ExecutionContextRefSP exe_ctx_ref_sp);
148 
149 bool LLDBSwigPythonCallModuleInit(const char *python_module_name,
150                                   const char *session_dictionary_name,
151                                   lldb::DebuggerSP debugger);
152 
153 void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
154                                    const char *session_dictionary_name,
155                                    const lldb::ProcessSP &process_sp);
156 
157 void *LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
158                                            const char *session_dictionary_name);
159 
160 PyObject *
161 LLDBSwigPython_GetRecognizedArguments(PyObject *implementor,
162                                       const lldb::StackFrameSP &frame_sp);
163 
164 bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name,
165                                            const char *session_dictionary_name,
166                                            const lldb::ProcessSP &process,
167                                            std::string &output);
168 
169 llvm::Optional<std::string>
170 LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name,
171                                      const char *session_dictionary_name,
172                                      lldb::ThreadSP thread);
173 
174 bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name,
175                                           const char *session_dictionary_name,
176                                           const lldb::TargetSP &target,
177                                           std::string &output);
178 
179 llvm::Optional<std::string>
180 LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name,
181                                     const char *session_dictionary_name,
182                                     lldb::StackFrameSP frame);
183 
184 bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name,
185                                          const char *session_dictionary_name,
186                                          const lldb::ValueObjectSP &value,
187                                          std::string &output);
188 
189 void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting,
190                                        const lldb::TargetSP &target_sp);
191 
192 } // namespace lldb_private
193 
194 #endif // LLDB_ENABLE_PYTHON
195 #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
196