diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-12-02 21:49:08 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:49 +0000 |
commit | 4824e7fd18a1223177218d4aec1b3c6c5c4a444e (patch) | |
tree | 5ca6493b1b0bf6a41f257794c0116d5e50fbf37c /contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python | |
parent | 5e801ac66d24704442eba426ed13c3effb8a34e7 (diff) | |
parent | f65dcba83ce5035ab88a85fe17628b447eb56e1b (diff) |
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python')
2 files changed, 160 insertions, 175 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h index 798d947a0a7d..c7af13598843 100644 --- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h +++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h @@ -15,8 +15,12 @@ #if LLDB_ENABLE_PYTHON +// LLDB Python header must be included first +#include "lldb-python.h" + #include "lldb/lldb-forward.h" #include "lldb/lldb-types.h" +#include "llvm/Support/Error.h" namespace lldb_private { @@ -41,20 +45,148 @@ template <> const char *GetPythonValueFormatString(unsigned long long); template <> const char *GetPythonValueFormatString(float t); template <> const char *GetPythonValueFormatString(double t); -extern "C" void *LLDBSwigPythonCreateScriptedProcess( +void *LLDBSWIGPython_CastPyObjectToSBData(PyObject *data); +void *LLDBSWIGPython_CastPyObjectToSBError(PyObject *data); +void *LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data); +void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data); + +// These prototypes are the Pythonic implementations of the required callbacks. +// Although these are scripting-language specific, their definition depends on +// the public API. + +void *LLDBSwigPythonCreateScriptedProcess(const char *python_class_name, + const char *session_dictionary_name, + const lldb::TargetSP &target_sp, + StructuredDataImpl *args_impl, + std::string &error_string); + +void *LLDBSwigPythonCreateScriptedThread(const char *python_class_name, + const char *session_dictionary_name, + const lldb::ProcessSP &process_sp, + StructuredDataImpl *args_impl, + std::string &error_string); + +llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( + const char *python_function_name, const char *session_dictionary_name, + const lldb::StackFrameSP &sb_frame, + const lldb::BreakpointLocationSP &sb_bp_loc, + lldb_private::StructuredDataImpl *args_impl); + +bool LLDBSwigPythonWatchpointCallbackFunction( + const char *python_function_name, const char *session_dictionary_name, + const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp); + +bool LLDBSwigPythonCallTypeScript(const char *python_function_name, + const void *session_dictionary, + const lldb::ValueObjectSP &valobj_sp, + void **pyfunct_wrapper, + const lldb::TypeSummaryOptionsSP &options_sp, + std::string &retval); + +void * +LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, + const char *session_dictionary_name, + const lldb::ValueObjectSP &valobj_sp); + +void *LLDBSwigPythonCreateCommandObject(const char *python_class_name, + const char *session_dictionary_name, + const lldb::DebuggerSP debugger_sp); + +void *LLDBSwigPythonCreateScriptedThreadPlan( const char *python_class_name, const char *session_dictionary_name, - const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl, - std::string &error_string); + lldb_private::StructuredDataImpl *args_data, std::string &error_string, + const lldb::ThreadPlanSP &thread_plan_sp); -extern "C" void *LLDBSwigPythonCreateScriptedThread( +bool LLDBSWIGPythonCallThreadPlan(void *implementor, const char *method_name, + lldb_private::Event *event_sp, + bool &got_error); + +void *LLDBSwigPythonCreateScriptedBreakpointResolver( const char *python_class_name, const char *session_dictionary_name, - const lldb::ProcessSP &process_sp, StructuredDataImpl *args_impl, - std::string &error_string); + lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp); + +unsigned int +LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, + lldb_private::SymbolContext *sym_ctx); + +void *LLDBSwigPythonCreateScriptedStopHook( + lldb::TargetSP target_sp, const char *python_class_name, + const char *session_dictionary_name, lldb_private::StructuredDataImpl *args, + lldb_private::Status &error); + +bool LLDBSwigPythonStopHookCallHandleStop(void *implementor, + lldb::ExecutionContextRefSP exc_ctx, + lldb::StreamSP stream); + +size_t LLDBSwigPython_CalculateNumChildren(PyObject *implementor, uint32_t max); + +PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor, uint32_t idx); + +int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor, + const char *child_name); + +lldb::ValueObjectSP LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data); + +bool LLDBSwigPython_UpdateSynthProviderInstance(PyObject *implementor); + +bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance( + PyObject *implementor); + +PyObject *LLDBSwigPython_GetValueSynthProviderInstance(PyObject *implementor); + +bool LLDBSwigPythonCallCommand(const char *python_function_name, + const char *session_dictionary_name, + lldb::DebuggerSP &debugger, const char *args, + lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp); + +bool LLDBSwigPythonCallCommandObject( + PyObject *implementor, lldb::DebuggerSP &debugger, const char *args, + lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp); + +bool LLDBSwigPythonCallModuleInit(const char *python_module_name, + const char *session_dictionary_name, + lldb::DebuggerSP &debugger); + +void *LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, + const char *session_dictionary_name, + const lldb::ProcessSP &process_sp); + +void *LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, + const char *session_dictionary_name); + +PyObject * +LLDBSwigPython_GetRecognizedArguments(PyObject *implementor, + const lldb::StackFrameSP &frame_sp); + +bool LLDBSWIGPythonRunScriptKeywordProcess(const char *python_function_name, + const char *session_dictionary_name, + const lldb::ProcessSP &process, + std::string &output); + +bool LLDBSWIGPythonRunScriptKeywordThread(const char *python_function_name, + const char *session_dictionary_name, + lldb::ThreadSP &thread, + std::string &output); + +bool LLDBSWIGPythonRunScriptKeywordTarget(const char *python_function_name, + const char *session_dictionary_name, + const lldb::TargetSP &target, + std::string &output); + +bool LLDBSWIGPythonRunScriptKeywordFrame(const char *python_function_name, + const char *session_dictionary_name, + lldb::StackFrameSP &frame, + std::string &output); + +bool LLDBSWIGPythonRunScriptKeywordValue(const char *python_function_name, + const char *session_dictionary_name, + const lldb::ValueObjectSP &value, + std::string &output); -extern "C" void *LLDBSWIGPython_CastPyObjectToSBData(void *data); -extern "C" void *LLDBSWIGPython_CastPyObjectToSBError(void *data); -extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data); -extern "C" void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(void *data); +void *LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, + const lldb::TargetSP &target_sp); } // namespace lldb_private diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index c1f4c2d3b4d3..5f282d74e364 100644 --- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -70,153 +70,6 @@ extern "C" void init_lldb(void); #define LLDBSwigPyInit init_lldb #endif -// These prototypes are the Pythonic implementations of the required callbacks. -// Although these are scripting-language specific, their definition depends on -// the public API. - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" - -// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has -// C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is -// incompatible with C -#if _MSC_VER -#pragma warning (push) -#pragma warning (disable : 4190) -#endif - -extern "C" llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( - const char *python_function_name, const char *session_dictionary_name, - const lldb::StackFrameSP &sb_frame, - const lldb::BreakpointLocationSP &sb_bp_loc, StructuredDataImpl *args_impl); - -#if _MSC_VER -#pragma warning (pop) -#endif - -#pragma clang diagnostic pop - -extern "C" bool LLDBSwigPythonWatchpointCallbackFunction( - const char *python_function_name, const char *session_dictionary_name, - const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp); - -extern "C" bool LLDBSwigPythonCallTypeScript( - const char *python_function_name, void *session_dictionary, - const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, - const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval); - -extern "C" void * -LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, - const char *session_dictionary_name, - const lldb::ValueObjectSP &valobj_sp); - -extern "C" void * -LLDBSwigPythonCreateCommandObject(const char *python_class_name, - const char *session_dictionary_name, - const lldb::DebuggerSP debugger_sp); - -extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( - const char *python_class_name, const char *session_dictionary_name, - StructuredDataImpl *args_data, - std::string &error_string, - const lldb::ThreadPlanSP &thread_plan_sp); - -extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, - const char *method_name, - Event *event_sp, bool &got_error); - -extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver( - const char *python_class_name, const char *session_dictionary_name, - lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp); - -extern "C" unsigned int -LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, - lldb_private::SymbolContext *sym_ctx); - -extern "C" void *LLDBSwigPythonCreateScriptedStopHook( - TargetSP target_sp, const char *python_class_name, - const char *session_dictionary_name, lldb_private::StructuredDataImpl *args, - lldb_private::Status &error); - -extern "C" bool -LLDBSwigPythonStopHookCallHandleStop(void *implementor, - lldb::ExecutionContextRefSP exc_ctx, - lldb::StreamSP stream); - -extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor, - uint32_t max); - -extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor, - uint32_t idx); - -extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor, - const char *child_name); - -extern lldb::ValueObjectSP -LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data); - -extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor); - -extern "C" bool -LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor); - -extern "C" void * -LLDBSwigPython_GetValueSynthProviderInstance(void *implementor); - -extern "C" bool -LLDBSwigPythonCallCommand(const char *python_function_name, - const char *session_dictionary_name, - lldb::DebuggerSP &debugger, const char *args, - lldb_private::CommandReturnObject &cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp); - -extern "C" bool -LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger, - const char *args, - lldb_private::CommandReturnObject &cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp); - -extern "C" bool -LLDBSwigPythonCallModuleInit(const char *python_module_name, - const char *session_dictionary_name, - lldb::DebuggerSP &debugger); - -extern "C" void * -LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, - const char *session_dictionary_name, - const lldb::ProcessSP &process_sp); - -extern "C" void * -LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, - const char *session_dictionary_name); - -extern "C" void * -LLDBSwigPython_GetRecognizedArguments(void *implementor, - const lldb::StackFrameSP &frame_sp); - -extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess( - const char *python_function_name, const char *session_dictionary_name, - lldb::ProcessSP &process, std::string &output); - -extern "C" bool LLDBSWIGPythonRunScriptKeywordThread( - const char *python_function_name, const char *session_dictionary_name, - lldb::ThreadSP &thread, std::string &output); - -extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget( - const char *python_function_name, const char *session_dictionary_name, - lldb::TargetSP &target, std::string &output); - -extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame( - const char *python_function_name, const char *session_dictionary_name, - lldb::StackFrameSP &frame, std::string &output); - -extern "C" bool LLDBSWIGPythonRunScriptKeywordValue( - const char *python_function_name, const char *session_dictionary_name, - lldb::ValueObjectSP &value, std::string &output); - -extern "C" void * -LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, - const lldb::TargetSP &target_sp); static ScriptInterpreterPythonImpl *GetPythonInterpreter(Debugger &debugger) { ScriptInterpreter *script_interpreter = @@ -1591,9 +1444,9 @@ lldb::ValueObjectListSP ScriptInterpreterPythonImpl::GetRecognizedArguments( if (!implementor.IsAllocated()) return ValueObjectListSP(); - PythonObject py_return(PyRefType::Owned, - (PyObject *)LLDBSwigPython_GetRecognizedArguments( - implementor.get(), frame_sp)); + PythonObject py_return( + PyRefType::Owned, + LLDBSwigPython_GetRecognizedArguments(implementor.get(), frame_sp)); // if it fails, print the error but otherwise go on if (PyErr_Occurred()) { @@ -2423,7 +2276,7 @@ size_t ScriptInterpreterPythonImpl::CalculateNumChildren( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return 0; - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return 0; @@ -2446,7 +2299,7 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return lldb::ValueObjectSP(); - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return lldb::ValueObjectSP(); @@ -2454,7 +2307,7 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex( { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - void *child_ptr = LLDBSwigPython_GetChildAtIndex(implementor, idx); + PyObject *child_ptr = LLDBSwigPython_GetChildAtIndex(implementor, idx); if (child_ptr != nullptr && child_ptr != Py_None) { lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); @@ -2478,7 +2331,7 @@ int ScriptInterpreterPythonImpl::GetIndexOfChildWithName( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return UINT32_MAX; - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return UINT32_MAX; @@ -2503,7 +2356,7 @@ bool ScriptInterpreterPythonImpl::UpdateSynthProviderInstance( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return ret_val; - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return ret_val; @@ -2526,7 +2379,7 @@ bool ScriptInterpreterPythonImpl::MightHaveChildrenSynthProviderInstance( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return ret_val; - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return ret_val; @@ -2550,14 +2403,15 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetSyntheticValue( StructuredData::Generic *generic = implementor_sp->GetAsGeneric(); if (!generic) return ret_val; - void *implementor = generic->GetValue(); + auto *implementor = static_cast<PyObject *>(generic->GetValue()); if (!implementor) return ret_val; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - void *child_ptr = LLDBSwigPython_GetValueSynthProviderInstance(implementor); + PyObject *child_ptr = + LLDBSwigPython_GetValueSynthProviderInstance(implementor); if (child_ptr != nullptr && child_ptr != Py_None) { lldb::SBValue *sb_value_ptr = (lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(child_ptr); @@ -2653,11 +2507,11 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( } { - ProcessSP process_sp(process->shared_from_this()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); ret_val = LLDBSWIGPythonRunScriptKeywordProcess( - impl_function, m_dictionary_name.c_str(), process_sp, output); + impl_function, m_dictionary_name.c_str(), process->shared_from_this(), + output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -2753,11 +2607,10 @@ bool ScriptInterpreterPythonImpl::RunScriptFormatKeyword( } { - ValueObjectSP value_sp(value->GetSP()); Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); ret_val = LLDBSWIGPythonRunScriptKeywordValue( - impl_function, m_dictionary_name.c_str(), value_sp, output); + impl_function, m_dictionary_name.c_str(), value->GetSP(), output); if (!ret_val) error.SetErrorString("python script evaluation failed"); } @@ -3076,9 +2929,9 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedCommand( SynchronicityHandler synch_handler(debugger_sp, synchronicity); std::string args_str = args.str(); - ret_val = LLDBSwigPythonCallCommandObject(impl_obj_sp->GetValue(), - debugger_sp, args_str.c_str(), - cmd_retobj, exe_ctx_ref_sp); + ret_val = LLDBSwigPythonCallCommandObject( + static_cast<PyObject *>(impl_obj_sp->GetValue()), debugger_sp, + args_str.c_str(), cmd_retobj, exe_ctx_ref_sp); } if (!ret_val) |