1 //===-- BreakpointSiteList.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_BreakpointSiteList_h_
11 #define liblldb_BreakpointSiteList_h_
19 // Other libraries and framework includes
21 #include "lldb/Breakpoint/BreakpointSite.h"
23 namespace lldb_private {
25 //----------------------------------------------------------------------
26 /// @class BreakpointSiteList BreakpointSiteList.h
27 /// "lldb/Breakpoint/BreakpointSiteList.h"
28 /// @brief Class that manages lists of BreakpointSite shared pointers.
29 //----------------------------------------------------------------------
30 class BreakpointSiteList {
31 // At present Process directly accesses the map of BreakpointSites so it can
32 // do quick lookups into the map (using GetMap).
33 // FIXME: Find a better interface for this.
37 //------------------------------------------------------------------
38 /// Default constructor makes an empty list.
39 //------------------------------------------------------------------
42 //------------------------------------------------------------------
43 /// Destructor, currently does nothing.
44 //------------------------------------------------------------------
45 ~BreakpointSiteList();
47 //------------------------------------------------------------------
48 /// Add a BreakpointSite to the list.
50 /// @param[in] bp_site_sp
51 /// A shared pointer to a breakpoint site being added to the list.
54 /// The ID of the BreakpointSite in the list.
55 //------------------------------------------------------------------
56 lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp);
58 //------------------------------------------------------------------
59 /// Standard Dump routine, doesn't do anything at present.
61 /// Stream into which to dump the description.
62 //------------------------------------------------------------------
63 void Dump(Stream *s) const;
65 //------------------------------------------------------------------
66 /// Returns a shared pointer to the breakpoint site at address
70 /// The address to look for.
73 /// A shared pointer to the breakpoint site. May contain a NULL
74 /// pointer if no breakpoint site exists with a matching address.
75 //------------------------------------------------------------------
76 lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr);
78 //------------------------------------------------------------------
79 /// Returns a shared pointer to the breakpoint site with id \a breakID.
81 /// @param[in] breakID
82 /// The breakpoint site ID to seek for.
85 /// A shared pointer to the breakpoint site. May contain a NULL pointer if
87 /// breakpoint doesn't exist.
88 //------------------------------------------------------------------
89 lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
91 //------------------------------------------------------------------
92 /// Returns a shared pointer to the breakpoint site with id \a breakID - const
95 /// @param[in] breakID
96 /// The breakpoint site ID to seek for.
99 /// A shared pointer to the breakpoint site. May contain a NULL pointer if
101 /// breakpoint doesn't exist.
102 //------------------------------------------------------------------
103 const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
105 //------------------------------------------------------------------
106 /// Returns the breakpoint site id to the breakpoint site at address \a addr.
109 /// The address to match.
112 /// The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
113 //------------------------------------------------------------------
114 lldb::break_id_t FindIDByAddress(lldb::addr_t addr);
116 //------------------------------------------------------------------
117 /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
118 // as one of its owners.
120 /// @param[in] bp_site_id
121 /// The breakpoint site id to query.
124 /// The breakpoint id to look for in \a bp_site_id.
127 /// True if \a bp_site_id exists in the site list AND \a bp_id is one of the
128 /// owners of that site.
129 //------------------------------------------------------------------
130 bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id,
131 lldb::break_id_t bp_id);
133 void ForEach(std::function<void(BreakpointSite *)> const &callback);
135 //------------------------------------------------------------------
136 /// Removes the breakpoint site given by \b breakID from this list.
138 /// @param[in] breakID
139 /// The breakpoint site index to remove.
142 /// \b true if the breakpoint site \a breakID was in the list.
143 //------------------------------------------------------------------
144 bool Remove(lldb::break_id_t breakID);
146 //------------------------------------------------------------------
147 /// Removes the breakpoint site at address \a addr from this list.
150 /// The address from which to remove a breakpoint site.
153 /// \b true if \a addr had a breakpoint site to remove from the list.
154 //------------------------------------------------------------------
155 bool RemoveByAddress(lldb::addr_t addr);
157 bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
158 BreakpointSiteList &bp_site_list) const;
160 typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
163 //------------------------------------------------------------------
164 /// Enquires of the breakpoint site on in this list with ID \a breakID whether
165 /// we should stop for the breakpoint or not.
167 /// @param[in] context
168 /// This contains the information about this stop.
170 /// @param[in] breakID
171 /// This break ID that we hit.
174 /// \b true if we should stop, \b false otherwise.
175 //------------------------------------------------------------------
176 bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
178 //------------------------------------------------------------------
179 /// Returns the number of elements in the list.
182 /// The number of elements.
183 //------------------------------------------------------------------
184 size_t GetSize() const {
185 std::lock_guard<std::recursive_mutex> guard(m_mutex);
186 return m_bp_site_list.size();
189 bool IsEmpty() const {
190 std::lock_guard<std::recursive_mutex> guard(m_mutex);
191 return m_bp_site_list.empty();
195 typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
197 collection::iterator GetIDIterator(lldb::break_id_t breakID);
199 collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
201 mutable std::recursive_mutex m_mutex;
202 collection m_bp_site_list; // The breakpoint site list.
205 } // namespace lldb_private
207 #endif // liblldb_BreakpointSiteList_h_