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