]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointSiteList.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Breakpoint / BreakpointSiteList.h
1 //===-- BreakpointSiteList.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_BreakpointSiteList_h_
11 #define liblldb_BreakpointSiteList_h_
12
13 #include <functional>
14 #include <map>
15 #include <mutex>
16
17 #include "lldb/Breakpoint/BreakpointSite.h"
18
19 namespace lldb_private {
20
21 //----------------------------------------------------------------------
22 /// @class BreakpointSiteList BreakpointSiteList.h
23 /// "lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of
24 /// BreakpointSite shared pointers.
25 //----------------------------------------------------------------------
26 class BreakpointSiteList {
27   // At present Process directly accesses the map of BreakpointSites so it can
28   // do quick lookups into the map (using GetMap).
29   // FIXME: Find a better interface for this.
30   friend class Process;
31
32 public:
33   //------------------------------------------------------------------
34   /// Default constructor makes an empty list.
35   //------------------------------------------------------------------
36   BreakpointSiteList();
37
38   //------------------------------------------------------------------
39   /// Destructor, currently does nothing.
40   //------------------------------------------------------------------
41   ~BreakpointSiteList();
42
43   //------------------------------------------------------------------
44   /// Add a BreakpointSite to the list.
45   ///
46   /// @param[in] bp_site_sp
47   ///    A shared pointer to a breakpoint site being added to the list.
48   ///
49   /// @return
50   ///    The ID of the BreakpointSite in the list.
51   //------------------------------------------------------------------
52   lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp);
53
54   //------------------------------------------------------------------
55   /// Standard Dump routine, doesn't do anything at present. @param[in] s
56   ///     Stream into which to dump the description.
57   //------------------------------------------------------------------
58   void Dump(Stream *s) const;
59
60   //------------------------------------------------------------------
61   /// Returns a shared pointer to the breakpoint site at address \a addr.
62   ///
63   /// @param[in] addr
64   ///     The address to look for.
65   ///
66   /// @result
67   ///     A shared pointer to the breakpoint site. May contain a NULL
68   ///     pointer if no breakpoint site exists with a matching address.
69   //------------------------------------------------------------------
70   lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr);
71
72   //------------------------------------------------------------------
73   /// Returns a shared pointer to the breakpoint site with id \a breakID.
74   ///
75   /// @param[in] breakID
76   ///   The breakpoint site ID to seek for.
77   ///
78   /// @result
79   ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if
80   ///   the
81   ///   breakpoint doesn't exist.
82   //------------------------------------------------------------------
83   lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
84
85   //------------------------------------------------------------------
86   /// Returns a shared pointer to the breakpoint site with id \a breakID -
87   /// const version.
88   ///
89   /// @param[in] breakID
90   ///   The breakpoint site ID to seek for.
91   ///
92   /// @result
93   ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if
94   ///   the
95   ///   breakpoint doesn't exist.
96   //------------------------------------------------------------------
97   const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
98
99   //------------------------------------------------------------------
100   /// Returns the breakpoint site id to the breakpoint site at address \a
101   /// addr.
102   ///
103   /// @param[in] addr
104   ///   The address to match.
105   ///
106   /// @result
107   ///   The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
108   //------------------------------------------------------------------
109   lldb::break_id_t FindIDByAddress(lldb::addr_t addr);
110
111   //------------------------------------------------------------------
112   /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
113   //  as one of its owners.
114   ///
115   /// @param[in] bp_site_id
116   ///   The breakpoint site id to query.
117   ///
118   /// @param[in] bp_id
119   ///   The breakpoint id to look for in \a bp_site_id.
120   ///
121   /// @result
122   ///   True if \a bp_site_id exists in the site list AND \a bp_id is one of the
123   ///   owners of that site.
124   //------------------------------------------------------------------
125   bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id,
126                                         lldb::break_id_t bp_id);
127
128   void ForEach(std::function<void(BreakpointSite *)> const &callback);
129
130   //------------------------------------------------------------------
131   /// Removes the breakpoint site given by \b breakID from this list.
132   ///
133   /// @param[in] breakID
134   ///   The breakpoint site index to remove.
135   ///
136   /// @result
137   ///   \b true if the breakpoint site \a breakID was in the list.
138   //------------------------------------------------------------------
139   bool Remove(lldb::break_id_t breakID);
140
141   //------------------------------------------------------------------
142   /// Removes the breakpoint site at address \a addr from this list.
143   ///
144   /// @param[in] addr
145   ///   The address from which to remove a breakpoint site.
146   ///
147   /// @result
148   ///   \b true if \a addr had a breakpoint site to remove from the list.
149   //------------------------------------------------------------------
150   bool RemoveByAddress(lldb::addr_t addr);
151
152   bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
153                    BreakpointSiteList &bp_site_list) const;
154
155   typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
156                                           void *baton);
157
158   //------------------------------------------------------------------
159   /// Enquires of the breakpoint site on in this list with ID \a breakID
160   /// whether we should stop for the breakpoint or not.
161   ///
162   /// @param[in] context
163   ///    This contains the information about this stop.
164   ///
165   /// @param[in] breakID
166   ///    This break ID that we hit.
167   ///
168   /// @return
169   ///    \b true if we should stop, \b false otherwise.
170   //------------------------------------------------------------------
171   bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
172
173   //------------------------------------------------------------------
174   /// Returns the number of elements in the list.
175   ///
176   /// @result
177   ///   The number of elements.
178   //------------------------------------------------------------------
179   size_t GetSize() const {
180     std::lock_guard<std::recursive_mutex> guard(m_mutex);
181     return m_bp_site_list.size();
182   }
183
184   bool IsEmpty() const {
185     std::lock_guard<std::recursive_mutex> guard(m_mutex);
186     return m_bp_site_list.empty();
187   }
188
189 protected:
190   typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
191
192   collection::iterator GetIDIterator(lldb::break_id_t breakID);
193
194   collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
195
196   mutable std::recursive_mutex m_mutex;
197   collection m_bp_site_list; // The breakpoint site list.
198 };
199
200 } // namespace lldb_private
201
202 #endif // liblldb_BreakpointSiteList_h_