1 //===-- BreakpointList.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_BreakpointList_h_
11 #define liblldb_BreakpointList_h_
16 #include "lldb/Breakpoint/Breakpoint.h"
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 /// @class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
22 /// This class manages a list of breakpoints.
23 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
27 /// Allows adding and removing breakpoints and find by ID and index.
28 //----------------------------------------------------------------------
30 class BreakpointList {
32 BreakpointList(bool is_internal);
36 //------------------------------------------------------------------
37 /// Add the breakpoint \a bp_sp to the list.
40 /// Shared pointer to the breakpoint that will get added to the list.
43 /// Returns breakpoint id.
44 //------------------------------------------------------------------
45 lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify);
47 //------------------------------------------------------------------
48 /// Standard "Dump" method. At present it does nothing.
49 //------------------------------------------------------------------
50 void Dump(Stream *s) const;
52 //------------------------------------------------------------------
53 /// Returns a shared pointer to the breakpoint with id \a breakID. Const
56 /// @param[in] breakID
57 /// The breakpoint ID to seek for.
60 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
61 /// breakpoint doesn't exist.
62 //------------------------------------------------------------------
63 lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const;
65 //------------------------------------------------------------------
66 /// Returns a shared pointer to the breakpoint with index \a i.
69 /// The breakpoint index to seek for.
72 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
73 /// breakpoint doesn't exist.
74 //------------------------------------------------------------------
75 lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const;
77 //------------------------------------------------------------------
78 /// Find all the breakpoints with a given name
81 /// The breakpoint name for which to search.
84 /// \bfalse if the input name was not a legal breakpoint name.
85 //------------------------------------------------------------------
86 bool FindBreakpointsByName(const char *name, BreakpointList &matching_bps);
88 //------------------------------------------------------------------
89 /// Returns the number of elements in this breakpoint list.
92 /// The number of elements.
93 //------------------------------------------------------------------
94 size_t GetSize() const {
95 std::lock_guard<std::recursive_mutex> guard(m_mutex);
96 return m_breakpoints.size();
99 //------------------------------------------------------------------
100 /// Removes the breakpoint given by \b breakID from this list.
102 /// @param[in] breakID
103 /// The breakpoint index to remove.
106 /// \b true if the breakpoint \a breakID was in the list.
107 //------------------------------------------------------------------
108 bool Remove(lldb::break_id_t breakID, bool notify);
110 //------------------------------------------------------------------
111 /// Removes all invalid breakpoint locations.
113 /// Removes all breakpoint locations in the list with architectures that
114 /// aren't compatible with \a arch. Also remove any breakpoint locations
115 /// with whose locations have address where the section has been deleted
116 /// (module and object files no longer exist).
118 /// This is typically used after the process calls exec, or anytime the
119 /// architecture of the target changes.
122 /// If valid, check the module in each breakpoint to make sure
123 /// they are compatible, otherwise, ignore architecture.
124 //------------------------------------------------------------------
125 void RemoveInvalidLocations(const ArchSpec &arch);
127 void SetEnabledAll(bool enabled);
129 void SetEnabledAllowed(bool enabled);
131 //------------------------------------------------------------------
132 /// Removes all the breakpoints from this list.
133 //------------------------------------------------------------------
134 void RemoveAll(bool notify);
136 //------------------------------------------------------------------
137 /// Removes all the breakpoints from this list - first checking the
138 /// ePermDelete on the breakpoints. This call should be used unless you are
139 /// shutting down and need to actually clear them all.
140 //------------------------------------------------------------------
141 void RemoveAllowed(bool notify);
143 //------------------------------------------------------------------
144 /// Tell all the breakpoints to update themselves due to a change in the
145 /// modules in \a module_list. \a added says whether the module was loaded
148 /// @param[in] module_list
149 /// The module list that has changed.
152 /// \b true if the modules are loaded, \b false if unloaded.
154 /// @param[in] delete_locations
155 /// If \a load is \b false, then delete breakpoint locations when
156 /// when updating breakpoints.
157 //------------------------------------------------------------------
158 void UpdateBreakpoints(ModuleList &module_list, bool load,
159 bool delete_locations);
161 void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp,
162 lldb::ModuleSP new_module_sp);
164 void ClearAllBreakpointSites();
166 //------------------------------------------------------------------
167 /// Sets the passed in Locker to hold the Breakpoint List mutex.
169 /// @param[in] locker
170 /// The locker object that is set.
171 //------------------------------------------------------------------
172 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
175 typedef std::vector<lldb::BreakpointSP> bp_collection;
177 bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID);
179 bp_collection::const_iterator
180 GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
182 std::recursive_mutex &GetMutex() const { return m_mutex; }
184 mutable std::recursive_mutex m_mutex;
185 bp_collection m_breakpoints;
186 lldb::break_id_t m_next_break_id;
190 typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
191 list_adapter, std::recursive_mutex>
193 BreakpointIterable Breakpoints() {
194 return BreakpointIterable(m_breakpoints, GetMutex());
198 DISALLOW_COPY_AND_ASSIGN(BreakpointList);
201 } // namespace lldb_private
203 #endif // liblldb_BreakpointList_h_