LLDB mainline
BreakpointList.cpp
Go to the documentation of this file.
1//===-- BreakpointList.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/Target/Target.h"
12
13#include "llvm/Support/Errc.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
18static void NotifyChange(const BreakpointSP &bp, BreakpointEventType event) {
19 bp->GetTarget().NotifyBreakpointChanged(*bp, event);
20}
21
23 : m_next_break_id(0), m_is_internal(is_internal) {}
24
26
28 std::lock_guard<std::recursive_mutex> guard(m_mutex);
29
30 // Internal breakpoint IDs are negative, normal ones are positive
31 bp_sp->SetID(m_is_internal ? --m_next_break_id : ++m_next_break_id);
32
33 m_breakpoints.push_back(bp_sp);
34
35 if (notify)
36 NotifyChange(bp_sp, eBreakpointEventTypeAdded);
37
38 return bp_sp->GetID();
39}
40
41bool BreakpointList::Remove(break_id_t break_id, bool notify) {
42 std::lock_guard<std::recursive_mutex> guard(m_mutex);
43
44 auto it = llvm::find_if(m_breakpoints, [&](const BreakpointSP &bp) {
45 return bp->GetID() == break_id;
46 });
47
48 if (it == m_breakpoints.end())
49 return false;
50
51 if (notify)
52 NotifyChange(*it, eBreakpointEventTypeRemoved);
53
54 m_breakpoints.erase(it);
55
56 return true;
57}
58
60 std::lock_guard<std::recursive_mutex> guard(m_mutex);
61 for (const auto &bp_sp : m_breakpoints)
62 bp_sp->RemoveInvalidLocations(arch);
63}
64
66 std::lock_guard<std::recursive_mutex> guard(m_mutex);
67 for (const auto &bp_sp : m_breakpoints)
68 bp_sp->SetEnabled(enabled);
69}
70
72 std::lock_guard<std::recursive_mutex> guard(m_mutex);
73 for (const auto &bp_sp : m_breakpoints)
74 if (bp_sp->AllowDisable())
75 bp_sp->SetEnabled(enabled);
76}
77
78void BreakpointList::RemoveAll(bool notify) {
79 std::lock_guard<std::recursive_mutex> guard(m_mutex);
81
82 if (notify) {
83 for (const auto &bp_sp : m_breakpoints)
84 NotifyChange(bp_sp, eBreakpointEventTypeRemoved);
85 }
86
87 m_breakpoints.clear();
88}
89
91 std::lock_guard<std::recursive_mutex> guard(m_mutex);
92
93 for (const auto &bp_sp : m_breakpoints) {
94 if (bp_sp->AllowDelete())
95 bp_sp->ClearAllBreakpointSites();
96 if (notify)
97 NotifyChange(bp_sp, eBreakpointEventTypeRemoved);
98 }
99
100 llvm::erase_if(m_breakpoints,
101 [&](const BreakpointSP &bp) { return bp->AllowDelete(); });
102}
103
104BreakpointList::bp_collection::iterator
106 return llvm::find_if(m_breakpoints, [&](const BreakpointSP &bp) {
107 return bp->GetID() == break_id;
108 });
109}
110
111BreakpointList::bp_collection::const_iterator
113 return llvm::find_if(m_breakpoints, [&](const BreakpointSP &bp) {
114 return bp->GetID() == break_id;
115 });
116}
117
119 std::lock_guard<std::recursive_mutex> guard(m_mutex);
120
121 auto it = GetBreakpointIDConstIterator(break_id);
122 if (it != m_breakpoints.end())
123 return *it;
124 return {};
125}
126
127llvm::Expected<std::vector<lldb::BreakpointSP>>
129 if (!name)
130 return llvm::createStringError(llvm::errc::invalid_argument,
131 "FindBreakpointsByName requires a name");
132
134 if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(name), error))
135 return error.ToError();
136
137 std::vector<lldb::BreakpointSP> matching_bps;
138 for (BreakpointSP bkpt_sp : Breakpoints()) {
139 if (bkpt_sp->MatchesName(name)) {
140 matching_bps.push_back(bkpt_sp);
141 }
142 }
143
144 return matching_bps;
145}
146
148 std::lock_guard<std::recursive_mutex> guard(m_mutex);
149 s->Printf("%p: ", static_cast<const void *>(this));
150 s->Indent();
151 s->Printf("BreakpointList with %u Breakpoints:\n",
152 (uint32_t)m_breakpoints.size());
153 s->IndentMore();
154 for (const auto &bp_sp : m_breakpoints)
155 bp_sp->Dump(s);
156 s->IndentLess();
157}
158
160 std::lock_guard<std::recursive_mutex> guard(m_mutex);
161 if (i < m_breakpoints.size())
162 return m_breakpoints[i];
163 return {};
164}
165
166void BreakpointList::UpdateBreakpoints(ModuleList &module_list, bool added,
167 bool delete_locations) {
168 std::lock_guard<std::recursive_mutex> guard(m_mutex);
169 for (const auto &bp_sp : m_breakpoints)
170 bp_sp->ModulesChanged(module_list, added, delete_locations);
171}
172
174 ModuleSP old_module_sp, ModuleSP new_module_sp) {
175 std::lock_guard<std::recursive_mutex> guard(m_mutex);
176 for (const auto &bp_sp : m_breakpoints)
177 bp_sp->ModuleReplaced(old_module_sp, new_module_sp);
178}
179
181 std::lock_guard<std::recursive_mutex> guard(m_mutex);
182 for (const auto &bp_sp : m_breakpoints)
183 bp_sp->ClearAllBreakpointSites();
184}
185
187 std::lock_guard<std::recursive_mutex> guard(m_mutex);
188 for (const auto &bp_sp : m_breakpoints)
189 bp_sp->ResetHitCount();
190}
191
193 std::unique_lock<std::recursive_mutex> &lock) {
194 lock = std::unique_lock<std::recursive_mutex>(m_mutex);
195}
static void NotifyChange(const BreakpointSP &bp, BreakpointEventType event)
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition ArchSpec.h:31
static bool StringIsBreakpointName(llvm::StringRef str, Status &error)
Takes an input string and checks to see whether it is a breakpoint name.
BreakpointIterable Breakpoints()
void RemoveInvalidLocations(const ArchSpec &arch)
Removes all invalid breakpoint locations.
lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const
Returns a shared pointer to the breakpoint with id breakID.
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Breakpoint List mutex.
bp_collection::const_iterator GetBreakpointIDConstIterator(lldb::break_id_t breakID) const
lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify)
Add the breakpoint bp_sp to the list.
void SetEnabledAllowed(bool enabled)
bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID)
void ResetHitCounts()
Resets the hit count of all breakpoints.
void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp, lldb::ModuleSP new_module_sp)
void RemoveAll(bool notify)
Removes all the breakpoints from this list.
void UpdateBreakpoints(ModuleList &module_list, bool load, bool delete_locations)
Tell all the breakpoints to update themselves due to a change in the modules in module_list.
std::recursive_mutex m_mutex
llvm::Expected< std::vector< lldb::BreakpointSP > > FindBreakpointsByName(const char *name)
Find all the breakpoints with a given name.
void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
bool Remove(lldb::break_id_t breakID, bool notify)
Removes the breakpoint given by breakID from this list.
void RemoveAllowed(bool notify)
Removes all the breakpoints from this list - first checking the ePermDelete on the breakpoints.
lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const
Returns a shared pointer to the breakpoint with index i.
void SetEnabledAll(bool enabled)
A collection class for Module objects.
Definition ModuleList.h:104
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:195
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
int32_t break_id_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::Module > ModuleSP