blob: 52698b2f15bbb03e3527d4317f2359bce670f6da [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Clayton4e78f602010-11-18 18:52:36 +000017#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Breakpoint/BreakpointLocation.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000019#include "lldb/Target/Thread.h"
20#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22using namespace lldb;
23using namespace lldb_private;
24
25//----------------------------------------------------------------------
26// BreakpointLocationCollection constructor
27//----------------------------------------------------------------------
28BreakpointLocationCollection::BreakpointLocationCollection() :
Jim Ingham1cf8f592016-05-26 23:55:04 +000029 m_break_loc_collection(),
30 m_collection_mutex()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031{
32}
33
34//----------------------------------------------------------------------
35// Destructor
36//----------------------------------------------------------------------
37BreakpointLocationCollection::~BreakpointLocationCollection()
38{
39}
40
41void
42BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc)
43{
Jim Ingham1cf8f592016-05-26 23:55:04 +000044 std::lock_guard<std::mutex> guard(m_collection_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045 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
50bool
Greg Claytonc982c762010-07-09 20:39:50 +000051BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052{
Jim Ingham1cf8f592016-05-26 23:55:04 +000053 std::lock_guard<std::mutex> guard(m_collection_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054 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
64class BreakpointIDPairMatches
65{
66public:
Greg Claytonc982c762010-07-09 20:39:50 +000067 BreakpointIDPairMatches (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 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
79private:
Greg Claytonc982c762010-07-09 20:39:50 +000080 const lldb::break_id_t m_break_id;
81 const lldb::break_id_t m_break_loc_id;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082};
83
84BreakpointLocationCollection::collection::iterator
Greg Claytonc982c762010-07-09 20:39:50 +000085BreakpointLocationCollection::GetIDPairIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086{
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
91BreakpointLocationCollection::collection::const_iterator
Greg Claytonc982c762010-07-09 20:39:50 +000092BreakpointLocationCollection::GetIDPairConstIterator (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093{
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
98BreakpointLocationSP
Greg Claytonc982c762010-07-09 20:39:50 +000099BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100{
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
109const BreakpointLocationSP
Greg Claytonc982c762010-07-09 20:39:50 +0000110BreakpointLocationCollection::FindByIDPair (lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111{
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
120BreakpointLocationSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000121BreakpointLocationCollection::GetByIndex (size_t i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122{
Jim Ingham1cf8f592016-05-26 23:55:04 +0000123 std::lock_guard<std::mutex> guard(m_collection_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124 BreakpointLocationSP stop_sp;
Greg Claytonc982c762010-07-09 20:39:50 +0000125 if (i < m_break_loc_collection.size())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126 stop_sp = m_break_loc_collection[i];
127
128 return stop_sp;
129}
130
131const BreakpointLocationSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000132BreakpointLocationCollection::GetByIndex (size_t i) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133{
Jim Ingham1cf8f592016-05-26 23:55:04 +0000134 std::lock_guard<std::mutex> guard(m_collection_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 BreakpointLocationSP stop_sp;
Greg Claytonc982c762010-07-09 20:39:50 +0000136 if (i < m_break_loc_collection.size())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 stop_sp = m_break_loc_collection[i];
138
139 return stop_sp;
140}
141
142bool
143BreakpointLocationCollection::ShouldStop (StoppointCallbackContext *context)
144{
145 bool shouldStop = false;
Tamas Berghammer729dcfb2015-05-27 09:46:47 +0000146 size_t i = 0;
147 size_t prev_size = GetSize();
148 while (i < prev_size)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000149 {
Tamas Berghammer729dcfb2015-05-27 09:46:47 +0000150 // ShouldStop can remove the breakpoint from the list
Greg Claytonf4b47e12010-08-04 01:40:35 +0000151 if (GetByIndex(i)->ShouldStop(context))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152 shouldStop = true;
Tamas Berghammer729dcfb2015-05-27 09:46:47 +0000153
154 if (prev_size == GetSize())
155 i++;
156 prev_size = GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157 }
158 return shouldStop;
159}
160
Jim Ingham1b54c882010-06-16 02:00:15 +0000161bool
162BreakpointLocationCollection::ValidForThisThread (Thread *thread)
163{
Jim Ingham1cf8f592016-05-26 23:55:04 +0000164 std::lock_guard<std::mutex> guard(m_collection_mutex);
Jim Ingham1b54c882010-06-16 02:00:15 +0000165 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 Ingham29950772013-01-26 02:19:28 +0000177bool
178BreakpointLocationCollection::IsInternal () const
179{
Jim Ingham1cf8f592016-05-26 23:55:04 +0000180 std::lock_guard<std::mutex> guard(m_collection_mutex);
Jim Ingham29950772013-01-26 02:19:28 +0000181 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 Ingham1b54c882010-06-16 02:00:15 +0000197
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198void
199BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level)
200{
Jim Ingham1cf8f592016-05-26 23:55:04 +0000201 std::lock_guard<std::mutex> guard(m_collection_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 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 Inghama672ece2014-10-22 01:54:17 +0000213