Skip to content

Commit 812fd46

Browse files
author
git apple-llvm automerger
committed
Merge commit '5009d66cabff' from apple/stable/20200714 into swift/main
2 parents dee9c92 + 40f9432 commit 812fd46

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-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/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40700,6 +40700,22 @@ SWIGINTERN PyObject *_wrap_SBModule_GetNumberAllocatedModules(PyObject *SWIGUNUS
4070040700
}
4070140701

4070240702

40703+
SWIGINTERN PyObject *_wrap_SBModule_GarbageCollectAllocatedModules(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
40704+
PyObject *resultobj = 0;
40705+
40706+
if (!SWIG_Python_UnpackTuple(args, "SBModule_GarbageCollectAllocatedModules", 0, 0, 0)) SWIG_fail;
40707+
{
40708+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
40709+
lldb::SBModule::GarbageCollectAllocatedModules();
40710+
SWIG_PYTHON_THREAD_END_ALLOW;
40711+
}
40712+
resultobj = SWIG_Py_Void();
40713+
return resultobj;
40714+
fail:
40715+
return NULL;
40716+
}
40717+
40718+
4070340719
SWIGINTERN PyObject *_wrap_SBModule___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
4070440720
PyObject *resultobj = 0;
4070540721
lldb::SBModule *arg1 = (lldb::SBModule *) 0 ;
@@ -82548,6 +82564,17 @@ static PyMethodDef SwigMethods[] = {
8254882564
" @return\n"
8254982565
" The number of modules in the module cache.\n"
8255082566
""},
82567+
{ "SBModule_GarbageCollectAllocatedModules", _wrap_SBModule_GarbageCollectAllocatedModules, METH_NOARGS, "\n"
82568+
"SBModule_GarbageCollectAllocatedModules()\n"
82569+
"\n"
82570+
" Removes all modules which are no longer needed by any part of LLDB from\n"
82571+
" the module cache.\n"
82572+
"\n"
82573+
" This is an implementation detail exposed for testing and should not be\n"
82574+
" relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce\n"
82575+
" LLDB's memory consumption during execution.\n"
82576+
"\n"
82577+
""},
8255182578
{ "SBModule___str__", _wrap_SBModule___str__, METH_O, "SBModule___str__(SBModule self) -> std::string"},
8255282579
{ "SBModule_swigregister", SBModule_swigregister, METH_O, NULL},
8255382580
{ "SBModule_swiginit", SBModule_swiginit, METH_VARARGS, NULL},

lldb/bindings/python/static-binding/lldb.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7484,6 +7484,21 @@ def GetNumberAllocatedModules():
74847484
"""
74857485
return _lldb.SBModule_GetNumberAllocatedModules()
74867486

7487+
@staticmethod
7488+
def GarbageCollectAllocatedModules():
7489+
r"""
7490+
GarbageCollectAllocatedModules()
7491+
7492+
Removes all modules which are no longer needed by any part of LLDB from
7493+
the module cache.
7494+
7495+
This is an implementation detail exposed for testing and should not be
7496+
relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce
7497+
LLDB's memory consumption during execution.
7498+
7499+
"""
7500+
return _lldb.SBModule_GarbageCollectAllocatedModules()
7501+
74877502
def __str__(self):
74887503
r"""__str__(SBModule self) -> std::string"""
74897504
return _lldb.SBModule___str__(self)
@@ -7716,6 +7731,20 @@ def SBModule_GetNumberAllocatedModules():
77167731
"""
77177732
return _lldb.SBModule_GetNumberAllocatedModules()
77187733

7734+
def SBModule_GarbageCollectAllocatedModules():
7735+
r"""
7736+
SBModule_GarbageCollectAllocatedModules()
7737+
7738+
Removes all modules which are no longer needed by any part of LLDB from
7739+
the module cache.
7740+
7741+
This is an implementation detail exposed for testing and should not be
7742+
relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce
7743+
LLDB's memory consumption during execution.
7744+
7745+
"""
7746+
return _lldb.SBModule_GarbageCollectAllocatedModules()
7747+
77197748
class SBModuleSpec(object):
77207749
r"""Proxy of C++ lldb::SBModuleSpec class."""
77217750

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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,18 @@ 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+
pass
1042+
1043+
10321044
# =========================================================
10331045
# Various callbacks to allow introspection of test progress
10341046
# =========================================================
@@ -1989,13 +2001,9 @@ def tearDown(self):
19892001
for target in targets:
19902002
self.dbg.DeleteTarget(target)
19912003

1992-
# Modules are not orphaned during reproducer replay because they're
1993-
# leaked on purpose.
19942004
if not configuration.is_reproducer():
19952005
# 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
2006+
self.assertEqual(self.dbg.GetNumTargets(), 0)
19992007

20002008
# Do this last, to make sure it's in reverse order from how we setup.
20012009
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)