1 //===-- WatchpointList.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_WatchpointList_h_
11 #define liblldb_WatchpointList_h_
19 // Other libraries and framework includes
21 #include "lldb/Core/Address.h"
22 #include "lldb/lldb-private.h"
24 namespace lldb_private {
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
31 //----------------------------------------------------------------------
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;
41 //------------------------------------------------------------------
42 /// Default constructor makes an empty list.
43 //------------------------------------------------------------------
46 //------------------------------------------------------------------
47 /// Destructor, currently does nothing.
48 //------------------------------------------------------------------
51 //------------------------------------------------------------------
52 /// Add a Watchpoint to the list.
55 /// A shared pointer to a watchpoint being added to the list.
58 /// The ID of the Watchpoint in the list.
59 //------------------------------------------------------------------
60 lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify);
62 //------------------------------------------------------------------
63 /// Standard "Dump" method.
64 //------------------------------------------------------------------
65 void Dump(Stream *s) const;
67 //------------------------------------------------------------------
68 /// Dump with lldb::DescriptionLevel.
69 //------------------------------------------------------------------
70 void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
72 //------------------------------------------------------------------
73 /// Returns a shared pointer to the watchpoint at address
78 /// The address to look for.
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;
86 //------------------------------------------------------------------
87 /// Returns a shared pointer to the watchpoint with watchpoint spec
92 /// The watchpoint spec to look for.
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;
100 //------------------------------------------------------------------
101 /// Returns a shared pointer to the watchpoint with id
102 /// \a watchID, const
105 /// @param[in] watchID
106 /// The watchpoint location ID to seek for.
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;
114 //------------------------------------------------------------------
115 /// Returns the watchpoint id to the watchpoint
116 /// at address \a addr.
119 /// The address to match.
122 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
123 //------------------------------------------------------------------
124 lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
126 //------------------------------------------------------------------
127 /// Returns the watchpoint id to the watchpoint
128 /// with watchpoint spec \a spec.
131 /// The watchpoint spec to match.
134 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
135 //------------------------------------------------------------------
136 lldb::watch_id_t FindIDBySpec(std::string spec);
138 //------------------------------------------------------------------
139 /// Returns a shared pointer to the watchpoint with index \a i.
142 /// The watchpoint index to seek for.
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);
150 //------------------------------------------------------------------
151 /// Returns a shared pointer to the watchpoint with index \a i, const
155 /// The watchpoint index to seek for.
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;
163 //------------------------------------------------------------------
164 /// Removes the watchpoint given by \b watchID from this list.
166 /// @param[in] watchID
167 /// The watchpoint ID to remove.
170 /// \b true if the watchpoint \a watchID was in the list.
171 //------------------------------------------------------------------
172 bool Remove(lldb::watch_id_t watchID, bool notify);
174 //------------------------------------------------------------------
175 /// Returns the number hit count of all watchpoints in this list.
178 /// Hit count of all watchpoints in this list.
179 //------------------------------------------------------------------
180 uint32_t GetHitCount() const;
182 //------------------------------------------------------------------
183 /// Enquires of the watchpoint in this list with ID \a watchID whether we
186 /// @param[in] context
187 /// This contains the information about this stop.
189 /// @param[in] watchID
190 /// This watch ID that we hit.
193 /// \b true if we should stop, \b false otherwise.
194 //------------------------------------------------------------------
195 bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
197 //------------------------------------------------------------------
198 /// Returns the number of elements in this watchpoint list.
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();
208 //------------------------------------------------------------------
209 /// Print a description of the watchpoints in this list to the stream \a s.
212 /// The stream to which to print the description.
215 /// The description level that indicates the detail level to
218 /// @see lldb::DescriptionLevel
219 //------------------------------------------------------------------
220 void GetDescription(Stream *s, lldb::DescriptionLevel level);
222 void SetEnabledAll(bool enabled);
224 void RemoveAll(bool notify);
226 //------------------------------------------------------------------
227 /// Sets the passed in Locker to hold the Watchpoint List mutex.
229 /// @param[in] locker
230 /// The locker object that is set.
231 //------------------------------------------------------------------
232 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
235 typedef std::list<lldb::WatchpointSP> wp_collection;
236 typedef std::vector<lldb::watch_id_t> id_vector;
238 id_vector GetWatchpointIDs() const;
240 wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
242 wp_collection::const_iterator
243 GetIDConstIterator(lldb::watch_id_t watchID) const;
245 wp_collection m_watchpoints;
246 mutable std::recursive_mutex m_mutex;
248 lldb::watch_id_t m_next_wp_id;
251 } // namespace lldb_private
253 #endif // liblldb_WatchpointList_h_