1 //===-- BreakpointSiteList.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_BreakpointSiteList_h_
10 #define liblldb_BreakpointSiteList_h_
16 #include "lldb/Breakpoint/BreakpointSite.h"
18 namespace lldb_private {
20 /// \class BreakpointSiteList BreakpointSiteList.h
21 /// "lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of
22 /// BreakpointSite shared pointers.
23 class BreakpointSiteList {
24 // At present Process directly accesses the map of BreakpointSites so it can
25 // do quick lookups into the map (using GetMap).
26 // FIXME: Find a better interface for this.
30 /// Default constructor makes an empty list.
33 /// Destructor, currently does nothing.
34 ~BreakpointSiteList();
36 /// Add a BreakpointSite to the list.
38 /// \param[in] bp_site_sp
39 /// A shared pointer to a breakpoint site being added to the list.
42 /// The ID of the BreakpointSite in the list.
43 lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp);
45 /// Standard Dump routine, doesn't do anything at present. \param[in] s
46 /// Stream into which to dump the description.
47 void Dump(Stream *s) const;
49 /// Returns a shared pointer to the breakpoint site at address \a addr.
52 /// The address to look for.
55 /// A shared pointer to the breakpoint site. May contain a NULL
56 /// pointer if no breakpoint site exists with a matching address.
57 lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr);
59 /// Returns a shared pointer to the breakpoint site with id \a breakID.
61 /// \param[in] breakID
62 /// The breakpoint site ID to seek for.
65 /// A shared pointer to the breakpoint site. May contain a NULL pointer if
67 /// breakpoint doesn't exist.
68 lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
70 /// Returns a shared pointer to the breakpoint site with id \a breakID -
73 /// \param[in] breakID
74 /// The breakpoint site ID to seek for.
77 /// A shared pointer to the breakpoint site. May contain a NULL pointer if
79 /// breakpoint doesn't exist.
80 const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
82 /// Returns the breakpoint site id to the breakpoint site at address \a
86 /// The address to match.
89 /// The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
90 lldb::break_id_t FindIDByAddress(lldb::addr_t addr);
92 /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
93 // as one of its owners.
95 /// \param[in] bp_site_id
96 /// The breakpoint site id to query.
99 /// The breakpoint id to look for in \a bp_site_id.
102 /// True if \a bp_site_id exists in the site list AND \a bp_id is one of the
103 /// owners of that site.
104 bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id,
105 lldb::break_id_t bp_id);
107 void ForEach(std::function<void(BreakpointSite *)> const &callback);
109 /// Removes the breakpoint site given by \b breakID from this list.
111 /// \param[in] breakID
112 /// The breakpoint site index to remove.
115 /// \b true if the breakpoint site \a breakID was in the list.
116 bool Remove(lldb::break_id_t breakID);
118 /// Removes the breakpoint site at address \a addr from this list.
121 /// The address from which to remove a breakpoint site.
124 /// \b true if \a addr had a breakpoint site to remove from the list.
125 bool RemoveByAddress(lldb::addr_t addr);
127 bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
128 BreakpointSiteList &bp_site_list) const;
130 typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
133 /// Enquires of the breakpoint site on in this list with ID \a breakID
134 /// whether we should stop for the breakpoint or not.
136 /// \param[in] context
137 /// This contains the information about this stop.
139 /// \param[in] breakID
140 /// This break ID that we hit.
143 /// \b true if we should stop, \b false otherwise.
144 bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
146 /// Returns the number of elements in the list.
149 /// The number of elements.
150 size_t GetSize() const {
151 std::lock_guard<std::recursive_mutex> guard(m_mutex);
152 return m_bp_site_list.size();
155 bool IsEmpty() const {
156 std::lock_guard<std::recursive_mutex> guard(m_mutex);
157 return m_bp_site_list.empty();
161 typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
163 collection::iterator GetIDIterator(lldb::break_id_t breakID);
165 collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
167 mutable std::recursive_mutex m_mutex;
168 collection m_bp_site_list; // The breakpoint site list.
171 } // namespace lldb_private
173 #endif // liblldb_BreakpointSiteList_h_