]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/WatchpointList.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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 <vector>
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/lldb-private.h"
20 #include "lldb/Core/Address.h"
21 #include "lldb/Host/Mutex.h"
22
23 namespace lldb_private {
24
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
29 //  well.
30 //----------------------------------------------------------------------
31
32 class WatchpointList
33 {
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
61     Add (const lldb::WatchpointSP& wp_sp, bool notify);
62
63     //------------------------------------------------------------------
64     /// Standard "Dump" method.
65     //------------------------------------------------------------------
66     void
67     Dump (Stream *s) const;
68
69     //------------------------------------------------------------------
70     /// Dump with lldb::DescriptionLevel.
71     //------------------------------------------------------------------
72     void
73     DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const;
74
75     //------------------------------------------------------------------
76     /// Returns a shared pointer to the watchpoint at address
77     /// \a addr -
78     /// const version.
79     ///
80     /// @param[in] addr
81     ///     The address to look for.
82     ///
83     /// @result
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;
89
90     //------------------------------------------------------------------
91     /// Returns a shared pointer to the watchpoint with watchpoint spec
92     /// \a spec -
93     /// const version.
94     ///
95     /// @param[in] spec
96     ///     The watchpoint spec to look for.
97     ///
98     /// @result
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;
104
105     //------------------------------------------------------------------
106     /// Returns a shared pointer to the watchpoint with id
107     /// \a watchID, const
108     /// version.
109     ///
110     /// @param[in] watchID
111     ///     The watchpoint location ID to seek for.
112     ///
113     /// @result
114     ///     A shared pointer to the watchpoint.  May contain a NULL
115     ///     pointer if the watchpoint doesn't exist.
116     //------------------------------------------------------------------
117     lldb::WatchpointSP
118     FindByID (lldb::watch_id_t watchID) const;
119
120     //------------------------------------------------------------------
121     /// Returns the watchpoint id to the watchpoint
122     /// at address \a addr.
123     ///
124     /// @param[in] addr
125     ///     The address to match.
126     ///
127     /// @result
128     ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
129     //------------------------------------------------------------------
130     lldb::watch_id_t
131     FindIDByAddress (lldb::addr_t addr);
132
133     //------------------------------------------------------------------
134     /// Returns the watchpoint id to the watchpoint
135     /// with watchpoint spec \a spec.
136     ///
137     /// @param[in] spec
138     ///     The watchpoint spec to match.
139     ///
140     /// @result
141     ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
142     //------------------------------------------------------------------
143     lldb::watch_id_t
144     FindIDBySpec (std::string spec);
145
146     //------------------------------------------------------------------
147     /// Returns a shared pointer to the watchpoint with index \a i.
148     ///
149     /// @param[in] i
150     ///     The watchpoint index to seek for.
151     ///
152     /// @result
153     ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
154     ///     the watchpoint doesn't exist.
155     //------------------------------------------------------------------
156     lldb::WatchpointSP
157     GetByIndex (uint32_t i);
158
159     //------------------------------------------------------------------
160     /// Returns a shared pointer to the watchpoint with index \a i, const
161     /// version.
162     ///
163     /// @param[in] i
164     ///     The watchpoint index to seek for.
165     ///
166     /// @result
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;
172
173     //------------------------------------------------------------------
174     /// Removes the watchpoint given by \b watchID from this list.
175     ///
176     /// @param[in] watchID
177     ///   The watchpoint ID to remove.
178     ///
179     /// @result
180     ///   \b true if the watchpoint \a watchID was in the list.
181     //------------------------------------------------------------------
182     bool
183     Remove (lldb::watch_id_t watchID, bool notify);
184
185     //------------------------------------------------------------------
186     /// Returns the number hit count of all watchpoints in this list.
187     ///
188     /// @result
189     ///     Hit count of all watchpoints in this list.
190     //------------------------------------------------------------------
191     uint32_t
192     GetHitCount () const;
193
194     //------------------------------------------------------------------
195     /// Enquires of the watchpoint in this list with ID \a watchID whether we
196     /// should stop.
197     ///
198     /// @param[in] context
199     ///     This contains the information about this stop.
200     ///
201     /// @param[in] watchID
202     ///     This watch ID that we hit.
203     ///
204     /// @return
205     ///     \b true if we should stop, \b false otherwise.
206     //------------------------------------------------------------------
207     bool
208     ShouldStop (StoppointCallbackContext *context,
209                 lldb::watch_id_t watchID);
210
211     //------------------------------------------------------------------
212     /// Returns the number of elements in this watchpoint list.
213     ///
214     /// @result
215     ///     The number of elements.
216     //------------------------------------------------------------------
217     size_t
218     GetSize() const
219     {
220         Mutex::Locker locker(m_mutex);
221         return m_watchpoints.size();
222     }
223
224     //------------------------------------------------------------------
225     /// Print a description of the watchpoints in this list to the stream \a s.
226     ///
227     /// @param[in] s
228     ///     The stream to which to print the description.
229     ///
230     /// @param[in] level
231     ///     The description level that indicates the detail level to
232     ///     provide.
233     ///
234     /// @see lldb::DescriptionLevel
235     //------------------------------------------------------------------
236     void
237     GetDescription (Stream *s,
238                     lldb::DescriptionLevel level);
239
240     void
241     SetEnabledAll (bool enabled);
242
243     void
244     RemoveAll (bool notify);
245     
246     //------------------------------------------------------------------
247     /// Sets the passed in Locker to hold the Watchpoint List mutex.
248     ///
249     /// @param[in] locker
250     ///   The locker object that is set.
251     //------------------------------------------------------------------
252     void
253     GetListMutex (lldb_private::Mutex::Locker &locker);
254
255 protected:
256     typedef std::list<lldb::WatchpointSP> wp_collection;
257     typedef std::vector<lldb::watch_id_t> id_vector;
258
259     id_vector
260     GetWatchpointIDs() const;
261
262     wp_collection::iterator
263     GetIDIterator(lldb::watch_id_t watchID);
264
265     wp_collection::const_iterator
266     GetIDConstIterator(lldb::watch_id_t watchID) const;
267
268     wp_collection m_watchpoints;
269     mutable Mutex m_mutex;
270
271     lldb::watch_id_t m_next_wp_id;
272 };
273
274 } // namespace lldb_private
275
276 #endif  // liblldb_WatchpointList_h_