11f6a57c1SMed Ismail Bennani //===-- ScriptInterpreterPython.h -------------------------------*- C++ -*-===// 21f6a57c1SMed Ismail Bennani // 31f6a57c1SMed Ismail Bennani // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41f6a57c1SMed Ismail Bennani // See https://llvm.org/LICENSE.txt for license information. 51f6a57c1SMed Ismail Bennani // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61f6a57c1SMed Ismail Bennani // 71f6a57c1SMed Ismail Bennani //===----------------------------------------------------------------------===// 81f6a57c1SMed Ismail Bennani 91f6a57c1SMed Ismail Bennani #ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H 101f6a57c1SMed Ismail Bennani #define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H 111f6a57c1SMed Ismail Bennani 121f6a57c1SMed Ismail Bennani #include <string> 131f6a57c1SMed Ismail Bennani 141f6a57c1SMed Ismail Bennani #include "lldb/Host/Config.h" 151f6a57c1SMed Ismail Bennani 161f6a57c1SMed Ismail Bennani #if LLDB_ENABLE_PYTHON 171f6a57c1SMed Ismail Bennani 189a14adeaSPavel Labath // LLDB Python header must be included first 199a14adeaSPavel Labath #include "lldb-python.h" 209a14adeaSPavel Labath 21*c154f397SPavel Labath #include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h" 221f6a57c1SMed Ismail Bennani #include "lldb/lldb-forward.h" 231f6a57c1SMed Ismail Bennani #include "lldb/lldb-types.h" 249a14adeaSPavel Labath #include "llvm/Support/Error.h" 251f6a57c1SMed Ismail Bennani 261f6a57c1SMed Ismail Bennani namespace lldb_private { 271f6a57c1SMed Ismail Bennani 281f6a57c1SMed Ismail Bennani // GetPythonValueFormatString provides a system independent type safe way to 291f6a57c1SMed Ismail Bennani // convert a variable's type into a python value format. Python value formats 301f6a57c1SMed Ismail Bennani // are defined in terms of builtin C types and could change from system to as 311f6a57c1SMed Ismail Bennani // the underlying typedef for uint* types, size_t, off_t and other values 321f6a57c1SMed Ismail Bennani // change. 331f6a57c1SMed Ismail Bennani 341f6a57c1SMed Ismail Bennani template <typename T> const char *GetPythonValueFormatString(T t); 351f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(char *); 361f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(char); 371f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(unsigned char); 381f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(short); 391f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(unsigned short); 401f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(int); 411f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(unsigned int); 421f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(long); 431f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(unsigned long); 441f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(long long); 451f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(unsigned long long); 461f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(float t); 471f6a57c1SMed Ismail Bennani template <> const char *GetPythonValueFormatString(double t); 481f6a57c1SMed Ismail Bennani 499a14adeaSPavel Labath void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data); 509a14adeaSPavel Labath void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data); 519a14adeaSPavel Labath void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data); 529a14adeaSPavel Labath void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data); 539a14adeaSPavel Labath 549a14adeaSPavel Labath // These prototypes are the Pythonic implementations of the required callbacks. 559a14adeaSPavel Labath // Although these are scripting-language specific, their definition depends on 569a14adeaSPavel Labath // the public API. 579a14adeaSPavel Labath 58*c154f397SPavel Labath python::PythonObject LLDBSwigPythonCreateScriptedProcess( 59*c154f397SPavel Labath const char *python_class_name, const char *session_dictionary_name, 60*c154f397SPavel Labath const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl, 611f6a57c1SMed Ismail Bennani std::string &error_string); 621f6a57c1SMed Ismail Bennani 63*c154f397SPavel Labath python::PythonObject LLDBSwigPythonCreateScriptedThread( 64*c154f397SPavel Labath const char *python_class_name, const char *session_dictionary_name, 65*c154f397SPavel Labath const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl, 66738621d0SMed Ismail Bennani std::string &error_string); 6759d8dd79SMed Ismail Bennani 689a14adeaSPavel Labath llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( 699a14adeaSPavel Labath const char *python_function_name, const char *session_dictionary_name, 709a14adeaSPavel Labath const lldb::StackFrameSP &sb_frame, 719a14adeaSPavel Labath const lldb::BreakpointLocationSP &sb_bp_loc, 7282de8df2SPavel Labath const lldb_private::StructuredDataImpl &args_impl); 739a14adeaSPavel Labath 749a14adeaSPavel Labath bool LLDBSwigPythonWatchpointCallbackFunction( 759a14adeaSPavel Labath const char *python_function_name, const char *session_dictionary_name, 769a14adeaSPavel Labath const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp); 779a14adeaSPavel Labath 789a14adeaSPavel Labath bool LLDBSwigPythonCallTypeScript(const char *python_function_name, 799a14adeaSPavel Labath const void *session_dictionary, 809a14adeaSPavel Labath const lldb::ValueObjectSP &valobj_sp, 819a14adeaSPavel Labath void **pyfunct_wrapper, 829a14adeaSPavel Labath const lldb::TypeSummaryOptionsSP &options_sp, 839a14adeaSPavel Labath std::string &retval); 849a14adeaSPavel Labath 85*c154f397SPavel Labath python::PythonObject 869a14adeaSPavel Labath LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, 879a14adeaSPavel Labath const char *session_dictionary_name, 889a14adeaSPavel Labath const lldb::ValueObjectSP &valobj_sp); 899a14adeaSPavel Labath 90*c154f397SPavel Labath python::PythonObject 91*c154f397SPavel Labath LLDBSwigPythonCreateCommandObject(const char *python_class_name, 929a14adeaSPavel Labath const char *session_dictionary_name, 937406d236SPavel Labath lldb::DebuggerSP debugger_sp); 949a14adeaSPavel Labath 95*c154f397SPavel Labath python::PythonObject LLDBSwigPythonCreateScriptedThreadPlan( 969a14adeaSPavel Labath const char *python_class_name, const char *session_dictionary_name, 9782de8df2SPavel Labath const StructuredDataImpl &args_data, std::string &error_string, 989a14adeaSPavel Labath const lldb::ThreadPlanSP &thread_plan_sp); 999a14adeaSPavel Labath 1009a14adeaSPavel Labath bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name, 1019a14adeaSPavel Labath lldb_private::Event *event_sp, 1029a14adeaSPavel Labath bool &got_error); 1039a14adeaSPavel Labath 104*c154f397SPavel Labath python::PythonObject LLDBSwigPythonCreateScriptedBreakpointResolver( 1059a14adeaSPavel Labath const char *python_class_name, const char *session_dictionary_name, 10682de8df2SPavel Labath const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp); 1079a14adeaSPavel Labath 1089a14adeaSPavel Labath unsigned int 1099a14adeaSPavel Labath LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, 1109a14adeaSPavel Labath lldb_private::SymbolContext *sym_ctx); 1119a14adeaSPavel Labath 112*c154f397SPavel Labath python::PythonObject LLDBSwigPythonCreateScriptedStopHook( 113*c154f397SPavel Labath lldb::TargetSP target_sp, const char *python_class_name, 114*c154f397SPavel Labath const char *session_dictionary_name, const StructuredDataImpl &args, 1159a14adeaSPavel Labath lldb_private::Status &error); 1169a14adeaSPavel Labath 1179a14adeaSPavel Labath bool LLDBSwigPythonStopHookCallHandleStop(void *implementor, 1189a14adeaSPavel Labath lldb::ExecutionContextRefSP exc_ctx, 1199a14adeaSPavel Labath lldb::StreamSP stream); 1209a14adeaSPavel Labath 1219a14adeaSPavel Labath size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max); 1229a14adeaSPavel Labath 1239a14adeaSPavel Labath PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx); 1249a14adeaSPavel Labath 1259a14adeaSPavel Labath int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor, 1269a14adeaSPavel Labath const char *child_name); 1279a14adeaSPavel Labath 1289a14adeaSPavel Labath lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data); 1299a14adeaSPavel Labath 1309a14adeaSPavel Labath bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor); 1319a14adeaSPavel Labath 1329a14adeaSPavel Labath bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance( 1339a14adeaSPavel Labath PyObject *implementor); 1349a14adeaSPavel Labath 1359a14adeaSPavel Labath PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor); 1369a14adeaSPavel Labath 1379a14adeaSPavel Labath bool LLDBSwigPythonCallCommand(const char *python_function_name, 1389a14adeaSPavel Labath const char *session_dictionary_name, 1397406d236SPavel Labath lldb::DebuggerSP debugger, const char *args, 1409a14adeaSPavel Labath lldb_private::CommandReturnObject &cmd_retobj, 1419a14adeaSPavel Labath lldb::ExecutionContextRefSP exe_ctx_ref_sp); 1429a14adeaSPavel Labath 1439a14adeaSPavel Labath bool LLDBSwigPythonCallCommandObject( 1447406d236SPavel Labath PyObject *implementor, lldb::DebuggerSP debugger, const char *args, 1459a14adeaSPavel Labath lldb_private::CommandReturnObject &cmd_retobj, 1469a14adeaSPavel Labath lldb::ExecutionContextRefSP exe_ctx_ref_sp); 1479a14adeaSPavel Labath 1489a14adeaSPavel Labath bool LLDBSwigPythonCallModuleInit(const char *python_module_name, 1499a14adeaSPavel Labath const char *session_dictionary_name, 1507406d236SPavel Labath lldb::DebuggerSP debugger); 1519a14adeaSPavel Labath 152*c154f397SPavel Labath python::PythonObject 153*c154f397SPavel Labath LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, 1549a14adeaSPavel Labath const char *session_dictionary_name, 1559a14adeaSPavel Labath const lldb::ProcessSP &process_sp); 1569a14adeaSPavel Labath 157*c154f397SPavel Labath python::PythonObject 158*c154f397SPavel Labath LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, 1599a14adeaSPavel Labath const char *session_dictionary_name); 1609a14adeaSPavel Labath 1619a14adeaSPavel Labath PyObject * 1629a14adeaSPavel Labath LLDBSwigPython_GetRecognizedArguments(PyObject *implementor, 1639a14adeaSPavel Labath const lldb::StackFrameSP &frame_sp); 1649a14adeaSPavel Labath 1659a14adeaSPavel Labath bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name, 1669a14adeaSPavel Labath const char *session_dictionary_name, 1679a14adeaSPavel Labath const lldb::ProcessSP &process, 1689a14adeaSPavel Labath std::string &output); 1699a14adeaSPavel Labath 1707406d236SPavel Labath llvm::Optional<std::string> 1717406d236SPavel Labath LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name, 1729a14adeaSPavel Labath const char *session_dictionary_name, 1737406d236SPavel Labath lldb::ThreadSP thread); 1749a14adeaSPavel Labath 1759a14adeaSPavel Labath bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name, 1769a14adeaSPavel Labath const char *session_dictionary_name, 1779a14adeaSPavel Labath const lldb::TargetSP &target, 1789a14adeaSPavel Labath std::string &output); 1799a14adeaSPavel Labath 1807406d236SPavel Labath llvm::Optional<std::string> 1817406d236SPavel Labath LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name, 1829a14adeaSPavel Labath const char *session_dictionary_name, 1837406d236SPavel Labath lldb::StackFrameSP frame); 1849a14adeaSPavel Labath 1859a14adeaSPavel Labath bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name, 1869a14adeaSPavel Labath const char *session_dictionary_name, 1879a14adeaSPavel Labath const lldb::ValueObjectSP &value, 1889a14adeaSPavel Labath std::string &output); 1899a14adeaSPavel Labath 1909a14adeaSPavel Labath void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, 1919a14adeaSPavel Labath const lldb::TargetSP &target_sp); 1921f6a57c1SMed Ismail Bennani 193ec00502bSShafik Yaghmour } // namespace lldb_private 1941f6a57c1SMed Ismail Bennani 1951f6a57c1SMed Ismail Bennani #endif // LLDB_ENABLE_PYTHON 1961f6a57c1SMed Ismail Bennani #endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H 197