blob: e0ada3adde186e7838a057e8c43600d951ed6af1 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Clayton640dc6b2010-11-18 18:52:36 +000017#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Breakpoint/BreakpointLocation.h"
19#include "lldb/Breakpoint/BreakpointLocationList.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000020#include "lldb/Target/Thread.h"
21#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23using namespace lldb;
24using namespace lldb_private;
25
26//----------------------------------------------------------------------
27// BreakpointLocationCollection constructor
28//----------------------------------------------------------------------
29BreakpointLocationCollection::BreakpointLocationCollection() :
30 m_break_loc_collection()
31{
32}
33
34//----------------------------------------------------------------------
35// Destructor
36//----------------------------------------------------------------------
37BreakpointLocationCollection::~BreakpointLocationCollection()
38{
39}
40
41void
42BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc)
43{
44 BreakpointLocationSP old_bp_loc = FindByIDPair (bp_loc->GetBreakpoint().GetID(), bp_loc->GetID());
45 if (!old_bp_loc.get())
46 m_break_loc_collection.push_back(bp_loc);
47}
48
49bool
Greg Clayton54e7afa2010-07-09 20:39:50 +000050BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id)
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52 collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate
53 if (pos != m_break_loc_collection.end())
54 {
55 m_break_loc_collection.erase(pos);
56 return true;
57 }
58 return false;
59
60}
61
62class BreakpointIDPairMatches
63{
64public:
Greg Clayton54e7afa2010-07-09 20:39:50 +000065 BreakpointIDPairMatches (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) :
Chris Lattner24943d22010-06-08 16:52:24 +000066 m_break_id(break_id),
67 m_break_loc_id (break_loc_id)
68 {
69 }
70
71 bool operator() (const BreakpointLocationSP &bp_loc) const
72 {
73 return m_break_id == bp_loc->GetBreakpoint().GetID()
74 && m_break_loc_id == bp_loc->GetID();
75 }
76
77private:
Greg Clayton54e7afa2010-07-09 20:39:50 +000078 const lldb::break_id_t m_break_id;
79 const lldb::break_id_t m_break_loc_id;
Chris Lattner24943d22010-06-08 16:52:24 +000080};
81
82BreakpointLocationCollection::collection::iterator
Greg Clayton54e7afa2010-07-09 20:39:50 +000083BreakpointLocationCollection::GetIDPairIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Chris Lattner24943d22010-06-08 16:52:24 +000084{
85 return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range
86 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
87}
88
89BreakpointLocationCollection::collection::const_iterator
Greg Clayton54e7afa2010-07-09 20:39:50 +000090BreakpointLocationCollection::GetIDPairConstIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
Chris Lattner24943d22010-06-08 16:52:24 +000091{
92 return std::find_if(m_break_loc_collection.begin(), m_break_loc_collection.end(), // Search full range
93 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
94}
95
96BreakpointLocationSP
Greg Clayton54e7afa2010-07-09 20:39:50 +000097BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Chris Lattner24943d22010-06-08 16:52:24 +000098{
99 BreakpointLocationSP stop_sp;
100 collection::iterator pos = GetIDPairIterator(break_id, break_loc_id);
101 if (pos != m_break_loc_collection.end())
102 stop_sp = *pos;
103
104 return stop_sp;
105}
106
107const BreakpointLocationSP
Greg Clayton54e7afa2010-07-09 20:39:50 +0000108BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
Chris Lattner24943d22010-06-08 16:52:24 +0000109{
110 BreakpointLocationSP stop_sp;
111 collection::const_iterator pos = GetIDPairConstIterator(break_id, break_loc_id);
112 if (pos != m_break_loc_collection.end())
113 stop_sp = *pos;
114
115 return stop_sp;
116}
117
118BreakpointLocationSP
119BreakpointLocationCollection::GetByIndex (uint32_t i)
120{
121 BreakpointLocationSP stop_sp;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000122 if (i < m_break_loc_collection.size())
Chris Lattner24943d22010-06-08 16:52:24 +0000123 stop_sp = m_break_loc_collection[i];
124
125 return stop_sp;
126}
127
128const BreakpointLocationSP
129BreakpointLocationCollection::GetByIndex (uint32_t i) const
130{
131 BreakpointLocationSP stop_sp;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000132 if (i < m_break_loc_collection.size())
Chris Lattner24943d22010-06-08 16:52:24 +0000133 stop_sp = m_break_loc_collection[i];
134
135 return stop_sp;
136}
137
138bool
139BreakpointLocationCollection::ShouldStop (StoppointCallbackContext *context)
140{
141 bool shouldStop = false;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000142 const size_t count = GetSize();
Greg Clayton643ee732010-08-04 01:40:35 +0000143 for (size_t i = 0; i < count; i++)
144 {
145 if (GetByIndex(i)->ShouldStop(context))
Chris Lattner24943d22010-06-08 16:52:24 +0000146 shouldStop = true;
147 }
148 return shouldStop;
149}
150
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000151bool
152BreakpointLocationCollection::ValidForThisThread (Thread *thread)
153{
154 collection::iterator pos,
155 begin = m_break_loc_collection.begin(),
156 end = m_break_loc_collection.end();
157
158 for (pos = begin; pos != end; ++pos)
159 {
160 if ((*pos)->ValidForThisThread (thread))
161 return true;
162 }
163 return false;
164}
165
166
Chris Lattner24943d22010-06-08 16:52:24 +0000167void
168BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level)
169{
170 collection::iterator pos,
171 begin = m_break_loc_collection.begin(),
172 end = m_break_loc_collection.end();
173
174 for (pos = begin; pos != end; ++pos)
175 {
176 if (pos != begin)
177 s->PutChar(' ');
178 (*pos)->GetDescription(s, level);
179 }
180}