[Lldb-commits] [PATCH] D115925: [lldb/python] Fix (some) dangling pointers in our glue code

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 17 02:06:29 PST 2021


labath created this revision.
labath added reviewers: JDevlieghere, mib.
labath requested review of this revision.
Herald added a project: LLDB.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115925

Files:
  lldb/bindings/python/python-swigsafecast.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/test/API/commands/command/script/TestCommandScript.py
  lldb/test/API/commands/command/script/persistence.py
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115925.395072.patch
Type: text/x-patch
Size: 19599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211217/ee4617cd/attachment-0001.bin>


More information about the lldb-commits mailing list