1 //===-- BreakpointLocationCollection.cpp ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
13 // Other libraries and framework includes
15 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
16 #include "lldb/Core/ModuleList.h"
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Target/Thread.h"
20 #include "lldb/Target/ThreadSpec.h"
23 using namespace lldb_private;
25 //----------------------------------------------------------------------
26 // BreakpointLocationCollection constructor
27 //----------------------------------------------------------------------
28 BreakpointLocationCollection::BreakpointLocationCollection() :
29 m_break_loc_collection()
33 //----------------------------------------------------------------------
35 //----------------------------------------------------------------------
36 BreakpointLocationCollection::~BreakpointLocationCollection()
41 BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc)
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);
49 BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id)
51 collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate
52 if (pos != m_break_loc_collection.end())
54 m_break_loc_collection.erase(pos);
61 class BreakpointIDPairMatches
64 BreakpointIDPairMatches (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) :
66 m_break_loc_id (break_loc_id)
70 bool operator() (const BreakpointLocationSP &bp_loc) const
72 return m_break_id == bp_loc->GetBreakpoint().GetID()
73 && m_break_loc_id == bp_loc->GetID();
77 const lldb::break_id_t m_break_id;
78 const lldb::break_id_t m_break_loc_id;
81 BreakpointLocationCollection::collection::iterator
82 BreakpointLocationCollection::GetIDPairIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
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
88 BreakpointLocationCollection::collection::const_iterator
89 BreakpointLocationCollection::GetIDPairConstIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
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
96 BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
98 BreakpointLocationSP stop_sp;
99 collection::iterator pos = GetIDPairIterator(break_id, break_loc_id);
100 if (pos != m_break_loc_collection.end())
106 const BreakpointLocationSP
107 BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
109 BreakpointLocationSP stop_sp;
110 collection::const_iterator pos = GetIDPairConstIterator(break_id, break_loc_id);
111 if (pos != m_break_loc_collection.end())
118 BreakpointLocationCollection::GetByIndex (size_t i)
120 BreakpointLocationSP stop_sp;
121 if (i < m_break_loc_collection.size())
122 stop_sp = m_break_loc_collection[i];
127 const BreakpointLocationSP
128 BreakpointLocationCollection::GetByIndex (size_t i) const
130 BreakpointLocationSP stop_sp;
131 if (i < m_break_loc_collection.size())
132 stop_sp = m_break_loc_collection[i];
138 BreakpointLocationCollection::ShouldStop (StoppointCallbackContext *context)
140 bool shouldStop = false;
141 const size_t count = GetSize();
142 for (size_t i = 0; i < count; i++)
144 if (GetByIndex(i)->ShouldStop(context))
151 BreakpointLocationCollection::ValidForThisThread (Thread *thread)
153 collection::iterator pos,
154 begin = m_break_loc_collection.begin(),
155 end = m_break_loc_collection.end();
157 for (pos = begin; pos != end; ++pos)
159 if ((*pos)->ValidForThisThread (thread))
166 BreakpointLocationCollection::IsInternal () const
168 collection::const_iterator pos,
169 begin = m_break_loc_collection.begin(),
170 end = m_break_loc_collection.end();
172 bool is_internal = true;
174 for (pos = begin; pos != end; ++pos)
176 if (!(*pos)->GetBreakpoint().IsInternal ())
186 BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level)
188 collection::iterator pos,
189 begin = m_break_loc_collection.begin(),
190 end = m_break_loc_collection.end();
192 for (pos = begin; pos != end; ++pos)
196 (*pos)->GetDescription(s, level);