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_
17 // Other libraries and framework includes
19 #include "lldb/lldb-private.h"
20 #include "lldb/Core/Address.h"
21 #include "lldb/Host/Mutex.h"
23 namespace lldb_private {
25 //----------------------------------------------------------------------
26 /// @class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h"
27 /// @brief This class is used by Watchpoint to manage a list of watchpoints,
28 // each watchpoint in the list has a unique ID, and is unique by Address as
30 //----------------------------------------------------------------------
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 //------------------------------------------------------------------
61 Add (const lldb::WatchpointSP& wp_sp, bool notify);
63 //------------------------------------------------------------------
64 /// Standard "Dump" method.
65 //------------------------------------------------------------------
67 Dump (Stream *s) const;
69 //------------------------------------------------------------------
70 /// Dump with lldb::DescriptionLevel.
71 //------------------------------------------------------------------
73 DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const;
75 //------------------------------------------------------------------
76 /// Returns a shared pointer to the watchpoint at address
81 /// The address to look for.
84 /// A shared pointer to the watchpoint. May contain a NULL
85 /// pointer if the watchpoint doesn't exist.
86 //------------------------------------------------------------------
87 const lldb::WatchpointSP
88 FindByAddress (lldb::addr_t addr) const;
90 //------------------------------------------------------------------
91 /// Returns a shared pointer to the watchpoint with watchpoint spec
96 /// The watchpoint spec to look for.
99 /// A shared pointer to the watchpoint. May contain a NULL
100 /// pointer if the watchpoint doesn't exist.
101 //------------------------------------------------------------------
102 const lldb::WatchpointSP
103 FindBySpec (std::string spec) const;
105 //------------------------------------------------------------------
106 /// Returns a shared pointer to the watchpoint with id
107 /// \a watchID, const
110 /// @param[in] watchID
111 /// The watchpoint location ID to seek for.
114 /// A shared pointer to the watchpoint. May contain a NULL
115 /// pointer if the watchpoint doesn't exist.
116 //------------------------------------------------------------------
118 FindByID (lldb::watch_id_t watchID) const;
120 //------------------------------------------------------------------
121 /// Returns the watchpoint id to the watchpoint
122 /// at address \a addr.
125 /// The address to match.
128 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
129 //------------------------------------------------------------------
131 FindIDByAddress (lldb::addr_t addr);
133 //------------------------------------------------------------------
134 /// Returns the watchpoint id to the watchpoint
135 /// with watchpoint spec \a spec.
138 /// The watchpoint spec to match.
141 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
142 //------------------------------------------------------------------
144 FindIDBySpec (std::string spec);
146 //------------------------------------------------------------------
147 /// Returns a shared pointer to the watchpoint with index \a i.
150 /// The watchpoint index to seek for.
153 /// A shared pointer to the watchpoint. May contain a NULL pointer if
154 /// the watchpoint doesn't exist.
155 //------------------------------------------------------------------
157 GetByIndex (uint32_t i);
159 //------------------------------------------------------------------
160 /// Returns a shared pointer to the watchpoint with index \a i, const
164 /// The watchpoint index to seek for.
167 /// A shared pointer to the watchpoint. May contain a NULL pointer if
168 /// the watchpoint location doesn't exist.
169 //------------------------------------------------------------------
170 const lldb::WatchpointSP
171 GetByIndex (uint32_t i) const;
173 //------------------------------------------------------------------
174 /// Removes the watchpoint given by \b watchID from this list.
176 /// @param[in] watchID
177 /// The watchpoint ID to remove.
180 /// \b true if the watchpoint \a watchID was in the list.
181 //------------------------------------------------------------------
183 Remove (lldb::watch_id_t watchID, bool notify);
185 //------------------------------------------------------------------
186 /// Returns the number hit count of all watchpoints in this list.
189 /// Hit count of all watchpoints in this list.
190 //------------------------------------------------------------------
192 GetHitCount () const;
194 //------------------------------------------------------------------
195 /// Enquires of the watchpoint in this list with ID \a watchID whether we
198 /// @param[in] context
199 /// This contains the information about this stop.
201 /// @param[in] watchID
202 /// This watch ID that we hit.
205 /// \b true if we should stop, \b false otherwise.
206 //------------------------------------------------------------------
208 ShouldStop (StoppointCallbackContext *context,
209 lldb::watch_id_t watchID);
211 //------------------------------------------------------------------
212 /// Returns the number of elements in this watchpoint list.
215 /// The number of elements.
216 //------------------------------------------------------------------
220 Mutex::Locker locker(m_mutex);
221 return m_watchpoints.size();
224 //------------------------------------------------------------------
225 /// Print a description of the watchpoints in this list to the stream \a s.
228 /// The stream to which to print the description.
231 /// The description level that indicates the detail level to
234 /// @see lldb::DescriptionLevel
235 //------------------------------------------------------------------
237 GetDescription (Stream *s,
238 lldb::DescriptionLevel level);
241 SetEnabledAll (bool enabled);
244 RemoveAll (bool notify);
246 //------------------------------------------------------------------
247 /// Sets the passed in Locker to hold the Watchpoint List mutex.
249 /// @param[in] locker
250 /// The locker object that is set.
251 //------------------------------------------------------------------
253 GetListMutex (lldb_private::Mutex::Locker &locker);
256 typedef std::list<lldb::WatchpointSP> wp_collection;
257 typedef std::vector<lldb::watch_id_t> id_vector;
260 GetWatchpointIDs() const;
262 wp_collection::iterator
263 GetIDIterator(lldb::watch_id_t watchID);
265 wp_collection::const_iterator
266 GetIDConstIterator(lldb::watch_id_t watchID) const;
268 wp_collection m_watchpoints;
269 mutable Mutex m_mutex;
271 lldb::watch_id_t m_next_wp_id;
274 } // namespace lldb_private
276 #endif // liblldb_WatchpointList_h_