summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2012-05-30 02:19:25 +0000
committerJim Ingham <jingham@apple.com>2012-05-30 02:19:25 +0000
commit3ee12ef26ed534af3d0c85f88df7b06db037bfe3 (patch)
tree9d46961f3981c27e927926a4ea7d5a2c2b0b6ba7 /lldb/source/Core
parent13586ab6d8a1c9f373315a70c384f67089c2371e (diff)
downloadbcm5719-llvm-3ee12ef26ed534af3d0c85f88df7b06db037bfe3.tar.gz
bcm5719-llvm-3ee12ef26ed534af3d0c85f88df7b06db037bfe3.zip
We were accessing the ModuleList in the target without locking it for tasks like
setting breakpoints. That's dangerous, since while we are setting a breakpoint, the target might hit the dyld load notification, and start removing modules from the list. This change adds a GetMutex accessor to the ModuleList class, and uses it whenever we are accessing the target's ModuleList (as returned by GetImages().) <rdar://problem/11552372> llvm-svn: 157668
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/ModuleList.cpp12
-rw-r--r--lldb/source/Core/SearchFilter.cpp33
2 files changed, 34 insertions, 11 deletions
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 8f852d4d8d1..157dafa7a2c 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -201,6 +201,12 @@ Module*
ModuleList::GetModulePointerAtIndex (uint32_t idx) const
{
Mutex::Locker locker(m_modules_mutex);
+ return GetModulePointerAtIndexUnlocked(idx);
+}
+
+Module*
+ModuleList::GetModulePointerAtIndexUnlocked (uint32_t idx) const
+{
if (idx < m_modules.size())
return m_modules[idx].get();
return NULL;
@@ -210,6 +216,12 @@ ModuleSP
ModuleList::GetModuleAtIndex(uint32_t idx)
{
Mutex::Locker locker(m_modules_mutex);
+ return GetModuleAtIndexUnlocked(idx);
+}
+
+ModuleSP
+ModuleList::GetModuleAtIndexUnlocked(uint32_t idx)
+{
ModuleSP module_sp;
if (idx < m_modules.size())
module_sp = m_modules[idx];
diff --git a/lldb/source/Core/SearchFilter.cpp b/lldb/source/Core/SearchFilter.cpp
index b52ffdd24b0..f00f222bc30 100644
--- a/lldb/source/Core/SearchFilter.cpp
+++ b/lldb/source/Core/SearchFilter.cpp
@@ -160,11 +160,12 @@ SearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules)
searcher.SearchCallback (*this, empty_sc, NULL, false);
else
{
+ Mutex::Locker modules_locker(modules.GetMutex());
const size_t numModules = modules.GetSize();
for (size_t i = 0; i < numModules; i++)
{
- ModuleSP module_sp(modules.GetModuleAtIndex(i));
+ ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i));
if (ModulePasses(module_sp))
{
if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
@@ -191,12 +192,15 @@ SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searche
{
if (!context.module_sp)
{
- size_t n_modules = m_target_sp->GetImages().GetSize();
+ ModuleList &target_images = m_target_sp->GetImages();
+ Mutex::Locker modules_locker(target_images.GetMutex());
+
+ size_t n_modules = target_images.GetSize();
for (size_t i = 0; i < n_modules; i++)
{
// If this is the last level supplied, then call the callback directly,
// otherwise descend.
- ModuleSP module_sp(m_target_sp->GetImages().GetModuleAtIndex(i));
+ ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked (i));
if (!ModulePasses (module_sp))
continue;
@@ -427,11 +431,13 @@ SearchFilterByModule::Search (Searcher &searcher)
// filespec that passes. Otherwise, we need to go through all modules and
// find the ones that match the file name.
- ModuleList matching_modules;
- const size_t num_modules = m_target_sp->GetImages().GetSize ();
+ ModuleList &target_modules = m_target_sp->GetImages();
+ Mutex::Locker modules_locker (target_modules.GetMutex());
+
+ const size_t num_modules = target_modules.GetSize ();
for (size_t i = 0; i < num_modules; i++)
{
- Module* module = m_target_sp->GetImages().GetModulePointerAtIndex(i);
+ Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
if (FileSpec::Compare (m_module_spec, module->GetFileSpec(), false) == 0)
{
SymbolContext matchingContext(m_target_sp, module->shared_from_this());
@@ -591,11 +597,13 @@ SearchFilterByModuleList::Search (Searcher &searcher)
// filespec that passes. Otherwise, we need to go through all modules and
// find the ones that match the file name.
- ModuleList matching_modules;
- const size_t num_modules = m_target_sp->GetImages().GetSize ();
+ ModuleList &target_modules = m_target_sp->GetImages();
+ Mutex::Locker modules_locker (target_modules.GetMutex());
+
+ const size_t num_modules = target_modules.GetSize ();
for (size_t i = 0; i < num_modules; i++)
{
- Module* module = m_target_sp->GetImages().GetModulePointerAtIndex(i);
+ Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) != UINT32_MAX)
{
SymbolContext matchingContext(m_target_sp, module->shared_from_this());
@@ -762,11 +770,14 @@ SearchFilterByModuleListAndCU::Search (Searcher &searcher)
// find the ones that match the file name.
ModuleList matching_modules;
- const size_t num_modules = m_target_sp->GetImages().GetSize ();
+ ModuleList &target_images = m_target_sp->GetImages();
+ Mutex::Locker modules_locker(target_images.GetMutex());
+
+ const size_t num_modules = target_images.GetSize ();
bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
for (size_t i = 0; i < num_modules; i++)
{
- lldb::ModuleSP module_sp = m_target_sp->GetImages().GetModuleAtIndex(i);
+ lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i);
if (no_modules_in_filter || m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
{
SymbolContext matchingContext(m_target_sp, module_sp);
OpenPOWER on IntegriCloud