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_
18 // Other libraries and framework includes
20 #include "lldb/Breakpoint/Breakpoint.h"
22 namespace lldb_private {
24 //----------------------------------------------------------------------
25 /// @class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
26 /// @brief This class manages a list of breakpoints.
27 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
31 /// Allows adding and removing breakpoints and find by ID and index.
32 //----------------------------------------------------------------------
34 class BreakpointList {
36 BreakpointList(bool is_internal);
40 //------------------------------------------------------------------
41 /// Add the breakpoint \a bp_sp to the list.
44 /// Shared pointer to the breakpoint that will get added to the list.
47 /// Returns breakpoint id.
48 //------------------------------------------------------------------
49 lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify);
51 //------------------------------------------------------------------
52 /// Standard "Dump" method. At present it does nothing.
53 //------------------------------------------------------------------
54 void Dump(Stream *s) const;
56 //------------------------------------------------------------------
57 /// Returns a shared pointer to the breakpoint with id \a breakID.
59 /// @param[in] breakID
60 /// The breakpoint ID to seek for.
63 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
64 /// breakpoint doesn't exist.
65 //------------------------------------------------------------------
66 lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID);
68 //------------------------------------------------------------------
69 /// Returns a shared pointer to the breakpoint with id \a breakID. Const
72 /// @param[in] breakID
73 /// The breakpoint ID to seek for.
76 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
77 /// breakpoint doesn't exist.
78 //------------------------------------------------------------------
79 const lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const;
81 //------------------------------------------------------------------
82 /// Returns a shared pointer to the breakpoint with index \a i.
85 /// The breakpoint index to seek for.
88 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
89 /// breakpoint doesn't exist.
90 //------------------------------------------------------------------
91 lldb::BreakpointSP GetBreakpointAtIndex(size_t i);
93 //------------------------------------------------------------------
94 /// Returns a shared pointer to the breakpoint with index \a i, const version
97 /// The breakpoint index to seek for.
100 /// A shared pointer to the breakpoint. May contain a NULL pointer if the
101 /// breakpoint doesn't exist.
102 //------------------------------------------------------------------
103 const lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const;
105 //------------------------------------------------------------------
106 /// Find all the breakpoints with a given name
109 /// The breakpoint name for which to search.
112 /// \bfalse if the input name was not a legal breakpoint name.
113 //------------------------------------------------------------------
114 bool FindBreakpointsByName(const char *name, BreakpointList &matching_bps);
116 //------------------------------------------------------------------
117 /// Returns the number of elements in this breakpoint list.
120 /// The number of elements.
121 //------------------------------------------------------------------
122 size_t GetSize() const {
123 std::lock_guard<std::recursive_mutex> guard(m_mutex);
124 return m_breakpoints.size();
127 //------------------------------------------------------------------
128 /// Removes the breakpoint given by \b breakID from this list.
130 /// @param[in] breakID
131 /// The breakpoint index to remove.
134 /// \b true if the breakpoint \a breakID was in the list.
135 //------------------------------------------------------------------
136 bool Remove(lldb::break_id_t breakID, bool notify);
138 //------------------------------------------------------------------
139 /// Removes all invalid breakpoint locations.
141 /// Removes all breakpoint locations in the list with architectures
142 /// that aren't compatible with \a arch. Also remove any breakpoint
143 /// locations with whose locations have address where the section
144 /// has been deleted (module and object files no longer exist).
146 /// This is typically used after the process calls exec, or anytime
147 /// the architecture of the target changes.
150 /// If valid, check the module in each breakpoint to make sure
151 /// they are compatible, otherwise, ignore architecture.
152 //------------------------------------------------------------------
153 void RemoveInvalidLocations(const ArchSpec &arch);
155 void SetEnabledAll(bool enabled);
157 //------------------------------------------------------------------
158 /// Removes all the breakpoints from this list.
159 //------------------------------------------------------------------
160 void RemoveAll(bool notify);
162 //------------------------------------------------------------------
163 /// Tell all the breakpoints to update themselves due to a change in the
164 /// modules in \a module_list. \a added says whether the module was loaded
167 /// @param[in] module_list
168 /// The module list that has changed.
171 /// \b true if the modules are loaded, \b false if unloaded.
173 /// @param[in] delete_locations
174 /// If \a load is \b false, then delete breakpoint locations when
175 /// when updating breakpoints.
176 //------------------------------------------------------------------
177 void UpdateBreakpoints(ModuleList &module_list, bool load,
178 bool delete_locations);
180 void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp,
181 lldb::ModuleSP new_module_sp);
183 void ClearAllBreakpointSites();
185 //------------------------------------------------------------------
186 /// Sets the passed in Locker to hold the Breakpoint List mutex.
188 /// @param[in] locker
189 /// The locker object that is set.
190 //------------------------------------------------------------------
191 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
194 typedef std::list<lldb::BreakpointSP> bp_collection;
196 bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID);
198 bp_collection::const_iterator
199 GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
201 std::recursive_mutex &GetMutex() const { return m_mutex; }
203 mutable std::recursive_mutex m_mutex;
204 bp_collection m_breakpoints; // The breakpoint list, currently a list.
205 lldb::break_id_t m_next_break_id;
209 typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
210 list_adapter, std::recursive_mutex>
212 BreakpointIterable Breakpoints() {
213 return BreakpointIterable(m_breakpoints, GetMutex());
217 DISALLOW_COPY_AND_ASSIGN(BreakpointList);
220 } // namespace lldb_private
222 #endif // liblldb_BreakpointList_h_