]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/WatchpointList.h
MFV r337206: 9338 moved dnode has incorrect dn_next_type
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Breakpoint / WatchpointList.h
1 //===-- WatchpointList.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_WatchpointList_h_
11 #define liblldb_WatchpointList_h_
12
13 // C Includes
14 // C++ Includes
15 #include <list>
16 #include <mutex>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/Core/Address.h"
22 #include "lldb/lldb-private.h"
23
24 namespace lldb_private {
25
26 //----------------------------------------------------------------------
27 /// @class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h"
28 /// @brief This class is used by Watchpoint to manage a list of watchpoints,
29 //  each watchpoint in the list has a unique ID, and is unique by Address as
30 //  well.
31 //----------------------------------------------------------------------
32
33 class WatchpointList {
34   // Only Target can make the watchpoint list, or add elements to it.
35   // This is not just some random collection of watchpoints.  Rather, the act of
36   // adding the watchpoint to this list sets its ID.
37   friend class Watchpoint;
38   friend class Target;
39
40 public:
41   //------------------------------------------------------------------
42   /// Default constructor makes an empty list.
43   //------------------------------------------------------------------
44   WatchpointList();
45
46   //------------------------------------------------------------------
47   /// Destructor, currently does nothing.
48   //------------------------------------------------------------------
49   ~WatchpointList();
50
51   //------------------------------------------------------------------
52   /// Add a Watchpoint to the list.
53   ///
54   /// @param[in] wp_sp
55   ///    A shared pointer to a watchpoint being added to the list.
56   ///
57   /// @return
58   ///    The ID of the Watchpoint in the list.
59   //------------------------------------------------------------------
60   lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify);
61
62   //------------------------------------------------------------------
63   /// Standard "Dump" method.
64   //------------------------------------------------------------------
65   void Dump(Stream *s) const;
66
67   //------------------------------------------------------------------
68   /// Dump with lldb::DescriptionLevel.
69   //------------------------------------------------------------------
70   void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
71
72   //------------------------------------------------------------------
73   /// Returns a shared pointer to the watchpoint at address
74   /// \a addr -
75   /// const version.
76   ///
77   /// @param[in] addr
78   ///     The address to look for.
79   ///
80   /// @result
81   ///     A shared pointer to the watchpoint.  May contain a NULL
82   ///     pointer if the watchpoint doesn't exist.
83   //------------------------------------------------------------------
84   const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const;
85
86   //------------------------------------------------------------------
87   /// Returns a shared pointer to the watchpoint with watchpoint spec
88   /// \a spec -
89   /// const version.
90   ///
91   /// @param[in] spec
92   ///     The watchpoint spec to look for.
93   ///
94   /// @result
95   ///     A shared pointer to the watchpoint.  May contain a NULL
96   ///     pointer if the watchpoint doesn't exist.
97   //------------------------------------------------------------------
98   const lldb::WatchpointSP FindBySpec(std::string spec) const;
99
100   //------------------------------------------------------------------
101   /// Returns a shared pointer to the watchpoint with id
102   /// \a watchID, const
103   /// version.
104   ///
105   /// @param[in] watchID
106   ///     The watchpoint location ID to seek for.
107   ///
108   /// @result
109   ///     A shared pointer to the watchpoint.  May contain a NULL
110   ///     pointer if the watchpoint doesn't exist.
111   //------------------------------------------------------------------
112   lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const;
113
114   //------------------------------------------------------------------
115   /// Returns the watchpoint id to the watchpoint
116   /// at address \a addr.
117   ///
118   /// @param[in] addr
119   ///     The address to match.
120   ///
121   /// @result
122   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
123   //------------------------------------------------------------------
124   lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
125
126   //------------------------------------------------------------------
127   /// Returns the watchpoint id to the watchpoint
128   /// with watchpoint spec \a spec.
129   ///
130   /// @param[in] spec
131   ///     The watchpoint spec to match.
132   ///
133   /// @result
134   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
135   //------------------------------------------------------------------
136   lldb::watch_id_t FindIDBySpec(std::string spec);
137
138   //------------------------------------------------------------------
139   /// Returns a shared pointer to the watchpoint with index \a i.
140   ///
141   /// @param[in] i
142   ///     The watchpoint index to seek for.
143   ///
144   /// @result
145   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
146   ///     the watchpoint doesn't exist.
147   //------------------------------------------------------------------
148   lldb::WatchpointSP GetByIndex(uint32_t i);
149
150   //------------------------------------------------------------------
151   /// Returns a shared pointer to the watchpoint with index \a i, const
152   /// version.
153   ///
154   /// @param[in] i
155   ///     The watchpoint index to seek for.
156   ///
157   /// @result
158   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
159   ///     the watchpoint location doesn't exist.
160   //------------------------------------------------------------------
161   const lldb::WatchpointSP GetByIndex(uint32_t i) const;
162
163   //------------------------------------------------------------------
164   /// Removes the watchpoint given by \b watchID from this list.
165   ///
166   /// @param[in] watchID
167   ///   The watchpoint ID to remove.
168   ///
169   /// @result
170   ///   \b true if the watchpoint \a watchID was in the list.
171   //------------------------------------------------------------------
172   bool Remove(lldb::watch_id_t watchID, bool notify);
173
174   //------------------------------------------------------------------
175   /// Returns the number hit count of all watchpoints in this list.
176   ///
177   /// @result
178   ///     Hit count of all watchpoints in this list.
179   //------------------------------------------------------------------
180   uint32_t GetHitCount() const;
181
182   //------------------------------------------------------------------
183   /// Enquires of the watchpoint in this list with ID \a watchID whether we
184   /// should stop.
185   ///
186   /// @param[in] context
187   ///     This contains the information about this stop.
188   ///
189   /// @param[in] watchID
190   ///     This watch ID that we hit.
191   ///
192   /// @return
193   ///     \b true if we should stop, \b false otherwise.
194   //------------------------------------------------------------------
195   bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
196
197   //------------------------------------------------------------------
198   /// Returns the number of elements in this watchpoint list.
199   ///
200   /// @result
201   ///     The number of elements.
202   //------------------------------------------------------------------
203   size_t GetSize() const {
204     std::lock_guard<std::recursive_mutex> guard(m_mutex);
205     return m_watchpoints.size();
206   }
207
208   //------------------------------------------------------------------
209   /// Print a description of the watchpoints in this list to the stream \a s.
210   ///
211   /// @param[in] s
212   ///     The stream to which to print the description.
213   ///
214   /// @param[in] level
215   ///     The description level that indicates the detail level to
216   ///     provide.
217   ///
218   /// @see lldb::DescriptionLevel
219   //------------------------------------------------------------------
220   void GetDescription(Stream *s, lldb::DescriptionLevel level);
221
222   void SetEnabledAll(bool enabled);
223
224   void RemoveAll(bool notify);
225
226   //------------------------------------------------------------------
227   /// Sets the passed in Locker to hold the Watchpoint List mutex.
228   ///
229   /// @param[in] locker
230   ///   The locker object that is set.
231   //------------------------------------------------------------------
232   void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
233
234 protected:
235   typedef std::list<lldb::WatchpointSP> wp_collection;
236   typedef std::vector<lldb::watch_id_t> id_vector;
237
238   id_vector GetWatchpointIDs() const;
239
240   wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
241
242   wp_collection::const_iterator
243   GetIDConstIterator(lldb::watch_id_t watchID) const;
244
245   wp_collection m_watchpoints;
246   mutable std::recursive_mutex m_mutex;
247
248   lldb::watch_id_t m_next_wp_id;
249 };
250
251 } // namespace lldb_private
252
253 #endif // liblldb_WatchpointList_h_