[lldb] Add SBModule::GarbageCollectAllocatedModules and clear modules after each...
authorRaphael Isemann <teemperor@gmail.com>
Mon, 17 Aug 2020 08:56:02 +0000 (10:56 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Mon, 17 Aug 2020 09:00:19 +0000 (11:00 +0200)
commitc2f9454a16e45e1df09d8ebed6dadbc0da264442
tree88b80395d987d0dfb40616e2a42adfc0b83f0946
parent867c347c32e27825a649af1ca5ccf22c350d2b8c
[lldb] Add SBModule::GarbageCollectAllocatedModules and clear modules after each test run

Right now the only places in the SB API where lldb:: ModuleSP instances are
destroyed are in SBDebugger::MemoryPressureDetected (where it's just attempted
but not guaranteed) and in SBDebugger::DeleteTarget (which will be removed in
D83933). Tests that directly create an lldb::ModuleSP and never create a target
therefore currently leak lldb::Module instances. This triggers the sanity checks
in lldbtest that make sure that the global module list is empty after a test.

This patch adds SBModule::GarbageCollectAllocatedModules as an explicit way to
clean orphaned lldb::ModuleSP instances. Also we now start calling this method
at the end of each test run and move the sanity check behind that call to make
this work. This way even tests that don't create targets can pass the sanity
check.

This fixes TestUnicodeSymbols.py when D83865 is applied (which makes that the
sanity checks actually fail the test).

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D83876
lldb/bindings/interface/SBModule.i
lldb/include/lldb/API/SBModule.h
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/source/API/SBModule.cpp