]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/WatchpointList.h
Merge clang 7.0.1 and several follow-up changes
[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 /// 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. This is
35   // not just some random collection of watchpoints.  Rather, the act of adding
36   // 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 \a addr - const
74   /// version.
75   ///
76   /// @param[in] addr
77   ///     The address to look for.
78   ///
79   /// @result
80   ///     A shared pointer to the watchpoint.  May contain a NULL
81   ///     pointer if the watchpoint doesn't exist.
82   //------------------------------------------------------------------
83   const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const;
84
85   //------------------------------------------------------------------
86   /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec
87   /// - const version.
88   ///
89   /// @param[in] spec
90   ///     The watchpoint spec to look for.
91   ///
92   /// @result
93   ///     A shared pointer to the watchpoint.  May contain a NULL
94   ///     pointer if the watchpoint doesn't exist.
95   //------------------------------------------------------------------
96   const lldb::WatchpointSP FindBySpec(std::string spec) const;
97
98   //------------------------------------------------------------------
99   /// Returns a shared pointer to the watchpoint with id \a watchID, const
100   /// version.
101   ///
102   /// @param[in] watchID
103   ///     The watchpoint location ID to seek for.
104   ///
105   /// @result
106   ///     A shared pointer to the watchpoint.  May contain a NULL
107   ///     pointer if the watchpoint doesn't exist.
108   //------------------------------------------------------------------
109   lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const;
110
111   //------------------------------------------------------------------
112   /// Returns the watchpoint id to the watchpoint at address \a addr.
113   ///
114   /// @param[in] addr
115   ///     The address to match.
116   ///
117   /// @result
118   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
119   //------------------------------------------------------------------
120   lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
121
122   //------------------------------------------------------------------
123   /// Returns the watchpoint id to the watchpoint with watchpoint spec \a
124   /// spec.
125   ///
126   /// @param[in] spec
127   ///     The watchpoint spec to match.
128   ///
129   /// @result
130   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
131   //------------------------------------------------------------------
132   lldb::watch_id_t FindIDBySpec(std::string spec);
133
134   //------------------------------------------------------------------
135   /// Returns a shared pointer to the watchpoint with index \a i.
136   ///
137   /// @param[in] i
138   ///     The watchpoint index to seek for.
139   ///
140   /// @result
141   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
142   ///     the watchpoint doesn't exist.
143   //------------------------------------------------------------------
144   lldb::WatchpointSP GetByIndex(uint32_t i);
145
146   //------------------------------------------------------------------
147   /// Returns a shared pointer to the watchpoint with index \a i, const
148   /// version.
149   ///
150   /// @param[in] i
151   ///     The watchpoint index to seek for.
152   ///
153   /// @result
154   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
155   ///     the watchpoint location doesn't exist.
156   //------------------------------------------------------------------
157   const lldb::WatchpointSP GetByIndex(uint32_t i) const;
158
159   //------------------------------------------------------------------
160   /// Removes the watchpoint given by \b watchID from this list.
161   ///
162   /// @param[in] watchID
163   ///   The watchpoint ID to remove.
164   ///
165   /// @result
166   ///   \b true if the watchpoint \a watchID was in the list.
167   //------------------------------------------------------------------
168   bool Remove(lldb::watch_id_t watchID, bool notify);
169
170   //------------------------------------------------------------------
171   /// Returns the number hit count of all watchpoints in this list.
172   ///
173   /// @result
174   ///     Hit count of all watchpoints in this list.
175   //------------------------------------------------------------------
176   uint32_t GetHitCount() const;
177
178   //------------------------------------------------------------------
179   /// Enquires of the watchpoint in this list with ID \a watchID whether we
180   /// should stop.
181   ///
182   /// @param[in] context
183   ///     This contains the information about this stop.
184   ///
185   /// @param[in] watchID
186   ///     This watch ID that we hit.
187   ///
188   /// @return
189   ///     \b true if we should stop, \b false otherwise.
190   //------------------------------------------------------------------
191   bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
192
193   //------------------------------------------------------------------
194   /// Returns the number of elements in this watchpoint list.
195   ///
196   /// @result
197   ///     The number of elements.
198   //------------------------------------------------------------------
199   size_t GetSize() const {
200     std::lock_guard<std::recursive_mutex> guard(m_mutex);
201     return m_watchpoints.size();
202   }
203
204   //------------------------------------------------------------------
205   /// Print a description of the watchpoints in this list to the stream \a s.
206   ///
207   /// @param[in] s
208   ///     The stream to which to print the description.
209   ///
210   /// @param[in] level
211   ///     The description level that indicates the detail level to
212   ///     provide.
213   ///
214   /// @see lldb::DescriptionLevel
215   //------------------------------------------------------------------
216   void GetDescription(Stream *s, lldb::DescriptionLevel level);
217
218   void SetEnabledAll(bool enabled);
219
220   void RemoveAll(bool notify);
221
222   //------------------------------------------------------------------
223   /// Sets the passed in Locker to hold the Watchpoint List mutex.
224   ///
225   /// @param[in] locker
226   ///   The locker object that is set.
227   //------------------------------------------------------------------
228   void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
229
230 protected:
231   typedef std::list<lldb::WatchpointSP> wp_collection;
232   typedef std::vector<lldb::watch_id_t> id_vector;
233
234   id_vector GetWatchpointIDs() const;
235
236   wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
237
238   wp_collection::const_iterator
239   GetIDConstIterator(lldb::watch_id_t watchID) const;
240
241   wp_collection m_watchpoints;
242   mutable std::recursive_mutex m_mutex;
243
244   lldb::watch_id_t m_next_wp_id;
245 };
246
247 } // namespace lldb_private
248
249 #endif // liblldb_WatchpointList_h_