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 "SBReproducerPrivate.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"
16 
19 #include "lldb/Core/StreamFile.h"
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 
26 using namespace lldb;
27 using namespace lldb_private;
28 
30 
31 SBWatchpoint::SBWatchpoint(const lldb::WatchpointSP &wp_sp)
32  : m_opaque_wp(wp_sp) {
33  LLDB_RECORD_CONSTRUCTOR(SBWatchpoint, (const lldb::WatchpointSP &), wp_sp);
34 }
35 
37  : m_opaque_wp(rhs.m_opaque_wp) {
39 }
40 
43  SBWatchpoint, operator=,(const lldb::SBWatchpoint &), rhs);
44 
46  return LLDB_RECORD_RESULT(*this);
47 }
48 
49 SBWatchpoint::~SBWatchpoint() = default;
50 
53 
54 
56  lldb::WatchpointSP watchpoint_sp(GetSP());
57  if (watchpoint_sp)
58  watch_id = watchpoint_sp->GetID();
59 
60  return watch_id;
61 }
62 
63 bool SBWatchpoint::IsValid() const {
65  return this->operator bool();
66 }
67 SBWatchpoint::operator bool() const {
68  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBWatchpoint, operator bool);
69 
70  return bool(m_opaque_wp.lock());
71 }
72 
73 bool SBWatchpoint::operator==(const SBWatchpoint &rhs) const {
75  bool, SBWatchpoint, operator==,(const SBWatchpoint &), rhs);
76 
77  return GetSP() == rhs.GetSP();
78 }
79 
80 bool SBWatchpoint::operator!=(const SBWatchpoint &rhs) const {
82  bool, SBWatchpoint, operator!=,(const SBWatchpoint &), rhs);
83 
84  return !(*this == rhs);
85 }
86 
89 
90  SBError sb_error;
91  lldb::WatchpointSP watchpoint_sp(GetSP());
92  if (watchpoint_sp) {
93  sb_error.SetError(watchpoint_sp->GetError());
94  }
95  return LLDB_RECORD_RESULT(sb_error);
96 }
97 
100 
101  int32_t hw_index = -1;
102 
103  lldb::WatchpointSP watchpoint_sp(GetSP());
104  if (watchpoint_sp) {
105  std::lock_guard<std::recursive_mutex> guard(
106  watchpoint_sp->GetTarget().GetAPIMutex());
107  hw_index = watchpoint_sp->GetHardwareIndex();
108  }
109 
110  return hw_index;
111 }
112 
115 
116  addr_t ret_addr = LLDB_INVALID_ADDRESS;
117 
118  lldb::WatchpointSP watchpoint_sp(GetSP());
119  if (watchpoint_sp) {
120  std::lock_guard<std::recursive_mutex> guard(
121  watchpoint_sp->GetTarget().GetAPIMutex());
122  ret_addr = watchpoint_sp->GetLoadAddress();
123  }
124 
125  return ret_addr;
126 }
127 
130 
131  size_t watch_size = 0;
132 
133  lldb::WatchpointSP watchpoint_sp(GetSP());
134  if (watchpoint_sp) {
135  std::lock_guard<std::recursive_mutex> guard(
136  watchpoint_sp->GetTarget().GetAPIMutex());
137  watch_size = watchpoint_sp->GetByteSize();
138  }
139 
140  return watch_size;
141 }
142 
143 void SBWatchpoint::SetEnabled(bool enabled) {
144  LLDB_RECORD_METHOD(void, SBWatchpoint, SetEnabled, (bool), enabled);
145 
146  lldb::WatchpointSP watchpoint_sp(GetSP());
147  if (watchpoint_sp) {
148  Target &target = watchpoint_sp->GetTarget();
149  std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
150  ProcessSP process_sp = target.GetProcessSP();
151  const bool notify = true;
152  if (process_sp) {
153  if (enabled)
154  process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
155  else
156  process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
157  } else {
158  watchpoint_sp->SetEnabled(enabled, notify);
159  }
160  }
161 }
162 
165 
166  lldb::WatchpointSP watchpoint_sp(GetSP());
167  if (watchpoint_sp) {
168  std::lock_guard<std::recursive_mutex> guard(
169  watchpoint_sp->GetTarget().GetAPIMutex());
170  return watchpoint_sp->IsEnabled();
171  } else
172  return false;
173 }
174 
177 
178  uint32_t count = 0;
179  lldb::WatchpointSP watchpoint_sp(GetSP());
180  if (watchpoint_sp) {
181  std::lock_guard<std::recursive_mutex> guard(
182  watchpoint_sp->GetTarget().GetAPIMutex());
183  count = watchpoint_sp->GetHitCount();
184  }
185 
186  return count;
187 }
188 
191 
192  lldb::WatchpointSP watchpoint_sp(GetSP());
193  if (watchpoint_sp) {
194  std::lock_guard<std::recursive_mutex> guard(
195  watchpoint_sp->GetTarget().GetAPIMutex());
196  return watchpoint_sp->GetIgnoreCount();
197  } else
198  return 0;
199 }
200 
203 
204  lldb::WatchpointSP watchpoint_sp(GetSP());
205  if (watchpoint_sp) {
206  std::lock_guard<std::recursive_mutex> guard(
207  watchpoint_sp->GetTarget().GetAPIMutex());
208  watchpoint_sp->SetIgnoreCount(n);
209  }
210 }
211 
214 
215  lldb::WatchpointSP watchpoint_sp(GetSP());
216  if (watchpoint_sp) {
217  std::lock_guard<std::recursive_mutex> guard(
218  watchpoint_sp->GetTarget().GetAPIMutex());
219  return watchpoint_sp->GetConditionText();
220  }
221  return nullptr;
222 }
223 
224 void SBWatchpoint::SetCondition(const char *condition) {
225  LLDB_RECORD_METHOD(void, SBWatchpoint, SetCondition, (const char *),
226  condition);
227 
228  lldb::WatchpointSP watchpoint_sp(GetSP());
229  if (watchpoint_sp) {
230  std::lock_guard<std::recursive_mutex> guard(
231  watchpoint_sp->GetTarget().GetAPIMutex());
232  watchpoint_sp->SetCondition(condition);
233  }
234 }
235 
237  DescriptionLevel level) {
239  (lldb::SBStream &, lldb::DescriptionLevel), description,
240  level);
241 
242  Stream &strm = description.ref();
243 
244  lldb::WatchpointSP watchpoint_sp(GetSP());
245  if (watchpoint_sp) {
246  std::lock_guard<std::recursive_mutex> guard(
247  watchpoint_sp->GetTarget().GetAPIMutex());
248  watchpoint_sp->GetDescription(&strm, level);
249  strm.EOL();
250  } else
251  strm.PutCString("No value");
252 
253  return true;
254 }
255 
258 
259  m_opaque_wp.reset();
260 }
261 
262 lldb::WatchpointSP SBWatchpoint::GetSP() const {
264 
265  return LLDB_RECORD_RESULT(m_opaque_wp.lock());
266 }
267 
268 void SBWatchpoint::SetSP(const lldb::WatchpointSP &sp) {
269  LLDB_RECORD_METHOD(void, SBWatchpoint, SetSP, (const lldb::WatchpointSP &),
270  sp);
271 
272  m_opaque_wp = sp;
273 }
274 
277  (const lldb::SBEvent &), event);
278 
279  return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) !=
280  nullptr;
281 }
282 
283 WatchpointEventType
285  LLDB_RECORD_STATIC_METHOD(lldb::WatchpointEventType, SBWatchpoint,
287  (const lldb::SBEvent &), event);
288 
289  if (event.IsValid())
290  return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent(
291  event.GetSP());
292  return eWatchpointEventTypeInvalidType;
293 }
294 
298  event);
299 
300  SBWatchpoint sb_watchpoint;
301  if (event.IsValid())
302  sb_watchpoint =
303  Watchpoint::WatchpointEventData::GetWatchpointFromEvent(event.GetSP());
304  return LLDB_RECORD_RESULT(sb_watchpoint);
305 }
306 
307 namespace lldb_private {
308 namespace repro {
309 
310 template <>
313  LLDB_REGISTER_CONSTRUCTOR(SBWatchpoint, (const lldb::WatchpointSP &));
316  SBWatchpoint, operator=,(const lldb::SBWatchpoint &));
318  LLDB_REGISTER_METHOD_CONST(bool, SBWatchpoint, IsValid, ());
319  LLDB_REGISTER_METHOD_CONST(bool, SBWatchpoint, operator bool, ());
321  bool, SBWatchpoint, operator==,(const lldb::SBWatchpoint &));
323  bool, SBWatchpoint, operator!=,(const lldb::SBWatchpoint &));
325  LLDB_REGISTER_METHOD(int32_t, SBWatchpoint, GetHardwareIndex, ());
326  LLDB_REGISTER_METHOD(lldb::addr_t, SBWatchpoint, GetWatchAddress, ());
327  LLDB_REGISTER_METHOD(size_t, SBWatchpoint, GetWatchSize, ());
328  LLDB_REGISTER_METHOD(void, SBWatchpoint, SetEnabled, (bool));
329  LLDB_REGISTER_METHOD(bool, SBWatchpoint, IsEnabled, ());
330  LLDB_REGISTER_METHOD(uint32_t, SBWatchpoint, GetHitCount, ());
331  LLDB_REGISTER_METHOD(uint32_t, SBWatchpoint, GetIgnoreCount, ());
332  LLDB_REGISTER_METHOD(void, SBWatchpoint, SetIgnoreCount, (uint32_t));
333  LLDB_REGISTER_METHOD(const char *, SBWatchpoint, GetCondition, ());
334  LLDB_REGISTER_METHOD(void, SBWatchpoint, SetCondition, (const char *));
335  LLDB_REGISTER_METHOD(bool, SBWatchpoint, GetDescription,
337  LLDB_REGISTER_METHOD(void, SBWatchpoint, Clear, ());
338  LLDB_REGISTER_METHOD_CONST(lldb::WatchpointSP, SBWatchpoint, GetSP, ());
339  LLDB_REGISTER_METHOD(void, SBWatchpoint, SetSP,
340  (const lldb::WatchpointSP &));
341  LLDB_REGISTER_STATIC_METHOD(bool, SBWatchpoint, EventIsWatchpointEvent,
342  (const lldb::SBEvent &));
343  LLDB_REGISTER_STATIC_METHOD(lldb::WatchpointEventType, SBWatchpoint,
344  GetWatchpointEventTypeFromEvent,
345  (const lldb::SBEvent &));
347  GetWatchpointFromEvent,
348  (const lldb::SBEvent &));
349 }
350 
351 }
352 }
LLDB_INVALID_WATCH_ID
#define LLDB_INVALID_WATCH_ID
Definition: lldb-defines.h:55
lldb::SBEvent::get
lldb_private::Event * get() const
Definition: SBEvent.cpp:139
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBWatchpoint::GetID
watch_id_t GetID()
Definition: SBWatchpoint.cpp:51
SBDefines.h
lldb::SBWatchpoint::Clear
void Clear()
Definition: SBWatchpoint.cpp:256
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
lldb::SBWatchpoint::SetSP
void SetSP(const lldb::WatchpointSP &sp)
Definition: SBWatchpoint.cpp:268
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBError
Definition: SBError.h:20
lldb::SBWatchpoint::GetWatchpointFromEvent
static lldb::SBWatchpoint GetWatchpointFromEvent(const lldb::SBEvent &event)
Definition: SBWatchpoint.cpp:295
lldb-defines.h
lldb::SBWatchpoint::operator==
bool operator==(const SBWatchpoint &rhs) const
Definition: SBWatchpoint.cpp:73
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb_private::repro::RegisterMethods< SBWatchpoint >
void RegisterMethods< SBWatchpoint >(Registry &R)
Definition: SBWatchpoint.cpp:311
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb::SBEvent
Definition: SBEvent.h:21
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
SBReproducerPrivate.h
lldb::SBWatchpoint::GetWatchSize
size_t GetWatchSize()
Definition: SBWatchpoint.cpp:128
SBWatchpoint.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb_private::Target
Definition: Target.h:451
lldb::SBWatchpoint::SBWatchpoint
SBWatchpoint()
Definition: SBWatchpoint.cpp:29
Process.h
lldb::SBWatchpoint::SetIgnoreCount
void SetIgnoreCount(uint32_t n)
Definition: SBWatchpoint.cpp:201
Target.h
lldb::SBWatchpoint::operator=
const lldb::SBWatchpoint & operator=(const lldb::SBWatchpoint &rhs)
Definition: SBWatchpoint.cpp:41
SBStream.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
Watchpoint.h
lldb::SBWatchpoint::GetHardwareIndex
int32_t GetHardwareIndex()
With -1 representing an invalid hardware index.
Definition: SBWatchpoint.cpp:98
lldb_private::Target::GetAPIMutex
std::recursive_mutex & GetAPIMutex()
Definition: Target.cpp:4449
lldb::SBEvent::GetSP
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:137
lldb::SBWatchpoint::operator!=
bool operator!=(const SBWatchpoint &rhs) const
Definition: SBWatchpoint.cpp:80
lldb::SBWatchpoint::GetDescription
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
Definition: SBWatchpoint.cpp:236
lldb::SBWatchpoint::EventIsWatchpointEvent
static bool EventIsWatchpointEvent(const lldb::SBEvent &event)
Definition: SBWatchpoint.cpp:275
lldb::SBWatchpoint::m_opaque_wp
std::weak_ptr< lldb_private::Watchpoint > m_opaque_wp
Definition: SBWatchpoint.h:80
SBDebugger.h
LLDB_REGISTER_STATIC_METHOD
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:103
sp
@ sp
Definition: CompactUnwindInfo.cpp:1249
lldb::watch_id_t
int32_t watch_id_t
Definition: lldb-types.h:89
lldb::SBError::SetError
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:97
SBAddress.h
lldb::SBWatchpoint::SetEnabled
void SetEnabled(bool enabled)
Definition: SBWatchpoint.cpp:143
lldb-types.h
lldb::SBWatchpoint
Definition: SBWatchpoint.h:16
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
StreamFile.h
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb_private::Target::GetProcessSP
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:211
uint32_t
lldb::SBWatchpoint::SetCondition
void SetCondition(const char *condition)
Definition: SBWatchpoint.cpp:224
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
lldb::SBWatchpoint::GetHitCount
uint32_t GetHitCount()
Definition: SBWatchpoint.cpp:175
lldb::SBWatchpoint::GetWatchpointEventTypeFromEvent
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::SBEvent &event)
Definition: SBWatchpoint.cpp:284
lldb::SBWatchpoint::GetSP
lldb::WatchpointSP GetSP() const
Definition: SBWatchpoint.cpp:262
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
SBEvent.h
lldb::SBWatchpoint::~SBWatchpoint
~SBWatchpoint()
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBEvent::IsValid
bool IsValid() const
Definition: SBEvent.cpp:160
LLDB_RECORD_STATIC_METHOD
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:171
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBWatchpoint::IsValid
bool IsValid() const
Definition: SBWatchpoint.cpp:63
lldb::SBStream
Definition: SBStream.h:18
lldb::SBWatchpoint::IsEnabled
bool IsEnabled()
Definition: SBWatchpoint.cpp:163
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb::SBWatchpoint::GetWatchAddress
lldb::addr_t GetWatchAddress()
Definition: SBWatchpoint.cpp:113
WatchpointList.h
lldb
Definition: SBAddress.h:15
lldb::SBWatchpoint::GetCondition
const char * GetCondition()
Definition: SBWatchpoint.cpp:212
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb::SBWatchpoint::GetIgnoreCount
uint32_t GetIgnoreCount()
Definition: SBWatchpoint.cpp:189
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93
lldb::SBWatchpoint::GetError
SBError GetError()
Definition: SBWatchpoint.cpp:87