From: Jim Ingham Date: Thu, 28 Mar 2019 01:51:33 +0000 (+0000) Subject: Copy the breakpoint site owner's collection so we can drop X-Git-Tag: llvmorg-10-init~9015 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1432b9780b3ef1d4f5deab0258c71124b362898d;p=platform%2Fupstream%2Fllvm.git Copy the breakpoint site owner's collection so we can drop the collection lock before we iterate over the owners calling ShouldStop. BreakpointSite::ShouldStop can do a lot of work, and might by chance hit the same breakpoint site again on another thread. So instead of holding the site's owners lock while iterating over them calling ShouldStop, I make a local copy of the list, drop the lock and then iterate over the copy calling BreakpointLocation::ShouldStop. It's actually quite difficult to make this cause problems because usually all the action happens on the private state thread, and the lock is recursive. I have a report where some code hit the ASAN error breakpoint, went to compile the ASAN error gathering expression, in the course of compiling that we went to fetch the ObjC runtime data, but the state of the program was such that the ObjC runtime grubbing function triggered an ASAN error and we were executing that function on another thread. I couldn't figure out a way to reproduce that situation in a test. But this is an NFC change anyway, it just makes the locking strategy more narrowly focused. llvm-svn: 357141 --- diff --git a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h index 1497c30..c1b3ff9 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h +++ b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h @@ -22,6 +22,8 @@ public: BreakpointLocationCollection(); ~BreakpointLocationCollection(); + + BreakpointLocationCollection &operator=(const BreakpointLocationCollection &rhs); //------------------------------------------------------------------ /// Add the breakpoint \a bp_loc_sp to the list. diff --git a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp index 8ca6d2f..413c12a 100644 --- a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp +++ b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp @@ -178,3 +178,20 @@ void BreakpointLocationCollection::GetDescription( (*pos)->GetDescription(s, level); } } + +BreakpointLocationCollection &BreakpointLocationCollection::operator=( + const BreakpointLocationCollection &rhs) { + // Same trick as in ModuleList to avoid lock inversion. + if (this != &rhs) { + if (uintptr_t(this) > uintptr_t(&rhs)) { + std::lock_guard lhs_guard(m_collection_mutex); + std::lock_guard rhs_guard(rhs.m_collection_mutex); + m_break_loc_collection = rhs.m_break_loc_collection; + } else { + std::lock_guard lhs_guard(m_collection_mutex); + std::lock_guard rhs_guard(rhs.m_collection_mutex); + m_break_loc_collection = rhs.m_break_loc_collection; + } + } + return *this; +} diff --git a/lldb/source/Breakpoint/BreakpointSite.cpp b/lldb/source/Breakpoint/BreakpointSite.cpp index 8151f30..a757a01 100644 --- a/lldb/source/Breakpoint/BreakpointSite.cpp +++ b/lldb/source/Breakpoint/BreakpointSite.cpp @@ -48,9 +48,17 @@ break_id_t BreakpointSite::GetNextID() { // should continue. bool BreakpointSite::ShouldStop(StoppointCallbackContext *context) { - std::lock_guard guard(m_owners_mutex); IncrementHitCount(); - return m_owners.ShouldStop(context); + // ShouldStop can do a lot of work, and might even come come back and hit + // this breakpoint site again. So don't hold the m_owners_mutex the whole + // while. Instead make a local copy of the collection and call ShouldStop on + // the copy. + BreakpointLocationCollection owners_copy; + { + std::lock_guard guard(m_owners_mutex); + owners_copy = m_owners; + } + return owners_copy.ShouldStop(context); } bool BreakpointSite::IsBreakpointAtThisSite(lldb::break_id_t bp_id) {