LLDB mainline
SBWatchpoint.cpp
Go to the documentation of this file.
1//===-- SBWatchpoint.cpp --------------------------------------------------===//
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
10#include "Utils.h"
11#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBDebugger.h"
13#include "lldb/API/SBDefines.h"
14#include "lldb/API/SBEvent.h"
15#include "lldb/API/SBStream.h"
17
21#include "lldb/Target/Process.h"
22#include "lldb/Target/Target.h"
23#include "lldb/Utility/Stream.h"
24#include "lldb/lldb-defines.h"
25#include "lldb/lldb-types.h"
26
27using namespace lldb;
28using namespace lldb_private;
29
31
33 : m_opaque_wp(wp_sp) {
34 LLDB_INSTRUMENT_VA(this, wp_sp);
35}
36
41
43 LLDB_INSTRUMENT_VA(this, rhs);
44
46 return *this;
47}
48
50
53
55 lldb::WatchpointSP watchpoint_sp(GetSP());
56 if (watchpoint_sp)
57 watch_id = watchpoint_sp->GetID();
58
59 return watch_id;
60}
61
64 return this->operator bool();
65}
66SBWatchpoint::operator bool() const {
68
69 return bool(m_opaque_wp.lock());
70}
71
72bool SBWatchpoint::operator==(const SBWatchpoint &rhs) const {
73 LLDB_INSTRUMENT_VA(this, rhs);
74
75 return GetSP() == rhs.GetSP();
76}
77
78bool SBWatchpoint::operator!=(const SBWatchpoint &rhs) const {
79 LLDB_INSTRUMENT_VA(this, rhs);
80
81 return !(*this == rhs);
82}
83
86
87 SBError sb_error;
88 lldb::WatchpointSP watchpoint_sp(GetSP());
89 if (watchpoint_sp) {
90 sb_error.SetError(watchpoint_sp->GetError().Clone());
91 }
92 return sb_error;
93}
94
97
98 // For processes using gdb remote protocol,
99 // we cannot determine the hardware breakpoint
100 // index reliably; providing possibly correct
101 // guesses is not useful to anyone.
102 return -1;
103}
104
106 LLDB_INSTRUMENT_VA(this);
107
108 addr_t ret_addr = LLDB_INVALID_ADDRESS;
109
110 lldb::WatchpointSP watchpoint_sp(GetSP());
111 if (watchpoint_sp) {
112 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
113 std::lock_guard<TargetAPIMutex> guard(api_lock);
114 ret_addr = watchpoint_sp->GetLoadAddress();
115 }
116
117 return ret_addr;
118}
119
121 LLDB_INSTRUMENT_VA(this);
122
123 size_t watch_size = 0;
124
125 lldb::WatchpointSP watchpoint_sp(GetSP());
126 if (watchpoint_sp) {
127 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
128 std::lock_guard<TargetAPIMutex> guard(api_lock);
129 watch_size = watchpoint_sp->GetByteSize();
130 }
131
132 return watch_size;
133}
134
135void SBWatchpoint::SetEnabled(bool enabled) {
136 LLDB_INSTRUMENT_VA(this, enabled);
137
138 lldb::WatchpointSP watchpoint_sp(GetSP());
139 if (watchpoint_sp) {
140 Target &target = watchpoint_sp->GetTarget();
141 TargetAPIMutex api_lock = target.GetAPIMutex();
142 std::lock_guard<TargetAPIMutex> guard(api_lock);
143 ProcessSP process_sp = target.GetProcessSP();
144 const bool notify = true;
145 if (process_sp) {
146 if (enabled)
147 process_sp->EnableWatchpoint(watchpoint_sp, notify);
148 else
149 process_sp->DisableWatchpoint(watchpoint_sp, notify);
150 } else {
151 watchpoint_sp->SetEnabled(enabled, notify);
152 }
153 }
154}
155
157 LLDB_INSTRUMENT_VA(this);
158
159 lldb::WatchpointSP watchpoint_sp(GetSP());
160 if (watchpoint_sp) {
161 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
162 std::lock_guard<TargetAPIMutex> guard(api_lock);
163 return watchpoint_sp->IsEnabled();
164 } else
165 return false;
166}
167
169 LLDB_INSTRUMENT_VA(this);
170
171 uint32_t count = 0;
172 lldb::WatchpointSP watchpoint_sp(GetSP());
173 if (watchpoint_sp) {
174 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
175 std::lock_guard<TargetAPIMutex> guard(api_lock);
176 count = watchpoint_sp->GetHitCount();
177 }
178
179 return count;
180}
181
183 LLDB_INSTRUMENT_VA(this);
184
185 lldb::WatchpointSP watchpoint_sp(GetSP());
186 if (watchpoint_sp) {
187 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
188 std::lock_guard<TargetAPIMutex> guard(api_lock);
189 return watchpoint_sp->GetIgnoreCount();
190 } else
191 return 0;
192}
193
195 LLDB_INSTRUMENT_VA(this, n);
196
197 lldb::WatchpointSP watchpoint_sp(GetSP());
198 if (watchpoint_sp) {
199 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
200 std::lock_guard<TargetAPIMutex> guard(api_lock);
201 watchpoint_sp->SetIgnoreCount(n);
202 }
203}
204
206 LLDB_INSTRUMENT_VA(this);
207
208 lldb::WatchpointSP watchpoint_sp(GetSP());
209 if (!watchpoint_sp)
210 return nullptr;
211
212 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
213 std::lock_guard<TargetAPIMutex> guard(api_lock);
214 return GetDebuggerStringPool(watchpoint_sp->GetTarget())
215 .Intern(watchpoint_sp->GetConditionText());
216}
217
218void SBWatchpoint::SetCondition(const char *condition) {
219 LLDB_INSTRUMENT_VA(this, condition);
220
221 lldb::WatchpointSP watchpoint_sp(GetSP());
222 if (watchpoint_sp) {
223 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
224 std::lock_guard<TargetAPIMutex> guard(api_lock);
225 watchpoint_sp->SetCondition(condition);
226 }
227}
228
230 DescriptionLevel level) {
231 LLDB_INSTRUMENT_VA(this, description, level);
232
233 Stream &strm = description.ref();
234
235 lldb::WatchpointSP watchpoint_sp(GetSP());
236 if (watchpoint_sp) {
237 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
238 std::lock_guard<TargetAPIMutex> guard(api_lock);
239 watchpoint_sp->GetDescription(&strm, level);
240 strm.EOL();
241 } else
242 strm.PutCString("No value");
243
244 return true;
245}
246
248 LLDB_INSTRUMENT_VA(this);
249
250 m_opaque_wp.reset();
251}
252
254 LLDB_INSTRUMENT_VA(this);
255
256 return m_opaque_wp.lock();
257}
258
264
271
272WatchpointEventType
274 LLDB_INSTRUMENT_VA(event);
275
276 if (event.IsValid())
278 event.GetSP());
279 return eWatchpointEventTypeInvalidType;
280}
281
283 LLDB_INSTRUMENT_VA(event);
284
285 SBWatchpoint sb_watchpoint;
286 if (event.IsValid())
287 sb_watchpoint =
289 return sb_watchpoint;
290}
291
293 LLDB_INSTRUMENT_VA(this);
294
295 lldb::WatchpointSP watchpoint_sp(GetSP());
296 if (watchpoint_sp) {
297 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
298 std::lock_guard<TargetAPIMutex> guard(api_lock);
299 const CompilerType &type = watchpoint_sp->GetCompilerType();
300 return lldb::SBType(type);
301 }
302 return lldb::SBType();
303}
304
306 LLDB_INSTRUMENT_VA(this);
307
308 lldb::WatchpointSP watchpoint_sp(GetSP());
309 if (watchpoint_sp) {
310 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
311 std::lock_guard<TargetAPIMutex> guard(api_lock);
312 if (watchpoint_sp->IsWatchVariable())
315 }
317}
318
320 LLDB_INSTRUMENT_VA(this);
321
322 lldb::WatchpointSP watchpoint_sp(GetSP());
323 if (!watchpoint_sp)
324 return nullptr;
325
326 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
327 std::lock_guard<TargetAPIMutex> guard(api_lock);
328 return GetDebuggerStringPool(watchpoint_sp->GetTarget())
329 .InternNonEmpty(watchpoint_sp->GetWatchSpec());
330}
331
333 LLDB_INSTRUMENT_VA(this);
334 lldb::WatchpointSP watchpoint_sp(GetSP());
335 if (watchpoint_sp) {
336 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
337 std::lock_guard<TargetAPIMutex> guard(api_lock);
338
339 return watchpoint_sp->WatchpointRead();
340 }
341
342 return false;
343}
344
346 LLDB_INSTRUMENT_VA(this);
347 lldb::WatchpointSP watchpoint_sp(GetSP());
348 if (watchpoint_sp) {
349 TargetAPIMutex api_lock = watchpoint_sp->GetTarget().GetAPIMutex();
350 std::lock_guard<TargetAPIMutex> guard(api_lock);
351
352 return watchpoint_sp->WatchpointWrite() ||
353 watchpoint_sp->WatchpointModify();
354 }
355
356 return false;
357}
#define LLDB_INSTRUMENT_VA(...)
void SetError(uint32_t err, lldb::ErrorType type)
Definition SBError.cpp:124
lldb_private::Event * get() const
Definition SBEvent.cpp:136
bool IsValid() const
Definition SBEvent.cpp:157
lldb::EventSP & GetSP() const
Definition SBEvent.cpp:134
lldb_private::Stream & ref()
Definition SBStream.cpp:179
void SetCondition(const char *condition)
const char * GetCondition()
void SetSP(const lldb::WatchpointSP &sp)
const char * GetWatchSpec()
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
lldb::addr_t GetWatchAddress()
lldb::SBType GetType()
std::weak_ptr< lldb_private::Watchpoint > m_opaque_wp
bool operator==(const SBWatchpoint &rhs) const
uint32_t GetIgnoreCount()
bool IsValid() const
void SetIgnoreCount(uint32_t n)
WatchpointValueKind GetWatchValueKind()
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::SBEvent &event)
int32_t GetHardwareIndex()
void SetEnabled(bool enabled)
static bool EventIsWatchpointEvent(const lldb::SBEvent &event)
static lldb::SBWatchpoint GetWatchpointFromEvent(const lldb::SBEvent &event)
bool operator!=(const SBWatchpoint &rhs) const
lldb::WatchpointSP GetSP() const
const lldb::SBWatchpoint & operator=(const lldb::SBWatchpoint &rhs)
Generic representation of a type in a programming language.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
TargetAPIMutex GetAPIMutex()
Returns a handle resolved to the mutex to serialize on before touching the target through the SB API.
Definition Target.cpp:6224
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:335
static lldb::WatchpointSP GetWatchpointFromEvent(const lldb::EventSP &event_sp)
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::EventSP &event_sp)
static const WatchpointEventData * GetEventDataFromEvent(const Event *event_sp)
#define LLDB_INVALID_WATCH_ID
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
StringPoolRef GetDebuggerStringPool(const Target &target)
Strings interned here live as long as target's debugger.
Definition Utils.h:21
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eWatchPointValueKindInvalid
@ eWatchPointValueKindExpression
Watchpoint was created watching the result of an expression that was evaluated at creation time.
@ eWatchPointValueKindVariable
Watchpoint was created watching a variable.
class LLDB_API SBType
Definition SBDefines.h:124
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
int32_t watch_id_t
Definition lldb-types.h:89
uint64_t addr_t
Definition lldb-types.h:80