<rdar://problem/11202426>
Work around a deadlocking issue where "SBDebugger::MemoryPressureDetected ()" is being called and is causing a deadlock. We now just try and get the lock when trying to trim down the unique modules so we don't deadlock debugger GUI programs until we can find the root cause.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@154339 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index b61acd7..4c62ffb 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -143,7 +143,12 @@
void
SBDebugger::MemoryPressureDetected ()
{
- ModuleList::RemoveOrphanSharedModules();
+ // Since this function can be call asynchronously, we allow it to be
+ // non-mandatory. We have seen deadlocks with this function when called
+ // so we need to safeguard against this until we can determine what is
+ // causing the deadlocks.
+ const bool mandatory = false;
+ ModuleList::RemoveOrphanSharedModules(mandatory);
}
SBDebugger::SBDebugger () :
@@ -648,7 +653,8 @@
result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
target_sp->Destroy();
target.Clear();
- ModuleList::RemoveOrphanSharedModules();
+ const bool mandatory = true;
+ ModuleList::RemoveOrphanSharedModules(mandatory);
}
}
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 17d5fd5..ec48de6 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -520,7 +520,8 @@
// the global shared module list
if (m_cleanup_option.GetOptionValue ())
{
- ModuleList::RemoveOrphanSharedModules();
+ const bool mandatory = true;
+ ModuleList::RemoveOrphanSharedModules(mandatory);
}
result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
result.SetStatus(eReturnStatusSuccessFinishResult);
diff --git a/source/Core/Module.cpp b/source/Core/Module.cpp
index 8ef4430..8932576 100644
--- a/source/Core/Module.cpp
+++ b/source/Core/Module.cpp
@@ -86,7 +86,8 @@
void
ClearModuleInfo (void)
{
- ModuleList::RemoveOrphanSharedModules();
+ const bool mandatory = true;
+ ModuleList::RemoveOrphanSharedModules(mandatory);
}
void
diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index 69245fb..5e4f660 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -112,9 +112,20 @@
size_t
-ModuleList::RemoveOrphans ()
+ModuleList::RemoveOrphans (bool mandatory)
{
- Mutex::Locker locker(m_modules_mutex);
+ Mutex::Locker locker;
+
+ if (mandatory)
+ {
+ locker.Reset (m_modules_mutex.GetMutex());
+ }
+ else
+ {
+ // Not mandatory, remove orphans if we can get the mutex
+ if (!locker.TryLock(m_modules_mutex.GetMutex()))
+ return 0;
+ }
collection::iterator pos = m_modules.begin();
size_t remove_count = 0;
while (pos != m_modules.end())
@@ -587,9 +598,9 @@
}
uint32_t
-ModuleList::RemoveOrphanSharedModules ()
+ModuleList::RemoveOrphanSharedModules (bool mandatory)
{
- return GetSharedModuleList ().RemoveOrphans();
+ return GetSharedModuleList ().RemoveOrphans(mandatory);
}
Error