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 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 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 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 const lldb::DebuggerSP debugger_sp); 94 95 void *LLDBSwigPythonCreateScriptedThreadPlan( 96 const char *python_class_name, const char *session_dictionary_name, 97 lldb_private::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 lldb_private::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( 113 lldb::TargetSP target_sp, const char *python_class_name, 114 const char *session_dictionary_name, lldb_private::StructuredDataImpl *args, 115 lldb_private::Status &error); 116 117 bool LLDBSwigPythonStopHookCallHandleStop(void *implementor, 118 lldb::ExecutionContextRefSP exc_ctx, 119 lldb::StreamSP stream); 120 121 size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max); 122 123 PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx); 124 125 int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor, 126 const char *child_name); 127 128 lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data); 129 130 bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor); 131 132 bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 133 PyObject *implementor); 134 135 PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor); 136 137 bool LLDBSwigPythonCallCommand(const char *python_function_name, 138 const char *session_dictionary_name, 139 lldb::DebuggerSP &debugger, const char *args, 140 lldb_private::CommandReturnObject &cmd_retobj, 141 lldb::ExecutionContextRefSP exe_ctx_ref_sp); 142 143 bool LLDBSwigPythonCallCommandObject( 144 PyObject *implementor, lldb::DebuggerSP &debugger, const char *args, 145 lldb_private::CommandReturnObject &cmd_retobj, 146 lldb::ExecutionContextRefSP exe_ctx_ref_sp); 147 148 bool LLDBSwigPythonCallModuleInit(const char *python_module_name, 149 const char *session_dictionary_name, 150 lldb::DebuggerSP &debugger); 151 152 void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 153 const char *session_dictionary_name, 154 const lldb::ProcessSP &process_sp); 155 156 void *LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, 157 const char *session_dictionary_name); 158 159 PyObject * 160 LLDBSwigPython_GetRecognizedArguments(PyObject *implementor, 161 const lldb::StackFrameSP &frame_sp); 162 163 bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name, 164 const char *session_dictionary_name, 165 const lldb::ProcessSP &process, 166 std::string &output); 167 168 bool LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name, 169 const char *session_dictionary_name, 170 lldb::ThreadSP &thread, 171 std::string &output); 172 173 bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name, 174 const char *session_dictionary_name, 175 const lldb::TargetSP &target, 176 std::string &output); 177 178 bool LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name, 179 const char *session_dictionary_name, 180 lldb::StackFrameSP &frame, 181 std::string &output); 182 183 bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name, 184 const char *session_dictionary_name, 185 const lldb::ValueObjectSP &value, 186 std::string &output); 187 188 void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, 189 const lldb::TargetSP &target_sp); 190 191 } // namespace lldb_private 192 193 #endif // LLDB_ENABLE_PYTHON 194 #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H 195