summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/Module.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-08-09 00:01:09 +0000
committerGreg Clayton <gclayton@apple.com>2011-08-09 00:01:09 +0000
commit65a0399197b044482b14255653e4f02487c2b778 (patch)
tree3900d564367191ac9e66f29cba65019811fb049c /lldb/source/Core/Module.cpp
parent41c7591a1af7ba10cb98b0d3f6af01c55cc5bd58 (diff)
downloadbcm5719-llvm-65a0399197b044482b14255653e4f02487c2b778.tar.gz
bcm5719-llvm-65a0399197b044482b14255653e4f02487c2b778.zip
Added a "--global" option to the "target modules list"
command that allows us to see all modules that exist and their corresponding global shared pointer count. This will help us track down memory issues when modules aren't being removed and cleaned up from the module list. llvm-svn: 137078
Diffstat (limited to 'lldb/source/Core/Module.cpp')
-rw-r--r--lldb/source/Core/Module.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index f35e36e26e3..65f2fb7e628 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -20,6 +20,45 @@
using namespace lldb;
using namespace lldb_private;
+// Shared pointers to modules track module lifetimes in
+// targets and in the global module, but this collection
+// will track all module objects that are still alive
+typedef std::vector<Module *> ModuleCollection;
+
+static ModuleCollection &
+GetModuleCollection()
+{
+ static ModuleCollection g_module_collection;
+ return g_module_collection;
+}
+
+Mutex &
+Module::GetAllocationModuleCollectionMutex()
+{
+ static Mutex g_module_collection_mutex(Mutex::eMutexTypeRecursive);
+ return g_module_collection_mutex;
+}
+
+size_t
+Module::GetNumberAllocatedModules ()
+{
+ Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ return GetModuleCollection().size();
+}
+
+Module *
+Module::GetAllocatedModuleAtIndex (size_t idx)
+{
+ Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ ModuleCollection &modules = GetModuleCollection();
+ if (idx < modules.size())
+ return modules[idx];
+ return NULL;
+}
+
+
+
+
Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) :
m_mutex (Mutex::eMutexTypeRecursive),
m_mod_time (file_spec.GetModificationTime()),
@@ -38,6 +77,12 @@ Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstStrin
m_did_init_ast (false),
m_is_dynamic_loader_module (false)
{
+ // Scope for locker below...
+ {
+ Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ GetModuleCollection().push_back(this);
+ }
+
if (object_name)
m_object_name = *object_name;
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
@@ -54,6 +99,15 @@ Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstStrin
Module::~Module()
{
+ // Scope for locker below...
+ {
+ Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ ModuleCollection &modules = GetModuleCollection();
+ ModuleCollection::iterator end = modules.end();
+ ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
+ if (pos != end)
+ modules.erase(pos);
+ }
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')",
OpenPOWER on IntegriCloud