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 "lldb/API/SBAddress.h"
11#include "lldb/API/SBDebugger.h"
12#include "lldb/API/SBDefines.h"
13#include "lldb/API/SBEvent.h"
14#include "lldb/API/SBStream.h"
16
20#include "lldb/Target/Process.h"
21#include "lldb/Target/Target.h"
22#include "lldb/Utility/Stream.h"
23#include "lldb/lldb-defines.h"
24#include "lldb/lldb-types.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
30
32 : m_opaque_wp(wp_sp) {
33 LLDB_INSTRUMENT_VA(this, wp_sp);
34}
35
37 : m_opaque_wp(rhs.m_opaque_wp) {
38 LLDB_INSTRUMENT_VA(this, rhs);
39}
40
42 LLDB_INSTRUMENT_VA(this, rhs);
43
45 return *this;
46}
47
49
52
54 lldb::WatchpointSP watchpoint_sp(GetSP());
55 if (watchpoint_sp)
56 watch_id = watchpoint_sp->GetID();
57
58 return watch_id;
59}
60
63 return this->operator bool();
64}
65SBWatchpoint::operator bool() const {
67
68 return bool(m_opaque_wp.lock());
69}
70
71bool SBWatchpoint::operator==(const SBWatchpoint &rhs) const {
72 LLDB_INSTRUMENT_VA(this, rhs);
73
74 return GetSP() == rhs.GetSP();
75}
76
77bool SBWatchpoint::operator!=(const SBWatchpoint &rhs) const {
78 LLDB_INSTRUMENT_VA(this, rhs);
79
80 return !(*this == rhs);
81}
82
85
86 SBError sb_error;
87 lldb::WatchpointSP watchpoint_sp(GetSP());
88 if (watchpoint_sp) {
89 sb_error.SetError(watchpoint_sp->GetError());
90 }
91 return sb_error;
92}
93
96
97 int32_t hw_index = -1;
98
99 lldb::WatchpointSP watchpoint_sp(GetSP());
100 if (watchpoint_sp) {
101 std::lock_guard<std::recursive_mutex> guard(
102 watchpoint_sp->GetTarget().GetAPIMutex());
103 hw_index = watchpoint_sp->GetHardwareIndex();
104 }
105
106 return hw_index;
107}
108
110 LLDB_INSTRUMENT_VA(this);
111
112 addr_t ret_addr = LLDB_INVALID_ADDRESS;
113
114 lldb::WatchpointSP watchpoint_sp(GetSP());
115 if (watchpoint_sp) {
116 std::lock_guard<std::recursive_mutex> guard(
117 watchpoint_sp->GetTarget().GetAPIMutex());
118 ret_addr = watchpoint_sp->GetLoadAddress();
119 }
120
121 return ret_addr;
122}
123
125 LLDB_INSTRUMENT_VA(this);
126
127 size_t watch_size = 0;
128
129 lldb::WatchpointSP watchpoint_sp(GetSP());
130 if (watchpoint_sp) {
131 std::lock_guard<std::recursive_mutex> guard(
132 watchpoint_sp->GetTarget().GetAPIMutex());
133 watch_size = watchpoint_sp->GetByteSize();
134 }
135
136 return watch_size;
137}
138
139void SBWatchpoint::SetEnabled(bool enabled) {
140 LLDB_INSTRUMENT_VA(this, enabled);
141
142 lldb::WatchpointSP watchpoint_sp(GetSP());
143 if (watchpoint_sp) {
144 Target &target = watchpoint_sp->GetTarget();
145 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
146 ProcessSP process_sp = target.GetProcessSP();
147 const bool notify = true;
148 if (process_sp) {
149 if (enabled)
150 process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
151 else
152 process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
153 } else {
154 watchpoint_sp->SetEnabled(enabled, notify);
155 }
156 }
157}
158
160 LLDB_INSTRUMENT_VA(this);
161
162 lldb::WatchpointSP watchpoint_sp(GetSP());
163 if (watchpoint_sp) {
164 std::lock_guard<std::recursive_mutex> guard(
165 watchpoint_sp->GetTarget().GetAPIMutex());
166 return watchpoint_sp->IsEnabled();
167 } else
168 return false;
169}
170
172 LLDB_INSTRUMENT_VA(this);
173
174 uint32_t count = 0;
175 lldb::WatchpointSP watchpoint_sp(GetSP());
176 if (watchpoint_sp) {
177 std::lock_guard<std::recursive_mutex> guard(
178 watchpoint_sp->GetTarget().GetAPIMutex());
179 count = watchpoint_sp->GetHitCount();
180 }
181
182 return count;
183}
184
186 LLDB_INSTRUMENT_VA(this);
187
188 lldb::WatchpointSP watchpoint_sp(GetSP());
189 if (watchpoint_sp) {
190 std::lock_guard<std::recursive_mutex> guard(
191 watchpoint_sp->GetTarget().GetAPIMutex());
192 return watchpoint_sp->GetIgnoreCount();
193 } else
194 return 0;
195}
196
198 LLDB_INSTRUMENT_VA(this, n);
199
200 lldb::WatchpointSP watchpoint_sp(GetSP());
201 if (watchpoint_sp) {
202 std::lock_guard<std::recursive_mutex> guard(
203 watchpoint_sp->GetTarget().GetAPIMutex());
204 watchpoint_sp->SetIgnoreCount(n);
205 }
206}
207
209 LLDB_INSTRUMENT_VA(this);
210
211 lldb::WatchpointSP watchpoint_sp(GetSP());
212 if (!watchpoint_sp)
213 return nullptr;
214
215 std::lock_guard<std::recursive_mutex> guard(
216 watchpoint_sp->GetTarget().GetAPIMutex());
217 return ConstString(watchpoint_sp->GetConditionText()).GetCString();
218}
219
220void SBWatchpoint::SetCondition(const char *condition) {
221 LLDB_INSTRUMENT_VA(this, condition);
222
223 lldb::WatchpointSP watchpoint_sp(GetSP());
224 if (watchpoint_sp) {
225 std::lock_guard<std::recursive_mutex> guard(
226 watchpoint_sp->GetTarget().GetAPIMutex());
227 watchpoint_sp->SetCondition(condition);
228 }
229}
230
232 DescriptionLevel level) {
233 LLDB_INSTRUMENT_VA(this, description, level);
234
235 Stream &strm = description.ref();
236
237 lldb::WatchpointSP watchpoint_sp(GetSP());
238 if (watchpoint_sp) {
239 std::lock_guard<std::recursive_mutex> guard(
240 watchpoint_sp->GetTarget().GetAPIMutex());
241 watchpoint_sp->GetDescription(&strm, level);
242 strm.EOL();
243 } else
244 strm.PutCString("No value");
245
246 return true;
247}
248
250 LLDB_INSTRUMENT_VA(this);
251
252 m_opaque_wp.reset();
253}
254
256 LLDB_INSTRUMENT_VA(this);
257
258 return m_opaque_wp.lock();
259}
260
262 LLDB_INSTRUMENT_VA(this, sp);
263
264 m_opaque_wp = sp;
265}
266
268 LLDB_INSTRUMENT_VA(event);
269
271 nullptr;
272}
273
274WatchpointEventType
276 LLDB_INSTRUMENT_VA(event);
277
278 if (event.IsValid())
280 event.GetSP());
281 return eWatchpointEventTypeInvalidType;
282}
283
285 LLDB_INSTRUMENT_VA(event);
286
287 SBWatchpoint sb_watchpoint;
288 if (event.IsValid())
289 sb_watchpoint =
291 return sb_watchpoint;
292}
293
295 LLDB_INSTRUMENT_VA(this);
296
297 lldb::WatchpointSP watchpoint_sp(GetSP());
298 if (watchpoint_sp) {
299 std::lock_guard<std::recursive_mutex> guard(
300 watchpoint_sp->GetTarget().GetAPIMutex());
301 const CompilerType &type = watchpoint_sp->GetCompilerType();
302 return lldb::SBType(type);
303 }
304 return lldb::SBType();
305}
306
308 LLDB_INSTRUMENT_VA(this);
309
310 lldb::WatchpointSP watchpoint_sp(GetSP());
311 if (watchpoint_sp) {
312 std::lock_guard<std::recursive_mutex> guard(
313 watchpoint_sp->GetTarget().GetAPIMutex());
314 if (watchpoint_sp->IsWatchVariable())
317 }
319}
320
322 LLDB_INSTRUMENT_VA(this);
323
324 lldb::WatchpointSP watchpoint_sp(GetSP());
325 if (!watchpoint_sp)
326 return nullptr;
327
328 std::lock_guard<std::recursive_mutex> guard(
329 watchpoint_sp->GetTarget().GetAPIMutex());
330 // Store the result of `GetWatchSpec()` as a ConstString
331 // so that the C string we return has a sufficiently long
332 // lifetime. Note this a memory leak but should be fairly
333 // low impact.
334 return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
335}
336
338 LLDB_INSTRUMENT_VA(this);
339 lldb::WatchpointSP watchpoint_sp(GetSP());
340 if (watchpoint_sp) {
341 std::lock_guard<std::recursive_mutex> guard(
342 watchpoint_sp->GetTarget().GetAPIMutex());
343
344 return watchpoint_sp->WatchpointRead();
345 }
346
347 return false;
348}
349
351 LLDB_INSTRUMENT_VA(this);
352 lldb::WatchpointSP watchpoint_sp(GetSP());
353 if (watchpoint_sp) {
354 std::lock_guard<std::recursive_mutex> guard(
355 watchpoint_sp->GetTarget().GetAPIMutex());
356
357 return watchpoint_sp->WatchpointWrite();
358 }
359
360 return false;
361}
#define LLDB_INSTRUMENT_VA(...)
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:106
lldb_private::Event * get() const
Definition: SBEvent.cpp:132
bool IsValid() const
Definition: SBEvent.cpp:153
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:130
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
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
Definition: SBWatchpoint.h:104
bool operator==(const SBWatchpoint &rhs) const
uint32_t GetHitCount()
uint32_t GetIgnoreCount()
bool IsValid() const
void SetIgnoreCount(uint32_t n)
WatchpointValueKind GetWatchValueKind()
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::SBEvent &event)
int32_t GetHardwareIndex()
With -1 representing an invalid hardware index.
void SetEnabled(bool enabled)
static bool EventIsWatchpointEvent(const lldb::SBEvent &event)
static lldb::SBWatchpoint GetWatchpointFromEvent(const lldb::SBEvent &event)
watch_id_t GetID()
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.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:182
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:205
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:128
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:220
std::recursive_mutex & GetAPIMutex()
Definition: Target.cpp:4907
static lldb::WatchpointSP GetWatchpointFromEvent(const lldb::EventSP &event_sp)
Definition: Watchpoint.cpp:455
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::EventSP &event_sp)
Definition: Watchpoint.cpp:445
static const WatchpointEventData * GetEventDataFromEvent(const Event *event_sp)
Definition: Watchpoint.cpp:434
#define LLDB_INVALID_WATCH_ID
Definition: lldb-defines.h:43
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eWatchPointValueKindInvalid
Watchpoint was created watching a variable.
@ eWatchPointValueKindExpression
@ eWatchPointValueKindVariable
Watchpoint was created watching the result of an expression that was evaluated at creation time.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:367
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
Definition: lldb-forward.h:462
int32_t watch_id_t
Definition: lldb-types.h:85
uint64_t addr_t
Definition: lldb-types.h:79