aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2021-11-18 08:11:34 +0100
committerPavel Labath <pavel@labath.sk>2021-12-20 09:42:08 +0100
commit7406d236d873d74b01c3cef285e5d9012dcef151 (patch)
treefc88c69eef1f20d1f776930024e22666cb3e844a /lldb/unittests/ScriptInterpreter/Python
parent3b2fd945b78454e7acacd5152b05288b526a718c (diff)
downloadllvm-7406d236d873d74b01c3cef285e5d9012dcef151.zip
llvm-7406d236d873d74b01c3cef285e5d9012dcef151.tar.gz
llvm-7406d236d873d74b01c3cef285e5d9012dcef151.tar.bz2
[lldb/python] Fix (some) dangling pointers in our glue code
This starts to fix the other half of the lifetime problems in this code -- dangling references. SB objects created on the stack will go away when the function returns, which is a problem if the python code they were meant for stashes a reference to them somewhere. Most of the time this goes by unnoticed, as the code rarely has a reason to store these, but in case it does, we shouldn't respond by crashing. This patch fixes the management for a couple of SB objects (Debugger, Frame, Thread). The SB objects are now created on the heap, and their ownership is immediately passed on to SWIG, which will ensure they are destroyed when the last python reference goes away. I will handle the other objects in separate patches. I include one test which demonstrates the lifetime issue for SBDebugger. Strictly speaking, one should create a test case for each of these objects and each of the contexts they are being used. That would require figuring out how to persist (and later access) each of these objects. Some of those may involve a lot of hoop-jumping (we can run python code from within a frame-format string). I don't think that is necessary/worth it since the new wrapper functions make it very hard to get this wrong. Differential Revision: https://reviews.llvm.org/D115925
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index c27fc03..837f6cb 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -88,7 +88,7 @@ void *lldb_private::LLDBSwigPythonCreateSyntheticProvider(
void *lldb_private::LLDBSwigPythonCreateCommandObject(
const char *python_class_name, const char *session_dictionary_name,
- const lldb::DebuggerSP debugger_sp) {
+ lldb::DebuggerSP debugger_sp) {
return nullptr;
}
@@ -172,14 +172,14 @@ PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance(
bool lldb_private::LLDBSwigPythonCallCommand(
const char *python_function_name, const char *session_dictionary_name,
- lldb::DebuggerSP &debugger, const char *args,
+ lldb::DebuggerSP debugger, const char *args,
lldb_private::CommandReturnObject &cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
return false;
}
bool lldb_private::LLDBSwigPythonCallCommandObject(
- PyObject *implementor, lldb::DebuggerSP &debugger, const char *args,
+ PyObject *implementor, lldb::DebuggerSP debugger, const char *args,
lldb_private::CommandReturnObject &cmd_retobj,
lldb::ExecutionContextRefSP exe_ctx_ref_sp) {
return false;
@@ -187,7 +187,7 @@ bool lldb_private::LLDBSwigPythonCallCommandObject(
bool lldb_private::LLDBSwigPythonCallModuleInit(
const char *python_module_name, const char *session_dictionary_name,
- lldb::DebuggerSP &debugger) {
+ lldb::DebuggerSP debugger) {
return false;
}
@@ -228,10 +228,10 @@ bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess(
return false;
}
-bool lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
+llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordThread(
const char *python_function_name, const char *session_dictionary_name,
- lldb::ThreadSP &thread, std::string &output) {
- return false;
+ lldb::ThreadSP thread) {
+ return llvm::None;
}
bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
@@ -240,10 +240,10 @@ bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget(
return false;
}
-bool lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
+llvm::Optional<std::string> lldb_private::LLDBSWIGPythonRunScriptKeywordFrame(
const char *python_function_name, const char *session_dictionary_name,
- lldb::StackFrameSP &frame, std::string &output) {
- return false;
+ lldb::StackFrameSP frame) {
+ return llvm::None;
}
bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue(