LLDB mainline
BreakpointLocationCollection.cpp
Go to the documentation of this file.
1//===-- BreakpointLocationCollection.cpp ----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13#include "lldb/Target/Thread.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19// BreakpointLocationCollection constructor
22
23// Destructor
25
27 std::lock_guard<std::mutex> guard(m_collection_mutex);
28 BreakpointLocationSP old_bp_loc =
29 FindByIDPair(bp_loc->GetBreakpoint().GetID(), bp_loc->GetID());
30 if (!old_bp_loc.get()) {
31 m_break_loc_collection.push_back(bp_loc);
33 lldb::break_id_t bp_loc_id = bp_loc->GetID();
34 Breakpoint &bkpt = bp_loc->GetBreakpoint();
35 lldb::break_id_t bp_id = bkpt.GetID();
36 std::pair<lldb::break_id_t, lldb::break_id_t> key =
37 std::make_pair(bp_id, bp_loc_id);
38 auto entry = m_preserved_bps.find(key);
39 if (entry == m_preserved_bps.end())
40 m_preserved_bps.emplace(key, bkpt.shared_from_this());
41 }
42 }
43}
44
46 lldb::break_id_t bp_loc_id) {
47 std::lock_guard<std::mutex> guard(m_collection_mutex);
48 collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate
49 if (pos != m_break_loc_collection.end()) {
51 std::pair<lldb::break_id_t, lldb::break_id_t> key =
52 std::make_pair(bp_id, bp_loc_id);
53 auto entry = m_preserved_bps.find(key);
54 if (entry == m_preserved_bps.end())
55 assert(0 && "Breakpoint added to collection but not preserving map.");
56 else
57 m_preserved_bps.erase(entry);
58 }
59 m_break_loc_collection.erase(pos);
60 return true;
61 }
62 return false;
63}
64
66public:
68 lldb::break_id_t break_loc_id)
69 : m_break_id(break_id), m_break_loc_id(break_loc_id) {}
70
71 bool operator()(const BreakpointLocationSP &bp_loc) const {
72 return m_break_id == bp_loc->GetBreakpoint().GetID() &&
73 m_break_loc_id == bp_loc->GetID();
74 }
75
76private:
79};
80
81BreakpointLocationCollection::collection::iterator
83 lldb::break_id_t break_loc_id) {
84 return llvm::find_if(
85 m_break_loc_collection, // Search full range
86 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
87}
88
89BreakpointLocationCollection::collection::const_iterator
91 lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const {
92 return llvm::find_if(
93 m_break_loc_collection, // Search full range
94 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
95}
96
99 lldb::break_id_t break_loc_id) {
100 BreakpointLocationSP stop_sp;
101 collection::iterator pos = GetIDPairIterator(break_id, break_loc_id);
102 if (pos != m_break_loc_collection.end())
103 stop_sp = *pos;
104
105 return stop_sp;
106}
107
109 lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const {
110 BreakpointLocationSP stop_sp;
111 collection::const_iterator pos =
112 GetIDPairConstIterator(break_id, break_loc_id);
113 if (pos != m_break_loc_collection.end())
114 stop_sp = *pos;
115
116 return stop_sp;
117}
118
120 std::lock_guard<std::mutex> guard(m_collection_mutex);
121 BreakpointLocationSP stop_sp;
122 if (i < m_break_loc_collection.size())
123 stop_sp = m_break_loc_collection[i];
124
125 return stop_sp;
126}
127
130 std::lock_guard<std::mutex> guard(m_collection_mutex);
131 BreakpointLocationSP stop_sp;
132 if (i < m_break_loc_collection.size())
133 stop_sp = m_break_loc_collection[i];
134
135 return stop_sp;
136}
137
140 BreakpointLocationCollection &stopped_bp_locs) {
141 bool shouldStop = false;
142 size_t i = 0;
143 size_t prev_size = GetSize();
144 while (i < prev_size) {
145 // ShouldStop can remove the breakpoint from the list, or even delete
146 // it, so we should
147 BreakpointLocationSP cur_loc_sp = GetByIndex(i);
148 BreakpointLocationSP reported_loc_sp;
149 BreakpointSP keep_bkpt_alive_sp = cur_loc_sp->GetBreakpoint().shared_from_this();
150 // We're building up the list or which locations claim responsibility for
151 // this stop. If the location's ShouldStop defers to a facade location by
152 // returning a non-null reported location, we want to use that. Otherwise
153 // use the original location.
154 if (cur_loc_sp->ShouldStop(context, reported_loc_sp)) {
155 if (reported_loc_sp)
156 stopped_bp_locs.Add(reported_loc_sp);
157 else
158 stopped_bp_locs.Add(cur_loc_sp);
159
160 shouldStop = true;
161 }
162
163 if (prev_size == GetSize())
164 i++;
165 prev_size = GetSize();
166 }
167 return shouldStop;
168}
169
171 std::lock_guard<std::mutex> guard(m_collection_mutex);
172 collection::iterator pos, begin = m_break_loc_collection.begin(),
173 end = m_break_loc_collection.end();
174
175 for (pos = begin; pos != end; ++pos) {
176 if ((*pos)->ValidForThisThread(thread))
177 return true;
178 }
179 return false;
180}
181
183 std::lock_guard<std::mutex> guard(m_collection_mutex);
184 collection::const_iterator pos, begin = m_break_loc_collection.begin(),
185 end = m_break_loc_collection.end();
186
187 bool is_internal = true;
188
189 for (pos = begin; pos != end; ++pos) {
190 if (!(*pos)->GetBreakpoint().IsInternal()) {
191 is_internal = false;
192 break;
193 }
194 }
195 return is_internal;
196}
197
199 Stream *s, lldb::DescriptionLevel level) {
200 std::lock_guard<std::mutex> guard(m_collection_mutex);
201 collection::iterator pos, begin = m_break_loc_collection.begin(),
202 end = m_break_loc_collection.end();
203
204 for (pos = begin; pos != end; ++pos) {
205 if (pos != begin)
206 s->PutChar(' ');
207 (*pos)->GetDescription(s, level);
208 }
209}
210
212 const BreakpointLocationCollection &rhs) {
213 if (this != &rhs) {
215 std::lock_guard<std::mutex> lhs_guard(m_collection_mutex, std::adopt_lock);
216 std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex, std::adopt_lock);
218 }
219 return *this;
220}
BreakpointIDPairMatches(lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
bool operator()(const BreakpointLocationSP &bp_loc) const
lldb::BreakpointLocationSP FindByIDPair(lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Returns a shared pointer to the breakpoint location with id breakID.
BreakpointLocationCollection(bool preserving=false)
Breakpoint locations don't keep their breakpoint owners alive, so neither will a collection of breakp...
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Print a description of the breakpoint locations in this list to the stream s.
std::map< std::pair< lldb::break_id_t, lldb::break_id_t >, lldb::BreakpointSP > m_preserved_bps
bool IsInternal() const
Tell whether ALL the breakpoints in the location collection are internal.
bool ValidForThisThread(Thread &thread)
Check whether this collection of breakpoint locations have any thread specifiers, and if yes,...
collection::const_iterator GetIDPairConstIterator(lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const
BreakpointLocationCollection & operator=(const BreakpointLocationCollection &rhs)
collection::iterator GetIDPairIterator(lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
lldb::BreakpointLocationSP GetByIndex(size_t i)
Returns a shared pointer to the breakpoint location with index i.
bool ShouldStop(StoppointCallbackContext *context, BreakpointLocationCollection &stopped_bp_locs)
Enquires of all the breakpoint locations in this list whether we should stop at a hit at breakID.
void Add(const lldb::BreakpointLocationSP &bp_loc_sp)
Add the breakpoint bp_loc_sp to the list.
bool Remove(lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
Removes the breakpoint location given by breakID from this list.
size_t GetSize() const
Returns the number of elements in this breakpoint location list.
const bool m_preserving_bkpts
These are used if we're preserving breakpoints in this list:
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition Breakpoint.h:81
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
lldb::break_id_t GetID() const
Definition Stoppoint.cpp:22
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutChar(char ch)
Definition Stream.cpp:131
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
int32_t break_id_t
Definition lldb-types.h:86