Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- BreakpointLocationList.cpp ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
| 14 | #include "lldb/Breakpoint/BreakpointLocationList.h" |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 15 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Michael Sartain | c87e752 | 2013-07-16 21:22:53 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/Breakpoint.h" |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ArchSpec.h" |
| 19 | #include "lldb/Core/Module.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Section.h" |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 21 | #include "lldb/Target/SectionLoadList.h" |
Michael Sartain | c87e752 | 2013-07-16 21:22:53 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 27 | BreakpointLocationList::BreakpointLocationList(Breakpoint &owner) |
| 28 | : m_owner(owner), m_locations(), m_address_to_location(), m_mutex(), m_next_id(0), m_new_location_recorder(nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Eugene Zelenko | 16fd751 | 2015-10-30 18:50:12 +0000 | [diff] [blame] | 32 | BreakpointLocationList::~BreakpointLocationList() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 34 | BreakpointLocationSP |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 35 | BreakpointLocationList::Create (const Address &addr, bool resolve_indirect_symbols) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 37 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 38 | // The location ID is just the size of the location list + 1 |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 39 | lldb::break_id_t bp_loc_id = ++m_next_id; |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 40 | BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, m_owner, addr, LLDB_INVALID_THREAD_ID, m_owner.IsHardware(), resolve_indirect_symbols)); |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 41 | m_locations.push_back (bp_loc_sp); |
| 42 | m_address_to_location[addr] = bp_loc_sp; |
| 43 | return bp_loc_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | bool |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 47 | BreakpointLocationList::ShouldStop (StoppointCallbackContext *context, lldb::break_id_t break_id) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | { |
| 49 | BreakpointLocationSP bp = FindByID (break_id); |
| 50 | if (bp) |
| 51 | { |
| 52 | // Let the BreakpointLocation decide if it should stop here (could not have |
| 53 | // reached it's target hit count yet, or it could have a callback |
| 54 | // that decided it shouldn't stop (shared library loads/unloads). |
| 55 | return bp->ShouldStop (context); |
| 56 | } |
| 57 | // We should stop here since this BreakpointLocation isn't valid anymore or it |
| 58 | // doesn't exist. |
| 59 | return true; |
| 60 | } |
| 61 | |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 62 | lldb::break_id_t |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 63 | BreakpointLocationList::FindIDByAddress (const Address &addr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | { |
| 65 | BreakpointLocationSP bp_loc_sp = FindByAddress (addr); |
| 66 | if (bp_loc_sp) |
| 67 | { |
| 68 | return bp_loc_sp->GetID(); |
| 69 | } |
| 70 | return LLDB_INVALID_BREAK_ID; |
| 71 | } |
| 72 | |
Jim Ingham | 177553e | 2013-12-03 02:31:17 +0000 | [diff] [blame] | 73 | static bool |
| 74 | Compare (BreakpointLocationSP lhs, lldb::break_id_t val) |
| 75 | { |
| 76 | return lhs->GetID() < val; |
| 77 | } |
| 78 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | BreakpointLocationSP |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 80 | BreakpointLocationList::FindByID (lldb::break_id_t break_id) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 82 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | c6b26f0 | 2013-12-03 17:50:20 +0000 | [diff] [blame] | 83 | collection::const_iterator end = m_locations.end(); |
| 84 | collection::const_iterator pos = std::lower_bound(m_locations.begin(), end, break_id, Compare); |
| 85 | if (pos != end && (*pos)->GetID() == break_id) |
| 86 | return *(pos); |
Jim Ingham | 177553e | 2013-12-03 02:31:17 +0000 | [diff] [blame] | 87 | else |
Greg Clayton | c6b26f0 | 2013-12-03 17:50:20 +0000 | [diff] [blame] | 88 | return BreakpointLocationSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | size_t |
| 92 | BreakpointLocationList::FindInModule (Module *module, |
| 93 | BreakpointLocationCollection& bp_loc_list) |
| 94 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 95 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | const size_t orig_size = bp_loc_list.GetSize(); |
| 97 | collection::iterator pos, end = m_locations.end(); |
| 98 | |
| 99 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 100 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 101 | BreakpointLocationSP break_loc = (*pos); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 102 | SectionSP section_sp (break_loc->GetAddress().GetSection()); |
| 103 | if (section_sp && section_sp->GetModule().get() == module) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | { |
Johnny Chen | 0861be0 | 2011-08-11 21:43:13 +0000 | [diff] [blame] | 105 | bp_loc_list.Add (break_loc); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | return bp_loc_list.GetSize() - orig_size; |
| 109 | } |
| 110 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | const BreakpointLocationSP |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 112 | BreakpointLocationList::FindByAddress (const Address &addr) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 114 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 115 | BreakpointLocationSP bp_loc_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | if (!m_locations.empty()) |
| 117 | { |
Michael Sartain | c87e752 | 2013-07-16 21:22:53 +0000 | [diff] [blame] | 118 | Address so_addr; |
| 119 | |
| 120 | if (addr.IsSectionOffset()) |
| 121 | { |
| 122 | so_addr = addr; |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | // Try and resolve as a load address if possible. |
| 127 | m_owner.GetTarget().GetSectionLoadList().ResolveLoadAddress (addr.GetOffset(), so_addr); |
| 128 | if (!so_addr.IsValid()) |
| 129 | { |
| 130 | // The address didn't resolve, so just set to passed in addr. |
| 131 | so_addr = addr; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | addr_map::const_iterator pos = m_address_to_location.find (so_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | if (pos != m_address_to_location.end()) |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 137 | bp_loc_sp = pos->second; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 140 | return bp_loc_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void |
| 144 | BreakpointLocationList::Dump (Stream *s) const |
| 145 | { |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 146 | s->Printf("%p: ", static_cast<const void*>(this)); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 147 | //s->Indent(); |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 148 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 149 | s->Printf("BreakpointLocationList with %" PRIu64 " BreakpointLocations:\n", (uint64_t)m_locations.size()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | s->IndentMore(); |
| 151 | collection::const_iterator pos, end = m_locations.end(); |
| 152 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 153 | (*pos).get()->Dump(s); |
| 154 | s->IndentLess(); |
| 155 | } |
| 156 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | BreakpointLocationSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 158 | BreakpointLocationList::GetByIndex (size_t i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 160 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 161 | BreakpointLocationSP bp_loc_sp; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 162 | if (i < m_locations.size()) |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 163 | bp_loc_sp = m_locations[i]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 165 | return bp_loc_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | const BreakpointLocationSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 169 | BreakpointLocationList::GetByIndex (size_t i) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 171 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 172 | BreakpointLocationSP bp_loc_sp; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 173 | if (i < m_locations.size()) |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 174 | bp_loc_sp = m_locations[i]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | |
Greg Clayton | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 176 | return bp_loc_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void |
| 180 | BreakpointLocationList::ClearAllBreakpointSites () |
| 181 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 182 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 183 | collection::iterator pos, end = m_locations.end(); |
| 184 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 185 | (*pos)->ClearBreakpointSite(); |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | BreakpointLocationList::ResolveAllBreakpointSites () |
| 190 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 191 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | collection::iterator pos, end = m_locations.end(); |
| 193 | |
| 194 | for (pos = m_locations.begin(); pos != end; ++pos) |
Jim Ingham | d4ce0a1 | 2010-10-20 03:36:33 +0000 | [diff] [blame] | 195 | { |
| 196 | if ((*pos)->IsEnabled()) |
| 197 | (*pos)->ResolveBreakpointSite(); |
| 198 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 201 | uint32_t |
| 202 | BreakpointLocationList::GetHitCount () const |
| 203 | { |
| 204 | uint32_t hit_count = 0; |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 205 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 206 | collection::const_iterator pos, end = m_locations.end(); |
| 207 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 208 | hit_count += (*pos)->GetHitCount(); |
| 209 | return hit_count; |
| 210 | } |
| 211 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 212 | size_t |
| 213 | BreakpointLocationList::GetNumResolvedLocations() const |
| 214 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 215 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | size_t resolve_count = 0; |
| 217 | collection::const_iterator pos, end = m_locations.end(); |
| 218 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 219 | { |
| 220 | if ((*pos)->IsResolved()) |
| 221 | ++resolve_count; |
| 222 | } |
| 223 | return resolve_count; |
| 224 | } |
| 225 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 226 | void |
| 227 | BreakpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 228 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 229 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | collection::iterator pos, end = m_locations.end(); |
| 231 | |
| 232 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 233 | { |
| 234 | s->Printf(" "); |
| 235 | (*pos)->GetDescription(s, level); |
| 236 | } |
| 237 | } |
| 238 | |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 239 | BreakpointLocationSP |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 240 | BreakpointLocationList::AddLocation (const Address &addr, bool resolve_indirect_symbols, bool *new_location) |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 241 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 242 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 243 | |
| 244 | if (new_location) |
| 245 | *new_location = false; |
| 246 | BreakpointLocationSP bp_loc_sp (FindByAddress(addr)); |
| 247 | if (!bp_loc_sp) |
| 248 | { |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 249 | bp_loc_sp = Create (addr, resolve_indirect_symbols); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 250 | if (bp_loc_sp) |
| 251 | { |
| 252 | bp_loc_sp->ResolveBreakpointSite(); |
| 253 | |
| 254 | if (new_location) |
| 255 | *new_location = true; |
| 256 | if(m_new_location_recorder) |
| 257 | { |
| 258 | m_new_location_recorder->Add(bp_loc_sp); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return bp_loc_sp; |
| 263 | } |
| 264 | |
Jim Ingham | 77fd738 | 2014-09-10 21:40:47 +0000 | [diff] [blame] | 265 | void |
| 266 | BreakpointLocationList::SwapLocation (BreakpointLocationSP to_location_sp, BreakpointLocationSP from_location_sp) |
| 267 | { |
| 268 | if (!from_location_sp || !to_location_sp) |
| 269 | return; |
| 270 | |
| 271 | m_address_to_location.erase(to_location_sp->GetAddress()); |
| 272 | to_location_sp->SwapLocation(from_location_sp); |
| 273 | RemoveLocation(from_location_sp); |
| 274 | m_address_to_location[to_location_sp->GetAddress()] = to_location_sp; |
| 275 | to_location_sp->ResolveBreakpointSite(); |
| 276 | } |
| 277 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 278 | bool |
| 279 | BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp) |
| 280 | { |
| 281 | if (bp_loc_sp) |
| 282 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 283 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 284 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 285 | m_address_to_location.erase (bp_loc_sp->GetAddress()); |
| 286 | |
| 287 | collection::iterator pos, end = m_locations.end(); |
| 288 | for (pos = m_locations.begin(); pos != end; ++pos) |
| 289 | { |
| 290 | if ((*pos).get() == bp_loc_sp.get()) |
| 291 | { |
| 292 | m_locations.erase (pos); |
| 293 | return true; |
| 294 | } |
| 295 | } |
Eugene Zelenko | 16fd751 | 2015-10-30 18:50:12 +0000 | [diff] [blame] | 296 | } |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 300 | void |
| 301 | BreakpointLocationList::RemoveInvalidLocations (const ArchSpec &arch) |
| 302 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 303 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 304 | size_t idx = 0; |
| 305 | // Don't cache m_location.size() as it will change since we might |
| 306 | // remove locations from our vector... |
| 307 | while (idx < m_locations.size()) |
| 308 | { |
| 309 | BreakpointLocation *bp_loc = m_locations[idx].get(); |
| 310 | if (bp_loc->GetAddress().SectionWasDeleted()) |
| 311 | { |
| 312 | // Section was deleted which means this breakpoint comes from a module |
| 313 | // that is no longer valid, so we should remove it. |
| 314 | m_locations.erase(m_locations.begin() + idx); |
| 315 | continue; |
| 316 | } |
| 317 | if (arch.IsValid()) |
| 318 | { |
| 319 | ModuleSP module_sp (bp_loc->GetAddress().GetModule()); |
| 320 | if (module_sp) |
| 321 | { |
| 322 | if (!arch.IsCompatibleMatch(module_sp->GetArchitecture())) |
| 323 | { |
| 324 | // The breakpoint was in a module whose architecture is no longer |
| 325 | // compatible with "arch", so we need to remove it |
| 326 | m_locations.erase(m_locations.begin() + idx); |
| 327 | continue; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | // Only increment the index if we didn't remove the locations at index "idx" |
| 332 | ++idx; |
| 333 | } |
| 334 | } |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 335 | |
| 336 | void |
| 337 | BreakpointLocationList::StartRecordingNewLocations (BreakpointLocationCollection &new_locations) |
| 338 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 339 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Eugene Zelenko | 16fd751 | 2015-10-30 18:50:12 +0000 | [diff] [blame] | 340 | assert(m_new_location_recorder == nullptr); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 341 | m_new_location_recorder = &new_locations; |
| 342 | } |
| 343 | |
| 344 | void |
| 345 | BreakpointLocationList::StopRecordingNewLocations () |
| 346 | { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame^] | 347 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Eugene Zelenko | 16fd751 | 2015-10-30 18:50:12 +0000 | [diff] [blame] | 348 | m_new_location_recorder = nullptr; |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Jim Ingham | 77fd738 | 2014-09-10 21:40:47 +0000 | [diff] [blame] | 351 | void |
| 352 | BreakpointLocationList::Compact() |
| 353 | { |
| 354 | lldb::break_id_t highest_id = 0; |
| 355 | |
| 356 | for (BreakpointLocationSP loc_sp : m_locations) |
| 357 | { |
| 358 | lldb::break_id_t cur_id = loc_sp->GetID(); |
| 359 | if (cur_id > highest_id) |
| 360 | highest_id = cur_id; |
| 361 | } |
| 362 | m_next_id = highest_id; |
| 363 | } |