LLDB  mainline
SBWatchpoint.cpp
Go to the documentation of this file.
1 //===-- SBWatchpoint.cpp --------------------------------*- 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 
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 
45  m_opaque_wp = rhs.m_opaque_wp;
46  return LLDB_RECORD_RESULT(*this);
47 }
48 
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 NULL;
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  NULL;
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 &));
319  LLDB_REGISTER_METHOD_CONST(bool, SBWatchpoint, operator bool, ());
321  bool, SBWatchpoint, operator==,(const lldb::SBWatchpoint &));
323  bool, SBWatchpoint, operator!=,(const lldb::SBWatchpoint &));
333  LLDB_REGISTER_METHOD(const char *, SBWatchpoint, GetCondition, ());
334  LLDB_REGISTER_METHOD(void, SBWatchpoint, SetCondition, (const char *));
338  LLDB_REGISTER_METHOD_CONST(lldb::WatchpointSP, SBWatchpoint, GetSP, ());
340  (const lldb::WatchpointSP &));
342  (const lldb::SBEvent &));
343  LLDB_REGISTER_STATIC_METHOD(lldb::WatchpointEventType, SBWatchpoint,
345  (const lldb::SBEvent &));
348  (const lldb::SBEvent &));
349 }
350 
351 }
352 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
The registry contains a unique mapping between functions and their ID.
uint32_t GetHitCount()
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool operator==(const SBWatchpoint &rhs) const
const char * GetCondition()
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:97
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:139
int32_t watch_id_t
Definition: lldb-types.h:89
static lldb::WatchpointEventType GetWatchpointEventTypeFromEvent(const lldb::SBEvent &event)
std::recursive_mutex & GetAPIMutex()
Definition: Target.h:539
const lldb::SBWatchpoint & operator=(const lldb::SBWatchpoint &rhs)
lldb_private::Event * get() const
Definition: SBEvent.cpp:141
bool IsValid() const
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
bool IsValid() const
Definition: SBEvent.cpp:162
void SetIgnoreCount(uint32_t n)
static lldb::SBWatchpoint GetWatchpointFromEvent(const lldb::SBEvent &event)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:206
static bool EventIsWatchpointEvent(const lldb::SBEvent &event)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:127
void SetEnabled(bool enabled)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void SetSP(const lldb::WatchpointSP &sp)
lldb::WatchpointSP GetSP() const
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
watch_id_t GetID()
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
lldb::addr_t GetWatchAddress()
uint64_t addr_t
Definition: lldb-types.h:83
#define LLDB_INVALID_WATCH_ID
Definition: lldb-defines.h:55
Definition: SBAddress.h:15
int32_t GetHardwareIndex()
With -1 representing an invalid hardware index.
bool operator!=(const SBWatchpoint &rhs) const
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
void RegisterMethods< SBWatchpoint >(Registry &R)
uint32_t GetIgnoreCount()
void SetCondition(const char *condition)