[Lldb-commits] [lldb] r196197 - Remove the bad assumption that breakpoint locations won't get deleted in BreakpointLocationList::FindByID.

Jim Ingham jingham at apple.com
Mon Dec 2 18:31:17 PST 2013


Author: jingham
Date: Mon Dec  2 20:31:17 2013
New Revision: 196197

URL: http://llvm.org/viewvc/llvm-project?rev=196197&view=rev
Log:
Remove the bad assumption that breakpoint locations won't get deleted in BreakpointLocationList::FindByID.

<rdar://problem/15566148>

Modified:
    lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h
    lldb/trunk/source/Breakpoint/BreakpointLocationList.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h?rev=196197&r1=196196&r2=196197&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocationList.h Mon Dec  2 20:31:17 2013
@@ -260,7 +260,7 @@ protected:
                      Address::ModulePointerAndOffsetLessThanFunctionObject> addr_map;
 
     Breakpoint &m_owner;
-    collection m_locations;
+    collection m_locations;         // Vector of locations, sorted by ID 
     addr_map m_address_to_location;
     mutable Mutex m_mutex;
     lldb::break_id_t m_next_id;

Modified: lldb/trunk/source/Breakpoint/BreakpointLocationList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocationList.cpp?rev=196197&r1=196196&r2=196197&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocationList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocationList.cpp Mon Dec  2 20:31:17 2013
@@ -77,19 +77,25 @@ BreakpointLocationList::FindIDByAddress
     return LLDB_INVALID_BREAK_ID;
 }
 
+static bool
+Compare (BreakpointLocationSP lhs, lldb::break_id_t val)
+{
+    return lhs->GetID() < val;
+}
+
 BreakpointLocationSP
 BreakpointLocationList::FindByID (lldb::break_id_t break_id) const
 {
     BreakpointLocationSP bp_loc_sp;
     Mutex::Locker locker (m_mutex);
-    // We never remove a breakpoint locations, so the ID can be translated into
-    // the location index by subtracting 1
-    uint32_t idx = break_id - 1;
-    if (idx <= m_locations.size())
-    {
-        bp_loc_sp = m_locations[idx];
-    }
-    return bp_loc_sp;
+    
+    collection::const_iterator begin = m_locations.begin(), end = m_locations.end();
+    collection::const_iterator result;
+    result = std::lower_bound(begin, end, break_id, Compare);
+    if (result == end)
+        return bp_loc_sp;
+    else
+        return *(result);
 }
 
 size_t





More information about the lldb-commits mailing list