LLDB mainline
BreakpointSiteList.cpp
Go to the documentation of this file.
1//===-- BreakpointSiteList.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
10
11#include "lldb/Utility/Stream.h"
12#include <algorithm>
13
14using namespace lldb;
15using namespace lldb_private;
16
18
20
21// Add breakpoint site to the list. However, if the element already exists in
22// the list, then we don't add it, and return LLDB_INVALID_BREAK_ID.
23
25 lldb::addr_t bp_site_load_addr = bp->GetLoadAddress();
26 std::lock_guard<std::recursive_mutex> guard(m_mutex);
27 collection::iterator iter = m_bp_site_list.find(bp_site_load_addr);
28
29 if (iter == m_bp_site_list.end()) {
30 m_bp_site_list.insert(iter, collection::value_type(bp_site_load_addr, bp));
31 return bp->GetID();
32 } else {
34 }
35}
36
38 lldb::break_id_t site_id) {
39 BreakpointSiteSP site_sp(FindByID(site_id));
40 if (site_sp) {
41 // Let the BreakpointSite decide if it should stop here (could not have
42 // reached it's target hit count yet, or it could have a callback that
43 // decided it shouldn't stop (shared library loads/unloads).
44 return site_sp->ShouldStop(context);
45 }
46 // We should stop here since this BreakpointSite isn't valid anymore or it
47 // doesn't exist.
48 return true;
49}
51 if (BreakpointSiteSP bp = FindByAddress(addr))
52 return bp.get()->GetID();
54}
55
57 std::lock_guard<std::recursive_mutex> guard(m_mutex);
58 collection::iterator pos = GetIDIterator(break_id); // Predicate
59 if (pos != m_bp_site_list.end()) {
60 m_bp_site_list.erase(pos);
61 return true;
62 }
63 return false;
64}
65
67 std::lock_guard<std::recursive_mutex> guard(m_mutex);
68 collection::iterator pos = m_bp_site_list.find(address);
69 if (pos != m_bp_site_list.end()) {
70 m_bp_site_list.erase(pos);
71 return true;
72 }
73 return false;
74}
75
77public:
78 BreakpointSiteIDMatches(lldb::break_id_t break_id) : m_break_id(break_id) {}
79
80 bool operator()(std::pair<lldb::addr_t, BreakpointSiteSP> val_pair) const {
81 return m_break_id == val_pair.second->GetID();
82 }
83
84private:
86};
87
88BreakpointSiteList::collection::iterator
90 std::lock_guard<std::recursive_mutex> guard(m_mutex);
91 return std::find_if(m_bp_site_list.begin(),
92 m_bp_site_list.end(), // Search full range
93 BreakpointSiteIDMatches(break_id)); // Predicate
94}
95
96BreakpointSiteList::collection::const_iterator
98 std::lock_guard<std::recursive_mutex> guard(m_mutex);
99 return std::find_if(m_bp_site_list.begin(),
100 m_bp_site_list.end(), // Search full range
101 BreakpointSiteIDMatches(break_id)); // Predicate
102}
103
105 std::lock_guard<std::recursive_mutex> guard(m_mutex);
106 BreakpointSiteSP stop_sp;
107 collection::iterator pos = GetIDIterator(break_id);
108 if (pos != m_bp_site_list.end())
109 stop_sp = pos->second;
110
111 return stop_sp;
112}
113
116 std::lock_guard<std::recursive_mutex> guard(m_mutex);
117 BreakpointSiteSP stop_sp;
118 collection::const_iterator pos = GetIDConstIterator(break_id);
119 if (pos != m_bp_site_list.end())
120 stop_sp = pos->second;
121
122 return stop_sp;
123}
124
126 BreakpointSiteSP found_sp;
127 std::lock_guard<std::recursive_mutex> guard(m_mutex);
128 collection::iterator iter = m_bp_site_list.find(addr);
129 if (iter != m_bp_site_list.end())
130 found_sp = iter->second;
131 return found_sp;
132}
133
135 lldb::break_id_t bp_site_id, lldb::break_id_t bp_id) {
136 std::lock_guard<std::recursive_mutex> guard(m_mutex);
137 collection::const_iterator pos = GetIDConstIterator(bp_site_id);
138 if (pos != m_bp_site_list.end())
139 return pos->second->IsBreakpointAtThisSite(bp_id);
140
141 return false;
142}
143
145 s->Printf("%p: ", static_cast<const void *>(this));
146 // s->Indent();
147 s->Printf("BreakpointSiteList with %u BreakpointSites:\n",
148 (uint32_t)m_bp_site_list.size());
149 s->IndentMore();
150 collection::const_iterator pos;
151 collection::const_iterator end = m_bp_site_list.end();
152 for (pos = m_bp_site_list.begin(); pos != end; ++pos)
153 pos->second->Dump(s);
154 s->IndentLess();
155}
156
158 std::function<void(BreakpointSite *)> const &callback) {
159 std::lock_guard<std::recursive_mutex> guard(m_mutex);
160 for (auto pair : m_bp_site_list)
161 callback(pair.second.get());
162}
163
165 lldb::addr_t upper_bound,
166 BreakpointSiteList &bp_site_list) const {
167 if (lower_bound > upper_bound)
168 return false;
169
170 std::lock_guard<std::recursive_mutex> guard(m_mutex);
171 collection::const_iterator lower, upper, pos;
172 lower = m_bp_site_list.lower_bound(lower_bound);
173 if (lower == m_bp_site_list.end() || (*lower).first >= upper_bound)
174 return false;
175
176 // This is one tricky bit. The breakpoint might overlap the bottom end of
177 // the range. So we grab the breakpoint prior to the lower bound, and check
178 // that that + its byte size isn't in our range.
179 if (lower != m_bp_site_list.begin()) {
180 collection::const_iterator prev_pos = lower;
181 prev_pos--;
182 const BreakpointSiteSP &prev_bp = (*prev_pos).second;
183 if (prev_bp->GetLoadAddress() + prev_bp->GetByteSize() > lower_bound)
184 bp_site_list.Add(prev_bp);
185 }
186
187 upper = m_bp_site_list.upper_bound(upper_bound);
188
189 for (pos = lower; pos != upper; pos++) {
190 bp_site_list.Add((*pos).second);
191 }
192 return true;
193}
BreakpointSiteIDMatches(lldb::break_id_t break_id)
bool operator()(std::pair< lldb::addr_t, BreakpointSiteSP > val_pair) const
const lldb::break_id_t m_break_id
"lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of BreakpointSite shared pointers.
void Dump(Stream *s) const
Standard Dump routine, doesn't do anything at present.
BreakpointSiteList()
Default constructor makes an empty list.
bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound, BreakpointSiteList &bp_site_list) const
collection::iterator GetIDIterator(lldb::break_id_t breakID)
bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id, lldb::break_id_t bp_id)
Returns whether the breakpoint site bp_site_id has bp_id.
~BreakpointSiteList()
Destructor, currently does nothing.
lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr)
Returns a shared pointer to the breakpoint site at address addr.
lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID)
Returns a shared pointer to the breakpoint site with id breakID.
collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const
lldb::break_id_t FindIDByAddress(lldb::addr_t addr)
Returns the breakpoint site id to the breakpoint site at address addr.
bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID)
Enquires of the breakpoint site on in this list with ID breakID whether we should stop for the breakp...
void ForEach(std::function< void(BreakpointSite *)> const &callback)
bool Remove(lldb::break_id_t breakID)
Removes the breakpoint site given by breakID from this list.
bool RemoveByAddress(lldb::addr_t addr)
Removes the breakpoint site at address addr from this list.
lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp)
Add a BreakpointSite to the list.
Class that manages the actual breakpoint that will be inserted into the running program.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:171
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:168
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
Definition: lldb-forward.h:305
int32_t break_id_t
Definition: lldb-types.h:84
uint64_t addr_t
Definition: lldb-types.h:79