Skip to content

Commit a2727a2

Browse files
committed
Merge commit '5009d66cabff' from apple/stable/20200714 into swift/main
Conflicts: lldb/packages/Python/lldbsuite/test/lldbtest.py
2 parents ed468a3 + 5009d66 commit a2727a2

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

lldb/bindings/interface/SBModule.i

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ public:
356356
static uint32_t
357357
GetNumberAllocatedModules();
358358

359+
%feature("docstring", "
360+
Removes all modules which are no longer needed by any part of LLDB from
361+
the module cache.
362+
363+
This is an implementation detail exposed for testing and should not be
364+
relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce
365+
LLDB's memory consumption during execution.
366+
") GarbageCollectAllocatedModules;
367+
static void
368+
GarbageCollectAllocatedModules();
369+
359370
STRING_EXTENSION(SBModule)
360371

361372
#ifdef SWIGPYTHON

lldb/include/lldb/API/SBModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ class LLDB_API SBModule {
293293
/// Get the number of global modules.
294294
static uint32_t GetNumberAllocatedModules();
295295

296+
/// Remove any global modules which are no longer needed.
297+
static void GarbageCollectAllocatedModules();
298+
296299
private:
297300
friend class SBAddress;
298301
friend class SBFrame;

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,17 @@ def tearDown(self):
10291029
lldb.SBDebugger.Destroy(self.dbg)
10301030
del self.dbg
10311031

1032+
# All modules should be orphaned now so that they can be cleared from
1033+
# the shared module cache.
1034+
lldb.SBModule.GarbageCollectAllocatedModules()
1035+
1036+
# Modules are not orphaned during reproducer replay because they're
1037+
# leaked on purpose.
1038+
if not configuration.is_reproducer():
1039+
# Assert that the global module cache is empty.
1040+
# (rdar://problem/64424164) self.assertEqual(lldb.SBModule.GetNumberAllocatedModules(), 0)
1041+
1042+
10321043
# =========================================================
10331044
# Various callbacks to allow introspection of test progress
10341045
# =========================================================
@@ -1989,13 +2000,9 @@ def tearDown(self):
19892000
for target in targets:
19902001
self.dbg.DeleteTarget(target)
19912002

1992-
# Modules are not orphaned during reproducer replay because they're
1993-
# leaked on purpose.
19942003
if not configuration.is_reproducer():
19952004
# Assert that all targets are deleted.
1996-
assert self.dbg.GetNumTargets() == 0
1997-
# Assert that the global module cache is empty.
1998-
# (rdar://problem/64424164) assert lldb.SBModule.GetNumberAllocatedModules() == 0
2005+
self.assertEqual(self.dbg.GetNumTargets(), 0)
19992006

20002007
# Do this last, to make sure it's in reverse order from how we setup.
20012008
Base.tearDown(self)

lldb/source/API/SBModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,13 @@ uint32_t SBModule::GetNumberAllocatedModules() {
714714
return Module::GetNumberAllocatedModules();
715715
}
716716

717+
void SBModule::GarbageCollectAllocatedModules() {
718+
LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBModule,
719+
GarbageCollectAllocatedModules);
720+
const bool mandatory = false;
721+
ModuleList::RemoveOrphanSharedModules(mandatory);
722+
}
723+
717724
namespace lldb_private {
718725
namespace repro {
719726

0 commit comments

Comments
 (0)