Chris Lattner | 24943d2 | 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 | 640dc6b | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/Breakpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Thread.h" |
| 20 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 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() : |
| 29 | m_break_loc_collection() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | //---------------------------------------------------------------------- |
| 34 | // Destructor |
| 35 | //---------------------------------------------------------------------- |
| 36 | BreakpointLocationCollection::~BreakpointLocationCollection() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) |
| 42 | { |
| 43 | BreakpointLocationSP old_bp_loc = FindByIDPair (bp_loc->GetBreakpoint().GetID(), bp_loc->GetID()); |
| 44 | if (!old_bp_loc.get()) |
| 45 | m_break_loc_collection.push_back(bp_loc); |
| 46 | } |
| 47 | |
| 48 | bool |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 49 | BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | { |
| 51 | collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate |
| 52 | if (pos != m_break_loc_collection.end()) |
| 53 | { |
| 54 | m_break_loc_collection.erase(pos); |
| 55 | return true; |
| 56 | } |
| 57 | return false; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | class BreakpointIDPairMatches |
| 62 | { |
| 63 | public: |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 64 | BreakpointIDPairMatches (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | m_break_id(break_id), |
| 66 | m_break_loc_id (break_loc_id) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | bool operator() (const BreakpointLocationSP &bp_loc) const |
| 71 | { |
| 72 | return m_break_id == bp_loc->GetBreakpoint().GetID() |
| 73 | && m_break_loc_id == bp_loc->GetID(); |
| 74 | } |
| 75 | |
| 76 | private: |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 77 | const lldb::break_id_t m_break_id; |
| 78 | const lldb::break_id_t m_break_loc_id; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | BreakpointLocationCollection::collection::iterator |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 82 | BreakpointLocationCollection::GetIDPairIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | { |
| 84 | return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range |
| 85 | BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate |
| 86 | } |
| 87 | |
| 88 | BreakpointLocationCollection::collection::const_iterator |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 89 | BreakpointLocationCollection::GetIDPairConstIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | { |
| 91 | return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range |
| 92 | BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate |
| 93 | } |
| 94 | |
| 95 | BreakpointLocationSP |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 96 | BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | { |
| 98 | BreakpointLocationSP stop_sp; |
| 99 | collection::iterator pos = GetIDPairIterator(break_id, break_loc_id); |
| 100 | if (pos != m_break_loc_collection.end()) |
| 101 | stop_sp = *pos; |
| 102 | |
| 103 | return stop_sp; |
| 104 | } |
| 105 | |
| 106 | const BreakpointLocationSP |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 107 | BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | { |
| 109 | BreakpointLocationSP stop_sp; |
| 110 | collection::const_iterator pos = GetIDPairConstIterator(break_id, break_loc_id); |
| 111 | if (pos != m_break_loc_collection.end()) |
| 112 | stop_sp = *pos; |
| 113 | |
| 114 | return stop_sp; |
| 115 | } |
| 116 | |
| 117 | BreakpointLocationSP |
| 118 | BreakpointLocationCollection::GetByIndex (uint32_t i) |
| 119 | { |
| 120 | BreakpointLocationSP stop_sp; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 121 | if (i < m_break_loc_collection.size()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | stop_sp = m_break_loc_collection[i]; |
| 123 | |
| 124 | return stop_sp; |
| 125 | } |
| 126 | |
| 127 | const BreakpointLocationSP |
| 128 | BreakpointLocationCollection::GetByIndex (uint32_t i) const |
| 129 | { |
| 130 | BreakpointLocationSP stop_sp; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 131 | if (i < m_break_loc_collection.size()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | stop_sp = m_break_loc_collection[i]; |
| 133 | |
| 134 | return stop_sp; |
| 135 | } |
| 136 | |
| 137 | bool |
| 138 | BreakpointLocationCollection::ShouldStop (StoppointCallbackContext *context) |
| 139 | { |
| 140 | bool shouldStop = false; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 141 | const size_t count = GetSize(); |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 142 | for (size_t i = 0; i < count; i++) |
| 143 | { |
| 144 | if (GetByIndex(i)->ShouldStop(context)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | shouldStop = true; |
| 146 | } |
| 147 | return shouldStop; |
| 148 | } |
| 149 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 150 | bool |
| 151 | BreakpointLocationCollection::ValidForThisThread (Thread *thread) |
| 152 | { |
| 153 | collection::iterator pos, |
| 154 | begin = m_break_loc_collection.begin(), |
| 155 | end = m_break_loc_collection.end(); |
| 156 | |
| 157 | for (pos = begin; pos != end; ++pos) |
| 158 | { |
| 159 | if ((*pos)->ValidForThisThread (thread)) |
| 160 | return true; |
| 161 | } |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | void |
| 167 | BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 168 | { |
| 169 | collection::iterator pos, |
| 170 | begin = m_break_loc_collection.begin(), |
| 171 | end = m_break_loc_collection.end(); |
| 172 | |
| 173 | for (pos = begin; pos != end; ++pos) |
| 174 | { |
| 175 | if (pos != begin) |
| 176 | s->PutChar(' '); |
| 177 | (*pos)->GetDescription(s, level); |
| 178 | } |
| 179 | } |