LLDB mainline
WatchpointList.h
Go to the documentation of this file.
1//===-- WatchpointList.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_BREAKPOINT_WATCHPOINTLIST_H
10#define LLDB_BREAKPOINT_WATCHPOINTLIST_H
11
12#include <list>
13#include <mutex>
14#include <vector>
15
16#include "lldb/Core/Address.h"
18#include "lldb/lldb-private.h"
19
20namespace lldb_private {
21
22/// \class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h"
23/// This class is used by Watchpoint to manage a list of watchpoints,
24// each watchpoint in the list has a unique ID, and is unique by Address as
25// well.
26
28 // Only Target can make the watchpoint list, or add elements to it. This is
29 // not just some random collection of watchpoints. Rather, the act of adding
30 // the watchpoint to this list sets its ID.
31 friend class Watchpoint;
32 friend class Target;
33
34public:
35 /// Default constructor makes an empty list.
37
38 /// Destructor, currently does nothing.
40
41 typedef std::list<lldb::WatchpointSP> wp_collection;
44
45 /// Add a Watchpoint to the list.
46 ///
47 /// \param[in] wp_sp
48 /// A shared pointer to a watchpoint being added to the list.
49 ///
50 /// \return
51 /// The ID of the Watchpoint in the list.
52 lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify);
53
54 /// Standard "Dump" method.
55 void Dump(Stream *s) const;
56
57 /// Dump with lldb::DescriptionLevel.
58 void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
59
60 /// Returns a shared pointer to the watchpoint at address \a addr - const
61 /// version.
62 ///
63 /// \param[in] addr
64 /// The address to look for.
65 ///
66 /// \result
67 /// A shared pointer to the watchpoint. May contain a NULL
68 /// pointer if the watchpoint doesn't exist.
70
71 /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec
72 /// - const version.
73 ///
74 /// \param[in] spec
75 /// The watchpoint spec to look for.
76 ///
77 /// \result
78 /// A shared pointer to the watchpoint. May contain a NULL
79 /// pointer if the watchpoint doesn't exist.
80 const lldb::WatchpointSP FindBySpec(std::string spec) const;
81
82 /// Returns a shared pointer to the watchpoint with id \a watchID, const
83 /// version.
84 ///
85 /// \param[in] watchID
86 /// The watchpoint location ID to seek for.
87 ///
88 /// \result
89 /// A shared pointer to the watchpoint. May contain a NULL
90 /// pointer if the watchpoint doesn't exist.
92
93 /// Returns the watchpoint id to the watchpoint at address \a addr.
94 ///
95 /// \param[in] addr
96 /// The address to match.
97 ///
98 /// \result
99 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
101
102 /// Returns the watchpoint id to the watchpoint with watchpoint spec \a
103 /// spec.
104 ///
105 /// \param[in] spec
106 /// The watchpoint spec to match.
107 ///
108 /// \result
109 /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
110 lldb::watch_id_t FindIDBySpec(std::string spec);
111
112 /// Returns a shared pointer to the watchpoint with index \a i.
113 ///
114 /// \param[in] i
115 /// The watchpoint index to seek for.
116 ///
117 /// \result
118 /// A shared pointer to the watchpoint. May contain a NULL pointer if
119 /// the watchpoint doesn't exist.
120 lldb::WatchpointSP GetByIndex(uint32_t i);
121
122 /// Returns a shared pointer to the watchpoint with index \a i, const
123 /// version.
124 ///
125 /// \param[in] i
126 /// The watchpoint index to seek for.
127 ///
128 /// \result
129 /// A shared pointer to the watchpoint. May contain a NULL pointer if
130 /// the watchpoint location doesn't exist.
131 const lldb::WatchpointSP GetByIndex(uint32_t i) const;
132
133 /// Removes the watchpoint given by \b watchID from this list.
134 ///
135 /// \param[in] watchID
136 /// The watchpoint ID to remove.
137 ///
138 /// \result
139 /// \b true if the watchpoint \a watchID was in the list.
140 bool Remove(lldb::watch_id_t watchID, bool notify);
141
142 /// Returns the number hit count of all watchpoints in this list.
143 ///
144 /// \result
145 /// Hit count of all watchpoints in this list.
146 uint32_t GetHitCount() const;
147
148 /// Enquires of the watchpoint in this list with ID \a watchID whether we
149 /// should stop.
150 ///
151 /// \param[in] context
152 /// This contains the information about this stop.
153 ///
154 /// \param[in] watchID
155 /// This watch ID that we hit.
156 ///
157 /// \return
158 /// \b true if we should stop, \b false otherwise.
160
161 /// Returns the number of elements in this watchpoint list.
162 ///
163 /// \result
164 /// The number of elements.
165 size_t GetSize() const {
166 std::lock_guard<std::recursive_mutex> guard(m_mutex);
167 return m_watchpoints.size();
168 }
169
170 /// Print a description of the watchpoints in this list to the stream \a s.
171 ///
172 /// \param[in] s
173 /// The stream to which to print the description.
174 ///
175 /// \param[in] level
176 /// The description level that indicates the detail level to
177 /// provide.
178 ///
179 /// \see lldb::DescriptionLevel
181
182 void SetEnabledAll(bool enabled);
183
184 void RemoveAll(bool notify);
185
186 /// Sets the passed in Locker to hold the Watchpoint List mutex.
187 ///
188 /// \param[in] lock
189 /// The locker object that is set.
190 void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
191
195
196protected:
197 typedef std::vector<lldb::watch_id_t> id_vector;
198
200
201 wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
202
203 wp_collection::const_iterator
205
207 mutable std::recursive_mutex m_mutex;
208
210};
211
212} // namespace lldb_private
213
214#endif // LLDB_BREAKPOINT_WATCHPOINTLIST_H
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition Stream.h:28
lldb::WatchpointSP GetByIndex(uint32_t i)
Returns a shared pointer to the watchpoint with index i.
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Print a description of the watchpoints in this list to the stream s.
LockingAdaptedIterable< std::recursive_mutex, wp_collection > WatchpointIterable
lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify)
Add a Watchpoint to the list.
lldb::watch_id_t FindIDBySpec(std::string spec)
Returns the watchpoint id to the watchpoint with watchpoint spec spec.
lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const
Returns a shared pointer to the watchpoint with id watchID, const version.
const lldb::WatchpointSP FindBySpec(std::string spec) const
Returns a shared pointer to the watchpoint with watchpoint spec spec.
WatchpointList()
Default constructor makes an empty list.
std::recursive_mutex m_mutex
bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID)
Enquires of the watchpoint in this list with ID watchID whether we should stop.
lldb::watch_id_t FindIDByAddress(lldb::addr_t addr)
Returns the watchpoint id to the watchpoint at address addr.
wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID)
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Watchpoint List mutex.
size_t GetSize() const
Returns the number of elements in this watchpoint list.
WatchpointIterable Watchpoints() const
uint32_t GetHitCount() const
Returns the number hit count of all watchpoints in this list.
void Dump(Stream *s) const
Standard "Dump" method.
std::vector< lldb::watch_id_t > id_vector
bool Remove(lldb::watch_id_t watchID, bool notify)
Removes the watchpoint given by watchID from this list.
~WatchpointList()
Destructor, currently does nothing.
wp_collection::const_iterator GetIDConstIterator(lldb::watch_id_t watchID) const
const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const
Returns a shared pointer to the watchpoint at address addr - const version.
void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
Dump with lldb::DescriptionLevel.
std::list< lldb::WatchpointSP > wp_collection
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
int32_t watch_id_t
Definition lldb-types.h:87
uint64_t addr_t
Definition lldb-types.h:80