Added the ability to remove orphaned module shared pointers from a ModuleList.
This is helping us track down some extra references to ModuleSP objects that
are causing things to get kept around for too long.
Added a module pointer accessor to target and change a lot of code to use
it where it would be more efficient.
"taret delete" can now specify "--clean=1" which will cleanup the global module
list for any orphaned module in the shared module cache which can save memory
and also help track down module reference leaks like we have now.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@137294 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index e65f2d1..600a06b 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -98,8 +98,9 @@
}
else
{
- if (GetExecutableModule())
- s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
+ Module *exe_module = GetExecutableModulePointer();
+ if (exe_module)
+ s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
else
s->PutCString ("No executable module.");
}
@@ -437,10 +438,13 @@
ModuleSP
Target::GetExecutableModule ()
{
- ModuleSP executable_sp;
- if (m_images.GetSize() > 0)
- executable_sp = m_images.GetModuleAtIndex(0);
- return executable_sp;
+ return m_images.GetModuleAtIndex(0);
+}
+
+Module*
+Target::GetExecutableModulePointer ()
+{
+ return m_images.GetModulePointerAtIndex(0);
}
void
@@ -915,14 +919,11 @@
)
{
Target *target = (Target *)baton;
- if (target->m_images.GetSize() > 1)
+ ModuleSP exe_module_sp (target->GetExecutableModule());
+ if (exe_module_sp)
{
- ModuleSP exe_module_sp (target->GetExecutableModule());
- if (exe_module_sp)
- {
- target->m_images.Clear();
- target->SetExecutableModule (exe_module_sp, true);
- }
+ target->m_images.Clear();
+ target->SetExecutableModule (exe_module_sp, true);
}
}
@@ -1013,14 +1014,13 @@
{
StreamString sstr;
- ModuleSP module_sp = GetExecutableModule();
- if (module_sp)
+ Module *exe_module = GetExecutableModulePointer();
+ if (exe_module)
{
sstr.Printf ("%s_%s",
- module_sp->GetFileSpec().GetFilename().AsCString(),
- module_sp->GetArchitecture().GetArchitectureName());
- GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
- sstr.GetData());
+ exe_module->GetFileSpec().GetFilename().AsCString(),
+ exe_module->GetArchitecture().GetArchitectureName());
+ GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
}
}