diff options
author | Pedro Tammela <pctammela@gmail.com> | 2020-11-27 22:29:56 +0000 |
---|---|---|
committer | Pedro Tammela <pctammela@gmail.com> | 2020-12-02 11:25:31 +0000 |
commit | d055e3a0eb4e957159b075c0937a960beb75c975 (patch) | |
tree | ddb7b83cf8101ac0f0fd2fc716d29040982e2535 /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | 137a25f04a515e5ea8f24c897e34b4cd236239a8 (diff) | |
download | llvm-d055e3a0eb4e957159b075c0937a960beb75c975.zip llvm-d055e3a0eb4e957159b075c0937a960beb75c975.tar.gz llvm-d055e3a0eb4e957159b075c0937a960beb75c975.tar.bz2 |
[LLDB/Python] Fix segfault on Python scripted entrypoints
The code that gets the ScriptInterpreter was not considering the
case that it receives a Lua interpreter.
Differential Revision: https://reviews.llvm.org/D92249
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index e5802ad..0d13884 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/Config.h" +#include "lldb/lldb-enumerations.h" #if LLDB_ENABLE_PYTHON @@ -214,6 +215,12 @@ extern "C" void * LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, const lldb::TargetSP &target_sp); +static ScriptInterpreterPythonImpl *GetPythonInterpreter(Debugger &debugger) { + ScriptInterpreter *script_interpreter = + debugger.GetScriptInterpreter(true, lldb::eScriptLanguagePython); + return static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); +} + static bool g_initialized = false; namespace { @@ -1825,11 +1832,10 @@ StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan( return {}; Debugger &debugger = thread_plan_sp->GetTarget().GetDebugger(); - ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); + GetPythonInterpreter(debugger); - if (!script_interpreter) + if (!python_interpreter) return {}; void *ret_val; @@ -1929,11 +1935,10 @@ ScriptInterpreterPythonImpl::CreateScriptedBreakpointResolver( return StructuredData::GenericSP(); Debugger &debugger = bkpt_sp->GetTarget().GetDebugger(); - ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); + GetPythonInterpreter(debugger); - if (!script_interpreter) + if (!python_interpreter) return StructuredData::GenericSP(); void *ret_val; @@ -2003,11 +2008,10 @@ StructuredData::GenericSP ScriptInterpreterPythonImpl::CreateScriptedStopHook( return StructuredData::GenericSP(); } - ScriptInterpreter *script_interpreter = m_debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - static_cast<ScriptInterpreterPythonImpl *>(script_interpreter); + GetPythonInterpreter(m_debugger); - if (!script_interpreter) { + if (!python_interpreter) { error.SetErrorString("No script interpreter for scripted stop-hook."); return StructuredData::GenericSP(); } @@ -2103,11 +2107,10 @@ ScriptInterpreterPythonImpl::CreateSyntheticScriptedProvider( return StructuredData::ObjectSP(); Debugger &debugger = target->GetDebugger(); - ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - (ScriptInterpreterPythonImpl *)script_interpreter; + GetPythonInterpreter(debugger); - if (!script_interpreter) + if (!python_interpreter) return StructuredData::ObjectSP(); void *ret_val = nullptr; @@ -2274,11 +2277,10 @@ bool ScriptInterpreterPythonImpl::BreakpointCallbackFunction( return true; Debugger &debugger = target->GetDebugger(); - ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - (ScriptInterpreterPythonImpl *)script_interpreter; + GetPythonInterpreter(debugger); - if (!script_interpreter) + if (!python_interpreter) return true; if (python_function_name && python_function_name[0]) { @@ -2340,11 +2342,10 @@ bool ScriptInterpreterPythonImpl::WatchpointCallbackFunction( return true; Debugger &debugger = target->GetDebugger(); - ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); ScriptInterpreterPythonImpl *python_interpreter = - (ScriptInterpreterPythonImpl *)script_interpreter; + GetPythonInterpreter(debugger); - if (!script_interpreter) + if (!python_interpreter) return true; if (python_function_name && python_function_name[0]) { |