[lldb-dev] Too many ModuleSP references

Pavel Labath via lldb-dev lldb-dev at lists.llvm.org
Tue Feb 21 09:03:07 PST 2017


Hello all,

I've been debugging the newly added TestStepOverBreakpoint.py, which
has been failing on windows, for a very prosaic reason: after the test
completes, we are unable to run "make clean" because lldb still holds
the file open.

After some debugging, I've found that this happens because the test
case stores the SBBreakpoint object in a member variable of the python
test case class. The breakpoint class ends up transitively holding a
reference to the main executable module, which prevents the module
from being garbage-collected when the target is destroyed.

For reference, the full ownership chain is something like:
StepOverBreakpointTestCase(python) => SBBreakpoint => Breakpoint =>
BreakpointLocation => LLVMUserExpression => IRExecutionUnit =>
SymbolContext => Module.

To get the test working, we need to break this chain somewhere. A
couple of places I see are:
- BreakpointLocation: Remove the compiled expression reference when
the target is destroyed (AFAICS, it is used as a cache to avoid
recomputing the expression every time. It can be theoretically
recomputed if needed, but that shouldn't be necessary as the target is
destroyed anyway)

- SBBreakpoint: make SBBreakpoint hold a weak_ptr to the Breakpoint
object. When the target is destroyed, the SBBreakpoint object becomes
invalid (One doesn't cannot do anything useful with the breakpoint
once the target has been deleted anyway).

- StepOverBreakpointTestCase: Have the test not store the breakpoints
in the test case object. Basically, declare that this is not a bug,
and it's the users responsibility to clean up necessary objects.

Any thoughts on what is the appropriate solution here?

cheers,
pavel


More information about the lldb-dev mailing list