Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- BreakpointLocationCollection.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 | |
| 10 | |
| 11 | // C Includes |
| 12 | // C++ Includes |
| 13 | // Other libraries and framework includes |
| 14 | // Project includes |
| 15 | #include "lldb/Breakpoint/BreakpointLocationCollection.h" |
| 16 | #include "lldb/Core/ModuleList.h" |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/Breakpoint.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Thread.h" |
| 20 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
| 25 | //---------------------------------------------------------------------- |
| 26 | // BreakpointLocationCollection constructor |
| 27 | //---------------------------------------------------------------------- |
| 28 | BreakpointLocationCollection::BreakpointLocationCollection() : |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 29 | m_break_loc_collection(), |
| 30 | m_collection_mutex() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
| 32 | } |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // Destructor |
| 36 | //---------------------------------------------------------------------- |
| 37 | BreakpointLocationCollection::~BreakpointLocationCollection() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) |
| 43 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 44 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | BreakpointLocationSP old_bp_loc = FindByIDPair (bp_loc->GetBreakpoint().GetID(), bp_loc->GetID()); |
| 46 | if (!old_bp_loc.get()) |
| 47 | m_break_loc_collection.push_back(bp_loc); |
| 48 | } |
| 49 | |
| 50 | bool |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 51 | BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 53 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate |
| 55 | if (pos != m_break_loc_collection.end()) |
| 56 | { |
| 57 | m_break_loc_collection.erase(pos); |
| 58 | return true; |
| 59 | } |
| 60 | return false; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | class BreakpointIDPairMatches |
| 65 | { |
| 66 | public: |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 67 | BreakpointIDPairMatches (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | m_break_id(break_id), |
| 69 | m_break_loc_id (break_loc_id) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | bool operator() (const BreakpointLocationSP &bp_loc) const |
| 74 | { |
| 75 | return m_break_id == bp_loc->GetBreakpoint().GetID() |
| 76 | && m_break_loc_id == bp_loc->GetID(); |
| 77 | } |
| 78 | |
| 79 | private: |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 80 | const lldb::break_id_t m_break_id; |
| 81 | const lldb::break_id_t m_break_loc_id; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | BreakpointLocationCollection::collection::iterator |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 85 | BreakpointLocationCollection::GetIDPairIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | { |
| 87 | return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range |
| 88 | BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate |
| 89 | } |
| 90 | |
| 91 | BreakpointLocationCollection::collection::const_iterator |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 92 | BreakpointLocationCollection::GetIDPairConstIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | { |
| 94 | return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range |
| 95 | BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate |
| 96 | } |
| 97 | |
| 98 | BreakpointLocationSP |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 99 | BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | { |
| 101 | BreakpointLocationSP stop_sp; |
| 102 | collection::iterator pos = GetIDPairIterator(break_id, break_loc_id); |
| 103 | if (pos != m_break_loc_collection.end()) |
| 104 | stop_sp = *pos; |
| 105 | |
| 106 | return stop_sp; |
| 107 | } |
| 108 | |
| 109 | const BreakpointLocationSP |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 110 | BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | { |
| 112 | BreakpointLocationSP stop_sp; |
| 113 | collection::const_iterator pos = GetIDPairConstIterator(break_id, break_loc_id); |
| 114 | if (pos != m_break_loc_collection.end()) |
| 115 | stop_sp = *pos; |
| 116 | |
| 117 | return stop_sp; |
| 118 | } |
| 119 | |
| 120 | BreakpointLocationSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 121 | BreakpointLocationCollection::GetByIndex (size_t i) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 123 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | BreakpointLocationSP stop_sp; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 125 | if (i < m_break_loc_collection.size()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | stop_sp = m_break_loc_collection[i]; |
| 127 | |
| 128 | return stop_sp; |
| 129 | } |
| 130 | |
| 131 | const BreakpointLocationSP |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 132 | BreakpointLocationCollection::GetByIndex (size_t i) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 134 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | BreakpointLocationSP stop_sp; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 136 | if (i < m_break_loc_collection.size()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | stop_sp = m_break_loc_collection[i]; |
| 138 | |
| 139 | return stop_sp; |
| 140 | } |
| 141 | |
| 142 | bool |
| 143 | BreakpointLocationCollection::ShouldStop (StoppointCallbackContext *context) |
| 144 | { |
| 145 | bool shouldStop = false; |
Tamas Berghammer | 729dcfb | 2015-05-27 09:46:47 +0000 | [diff] [blame] | 146 | size_t i = 0; |
| 147 | size_t prev_size = GetSize(); |
| 148 | while (i < prev_size) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 149 | { |
Tamas Berghammer | 729dcfb | 2015-05-27 09:46:47 +0000 | [diff] [blame] | 150 | // ShouldStop can remove the breakpoint from the list |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 151 | if (GetByIndex(i)->ShouldStop(context)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | shouldStop = true; |
Tamas Berghammer | 729dcfb | 2015-05-27 09:46:47 +0000 | [diff] [blame] | 153 | |
| 154 | if (prev_size == GetSize()) |
| 155 | i++; |
| 156 | prev_size = GetSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | } |
| 158 | return shouldStop; |
| 159 | } |
| 160 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 161 | bool |
| 162 | BreakpointLocationCollection::ValidForThisThread (Thread *thread) |
| 163 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 164 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 165 | collection::iterator pos, |
| 166 | begin = m_break_loc_collection.begin(), |
| 167 | end = m_break_loc_collection.end(); |
| 168 | |
| 169 | for (pos = begin; pos != end; ++pos) |
| 170 | { |
| 171 | if ((*pos)->ValidForThisThread (thread)) |
| 172 | return true; |
| 173 | } |
| 174 | return false; |
| 175 | } |
| 176 | |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 177 | bool |
| 178 | BreakpointLocationCollection::IsInternal () const |
| 179 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 180 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 181 | collection::const_iterator pos, |
| 182 | begin = m_break_loc_collection.begin(), |
| 183 | end = m_break_loc_collection.end(); |
| 184 | |
| 185 | bool is_internal = true; |
| 186 | |
| 187 | for (pos = begin; pos != end; ++pos) |
| 188 | { |
| 189 | if (!(*pos)->GetBreakpoint().IsInternal ()) |
| 190 | { |
| 191 | is_internal = false; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | return is_internal; |
| 196 | } |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 197 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | void |
| 199 | BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 200 | { |
Jim Ingham | 1cf8f59 | 2016-05-26 23:55:04 +0000 | [diff] [blame] | 201 | std::lock_guard<std::mutex> guard(m_collection_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | collection::iterator pos, |
| 203 | begin = m_break_loc_collection.begin(), |
| 204 | end = m_break_loc_collection.end(); |
| 205 | |
| 206 | for (pos = begin; pos != end; ++pos) |
| 207 | { |
| 208 | if (pos != begin) |
| 209 | s->PutChar(' '); |
| 210 | (*pos)->GetDescription(s, level); |
| 211 | } |
| 212 | } |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 213 | |