[Lldb-commits] [lldb] r149138 - in /lldb/trunk: include/lldb/Core/ModuleList.h source/Core/Module.cpp source/Core/ModuleList.cpp source/Utility/SharingPtr.cpp
Greg Clayton
gclayton at apple.com
Fri Jan 27 10:45:39 PST 2012
Author: gclayton
Date: Fri Jan 27 12:45:39 2012
New Revision: 149138
URL: http://llvm.org/viewvc/llvm-project?rev=149138&view=rev
Log:
Added a ModuleList::Destroy() method which will reclaim the std::vector
memory by doing a swap.
Also added a few utilty functions that can be enabled for debugging issues
with modules staying around too long when external clients still have references
to them.
Modified:
lldb/trunk/include/lldb/Core/ModuleList.h
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Core/ModuleList.cpp
lldb/trunk/source/Utility/SharingPtr.cpp
Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=149138&r1=149137&r2=149138&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Fri Jan 27 12:45:39 2012
@@ -89,6 +89,16 @@
Clear ();
//------------------------------------------------------------------
+ /// Clear the object's state.
+ ///
+ /// Clears the list of modules and releases a reference to each
+ /// module object and if the reference count goes to zero, the
+ /// module will be deleted. Also relese all memory that might be
+ /// held by any collection classes (like std::vector)
+ //------------------------------------------------------------------
+ void
+ Destroy();
+ //------------------------------------------------------------------
/// Dump the description of each module contained in this list.
///
/// Dump the description of each module contained in this list to
@@ -395,8 +405,8 @@
size_t
GetSize () const;
- static const lldb::ModuleSP
- GetModuleSP (const Module *module_ptr);
+ static bool
+ ModuleIsInCache (const Module *module_ptr);
static Error
GetSharedModule (const FileSpec& file_spec,
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=149138&r1=149137&r2=149138&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Jan 27 12:45:39 2012
@@ -73,8 +73,42 @@
return modules[idx];
return NULL;
}
+#if 0
+// These functions help us to determine if modules are still loaded, yet don't require that
+// you have a command interpreter and can easily be called from an external debugger.
+namespace lldb {
+ void
+ ClearModuleInfo (void)
+ {
+ ModuleList::RemoveOrphanSharedModules();
+ }
+
+ void
+ DumpModuleInfo (void)
+ {
+ Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
+ ModuleCollection &modules = GetModuleCollection();
+ const size_t count = modules.size();
+ printf ("%s: %zu modules:\n", __PRETTY_FUNCTION__, count);
+ for (size_t i=0; i<count; ++i)
+ {
+
+ StreamString strm;
+ Module *module = modules[i];
+ const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
+ module->GetDescription(&strm, eDescriptionLevelFull);
+ printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
+ module,
+ in_shared_module_list,
+ (uint32_t)module->use_count(),
+ strm.GetString().c_str());
+ }
+ }
+}
+
+#endif
Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) :
Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=149138&r1=149137&r2=149138&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Fri Jan 27 12:45:39 2012
@@ -155,6 +155,14 @@
m_modules.clear();
}
+void
+ModuleList::Destroy()
+{
+ Mutex::Locker locker(m_modules_mutex);
+ collection empty;
+ m_modules.swap(empty);
+}
+
Module*
ModuleList::GetModulePointerAtIndex (uint32_t idx) const
{
@@ -653,28 +661,15 @@
return g_shared_module_list;
}
-const lldb::ModuleSP
-ModuleList::GetModuleSP (const Module *module_ptr)
+bool
+ModuleList::ModuleIsInCache (const Module *module_ptr)
{
- lldb::ModuleSP module_sp;
if (module_ptr)
{
ModuleList &shared_module_list = GetSharedModuleList ();
- module_sp = shared_module_list.FindModule (module_ptr);
- if (module_sp.get() == NULL)
- {
- char uuid_cstr[256];
- const_cast<Module *>(module_ptr)->GetUUID().GetAsCString (uuid_cstr, sizeof(uuid_cstr));
- const FileSpec &module_file_spec = module_ptr->GetFileSpec();
- Host::SystemLog (Host::eSystemLogWarning,
- "warning: module not in shared module list: %s (%s) \"%s/%s\"\n",
- uuid_cstr,
- module_ptr->GetArchitecture().GetArchitectureName(),
- module_file_spec.GetDirectory().GetCString(),
- module_file_spec.GetFilename().GetCString());
- }
+ return shared_module_list.FindModule (module_ptr).get() != NULL;
}
- return module_sp;
+ return false;
}
size_t
Modified: lldb/trunk/source/Utility/SharingPtr.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/SharingPtr.cpp?rev=149138&r1=149137&r2=149138&view=diff
==============================================================================
--- lldb/trunk/source/Utility/SharingPtr.cpp (original)
+++ lldb/trunk/source/Utility/SharingPtr.cpp Fri Jan 27 12:45:39 2012
@@ -111,11 +111,16 @@
}
}
}
-extern "C" void dump_sp_refs (void *ptr)
-{
- // Use a specially crafted call to "track_sp" which will
- // dump info on all live shared pointers that reference "ptr"
- track_sp (NULL, ptr, 0);
+// Put dump_sp_refs in the lldb namespace to it gets through our exports lists filter in the LLDB.framework or lldb.so
+namespace lldb {
+
+ void dump_sp_refs (void *ptr)
+ {
+ // Use a specially crafted call to "track_sp" which will
+ // dump info on all live shared pointers that reference "ptr"
+ track_sp (NULL, ptr, 0);
+ }
+
}
#endif
More information about the lldb-commits
mailing list