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 /// 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. 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;
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 \a addr - const
77 /// The address to look for.
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;
85 //------------------------------------------------------------------
86 /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec
90 /// The watchpoint spec to look for.
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;
98 //------------------------------------------------------------------
99 /// Returns a shared pointer to the watchpoint with id \a watchID, const
102 /// @param[in] watchID
103 /// The watchpoint location ID to seek for.
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;
111 //------------------------------------------------------------------
112 /// Returns the watchpoint id to the watchpoint at address \a addr.
115 /// The address to match.
118 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
119 //------------------------------------------------------------------
120 lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
122 //------------------------------------------------------------------
123 /// Returns the watchpoint id to the watchpoint with watchpoint spec \a
127 /// The watchpoint spec to match.
130 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
131 //------------------------------------------------------------------
132 lldb::watch_id_t FindIDBySpec(std::string spec);
134 //------------------------------------------------------------------
135 /// Returns a shared pointer to the watchpoint with index \a i.
138 /// The watchpoint index to seek for.
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);
146 //------------------------------------------------------------------
147 /// Returns a shared pointer to the watchpoint with index \a i, const
151 /// The watchpoint index to seek for.
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;
159 //------------------------------------------------------------------
160 /// Removes the watchpoint given by \b watchID from this list.
162 /// @param[in] watchID
163 /// The watchpoint ID to remove.
166 /// \b true if the watchpoint \a watchID was in the list.
167 //------------------------------------------------------------------
168 bool Remove(lldb::watch_id_t watchID, bool notify);
170 //------------------------------------------------------------------
171 /// Returns the number hit count of all watchpoints in this list.
174 /// Hit count of all watchpoints in this list.
175 //------------------------------------------------------------------
176 uint32_t GetHitCount() const;
178 //------------------------------------------------------------------
179 /// Enquires of the watchpoint in this list with ID \a watchID whether we
182 /// @param[in] context
183 /// This contains the information about this stop.
185 /// @param[in] watchID
186 /// This watch ID that we hit.
189 /// \b true if we should stop, \b false otherwise.
190 //------------------------------------------------------------------
191 bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
193 //------------------------------------------------------------------
194 /// Returns the number of elements in this watchpoint list.
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();
204 //------------------------------------------------------------------
205 /// Print a description of the watchpoints in this list to the stream \a s.
208 /// The stream to which to print the description.
211 /// The description level that indicates the detail level to
214 /// @see lldb::DescriptionLevel
215 //------------------------------------------------------------------
216 void GetDescription(Stream *s, lldb::DescriptionLevel level);
218 void SetEnabledAll(bool enabled);
220 void RemoveAll(bool notify);
222 //------------------------------------------------------------------
223 /// Sets the passed in Locker to hold the Watchpoint List mutex.
225 /// @param[in] locker
226 /// The locker object that is set.
227 //------------------------------------------------------------------
228 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
231 typedef std::list<lldb::WatchpointSP> wp_collection;
232 typedef std::vector<lldb::watch_id_t> id_vector;
234 id_vector GetWatchpointIDs() const;
236 wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
238 wp_collection::const_iterator
239 GetIDConstIterator(lldb::watch_id_t watchID) const;
241 wp_collection m_watchpoints;
242 mutable std::recursive_mutex m_mutex;
244 lldb::watch_id_t m_next_wp_id;
247 } // namespace lldb_private
249 #endif // liblldb_WatchpointList_h_