1 //===-- BreakpointList.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_BreakpointList_h_
10 #define liblldb_BreakpointList_h_
15 #include "lldb/Breakpoint/Breakpoint.h"
17 namespace lldb_private {
19 /// \class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
20 /// This class manages a list of breakpoints.
23 /// Allows adding and removing breakpoints and find by ID and index.
25 class BreakpointList {
27 BreakpointList(bool is_internal);
31 /// Add the breakpoint \a bp_sp to the list.
34 /// Shared pointer to the breakpoint that will get added to the list.
37 /// Returns breakpoint id.
38 lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify);
40 /// Standard "Dump" method. At present it does nothing.
41 void Dump(Stream *s) const;
43 /// Returns a shared pointer to the breakpoint with id \a breakID. Const
46 /// \param[in] breakID
47 /// The breakpoint ID to seek for.
50 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
51 /// breakpoint doesn't exist.
52 lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const;
54 /// Returns a shared pointer to the breakpoint with index \a i.
57 /// The breakpoint index to seek for.
60 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
61 /// breakpoint doesn't exist.
62 lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const;
64 /// Find all the breakpoints with a given name
67 /// The breakpoint name for which to search.
70 /// \bfalse if the input name was not a legal breakpoint name.
71 bool FindBreakpointsByName(const char *name, BreakpointList &matching_bps);
73 /// Returns the number of elements in this breakpoint list.
76 /// The number of elements.
77 size_t GetSize() const {
78 std::lock_guard<std::recursive_mutex> guard(m_mutex);
79 return m_breakpoints.size();
82 /// Removes the breakpoint given by \b breakID from this list.
84 /// \param[in] breakID
85 /// The breakpoint index to remove.
88 /// \b true if the breakpoint \a breakID was in the list.
89 bool Remove(lldb::break_id_t breakID, bool notify);
91 /// Removes all invalid breakpoint locations.
93 /// Removes all breakpoint locations in the list with architectures that
94 /// aren't compatible with \a arch. Also remove any breakpoint locations
95 /// with whose locations have address where the section has been deleted
96 /// (module and object files no longer exist).
98 /// This is typically used after the process calls exec, or anytime the
99 /// architecture of the target changes.
102 /// If valid, check the module in each breakpoint to make sure
103 /// they are compatible, otherwise, ignore architecture.
104 void RemoveInvalidLocations(const ArchSpec &arch);
106 void SetEnabledAll(bool enabled);
108 void SetEnabledAllowed(bool enabled);
110 /// Removes all the breakpoints from this list.
111 void RemoveAll(bool notify);
113 /// Removes all the breakpoints from this list - first checking the
114 /// ePermDelete on the breakpoints. This call should be used unless you are
115 /// shutting down and need to actually clear them all.
116 void RemoveAllowed(bool notify);
118 /// Tell all the breakpoints to update themselves due to a change in the
119 /// modules in \a module_list. \a added says whether the module was loaded
122 /// \param[in] module_list
123 /// The module list that has changed.
126 /// \b true if the modules are loaded, \b false if unloaded.
128 /// \param[in] delete_locations
129 /// If \a load is \b false, then delete breakpoint locations when
130 /// when updating breakpoints.
131 void UpdateBreakpoints(ModuleList &module_list, bool load,
132 bool delete_locations);
134 void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp,
135 lldb::ModuleSP new_module_sp);
137 void ClearAllBreakpointSites();
139 /// Sets the passed in Locker to hold the Breakpoint List mutex.
141 /// \param[in] locker
142 /// The locker object that is set.
143 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
146 typedef std::vector<lldb::BreakpointSP> bp_collection;
148 bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID);
150 bp_collection::const_iterator
151 GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
153 std::recursive_mutex &GetMutex() const { return m_mutex; }
155 mutable std::recursive_mutex m_mutex;
156 bp_collection m_breakpoints;
157 lldb::break_id_t m_next_break_id;
161 typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
162 list_adapter, std::recursive_mutex>
164 BreakpointIterable Breakpoints() {
165 return BreakpointIterable(m_breakpoints, GetMutex());
169 DISALLOW_COPY_AND_ASSIGN(BreakpointList);
172 } // namespace lldb_private
174 #endif // liblldb_BreakpointList_h_