]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointSiteList.h
Upgrade to OpenSSH 7.7p1.
[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"
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.
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.
60   /// @param[in] s
61   ///     Stream into which to dump the description.
62   //------------------------------------------------------------------
63   void Dump(Stream *s) const;
64
65   //------------------------------------------------------------------
66   /// Returns a shared pointer to the breakpoint site at address
67   /// \a addr.
68   ///
69   /// @param[in] addr
70   ///     The address to look for.
71   ///
72   /// @result
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);
77
78   //------------------------------------------------------------------
79   /// Returns a shared pointer to the breakpoint site with id \a breakID.
80   ///
81   /// @param[in] breakID
82   ///   The breakpoint site ID to seek for.
83   ///
84   /// @result
85   ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if
86   ///   the
87   ///   breakpoint doesn't exist.
88   //------------------------------------------------------------------
89   lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
90
91   //------------------------------------------------------------------
92   /// Returns a shared pointer to the breakpoint site with id \a breakID - const
93   /// version.
94   ///
95   /// @param[in] breakID
96   ///   The breakpoint site ID to seek for.
97   ///
98   /// @result
99   ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if
100   ///   the
101   ///   breakpoint doesn't exist.
102   //------------------------------------------------------------------
103   const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
104
105   //------------------------------------------------------------------
106   /// Returns the breakpoint site id to the breakpoint site at address \a addr.
107   ///
108   /// @param[in] addr
109   ///   The address to match.
110   ///
111   /// @result
112   ///   The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
113   //------------------------------------------------------------------
114   lldb::break_id_t FindIDByAddress(lldb::addr_t addr);
115
116   //------------------------------------------------------------------
117   /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
118   //  as one of its owners.
119   ///
120   /// @param[in] bp_site_id
121   ///   The breakpoint site id to query.
122   ///
123   /// @param[in] bp_id
124   ///   The breakpoint id to look for in \a bp_site_id.
125   ///
126   /// @result
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);
132
133   void ForEach(std::function<void(BreakpointSite *)> const &callback);
134
135   //------------------------------------------------------------------
136   /// Removes the breakpoint site given by \b breakID from this list.
137   ///
138   /// @param[in] breakID
139   ///   The breakpoint site index to remove.
140   ///
141   /// @result
142   ///   \b true if the breakpoint site \a breakID was in the list.
143   //------------------------------------------------------------------
144   bool Remove(lldb::break_id_t breakID);
145
146   //------------------------------------------------------------------
147   /// Removes the breakpoint site at address \a addr from this list.
148   ///
149   /// @param[in] addr
150   ///   The address from which to remove a breakpoint site.
151   ///
152   /// @result
153   ///   \b true if \a addr had a breakpoint site to remove from the list.
154   //------------------------------------------------------------------
155   bool RemoveByAddress(lldb::addr_t addr);
156
157   bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
158                    BreakpointSiteList &bp_site_list) const;
159
160   typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
161                                           void *baton);
162
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.
166   ///
167   /// @param[in] context
168   ///    This contains the information about this stop.
169   ///
170   /// @param[in] breakID
171   ///    This break ID that we hit.
172   ///
173   /// @return
174   ///    \b true if we should stop, \b false otherwise.
175   //------------------------------------------------------------------
176   bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
177
178   //------------------------------------------------------------------
179   /// Returns the number of elements in the list.
180   ///
181   /// @result
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();
187   }
188
189   bool IsEmpty() const {
190     std::lock_guard<std::recursive_mutex> guard(m_mutex);
191     return m_bp_site_list.empty();
192   }
193
194 protected:
195   typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
196
197   collection::iterator GetIDIterator(lldb::break_id_t breakID);
198
199   collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
200
201   mutable std::recursive_mutex m_mutex;
202   collection m_bp_site_list; // The breakpoint site list.
203 };
204
205 } // namespace lldb_private
206
207 #endif // liblldb_BreakpointSiteList_h_