LLDB  mainline
SBBreakpointLocation.cpp
Go to the documentation of this file.
1 //===-- SBBreakpointLocation.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/SBStream.h"
15 #include "lldb/API/SBStringList.h"
16 
19 #include "lldb/Core/Debugger.h"
20 #include "lldb/Core/StreamFile.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Target/ThreadSpec.h"
25 #include "lldb/Utility/Stream.h"
26 #include "lldb/lldb-defines.h"
27 #include "lldb/lldb-types.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 
34 }
35 
37  const lldb::BreakpointLocationSP &break_loc_sp)
38  : m_opaque_wp(break_loc_sp) {
40  (const lldb::BreakpointLocationSP &), break_loc_sp);
41 }
42 
44  : m_opaque_wp(rhs.m_opaque_wp) {
46  (const lldb::SBBreakpointLocation &), rhs);
47 }
48 
54  rhs);
55 
56  m_opaque_wp = rhs.m_opaque_wp;
57  return LLDB_RECORD_RESULT(*this);
58 }
59 
61 
62 BreakpointLocationSP SBBreakpointLocation::GetSP() const {
63  return m_opaque_wp.lock();
64 }
65 
68  return this->operator bool();
69 }
70 SBBreakpointLocation::operator bool() const {
72 
73  return bool(GetSP());
74 }
75 
78 
79  BreakpointLocationSP loc_sp = GetSP();
80  if (loc_sp) {
81  return LLDB_RECORD_RESULT(SBAddress(&loc_sp->GetAddress()));
82  }
83 
84  return LLDB_RECORD_RESULT(SBAddress());
85 }
86 
90 
91  addr_t ret_addr = LLDB_INVALID_ADDRESS;
92  BreakpointLocationSP loc_sp = GetSP();
93 
94  if (loc_sp) {
95  std::lock_guard<std::recursive_mutex> guard(
96  loc_sp->GetTarget().GetAPIMutex());
97  ret_addr = loc_sp->GetLoadAddress();
98  }
99 
100  return ret_addr;
101 }
102 
104  LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetEnabled, (bool), enabled);
105 
106  BreakpointLocationSP loc_sp = GetSP();
107  if (loc_sp) {
108  std::lock_guard<std::recursive_mutex> guard(
109  loc_sp->GetTarget().GetAPIMutex());
110  loc_sp->SetEnabled(enabled);
111  }
112 }
113 
116 
117  BreakpointLocationSP loc_sp = GetSP();
118  if (loc_sp) {
119  std::lock_guard<std::recursive_mutex> guard(
120  loc_sp->GetTarget().GetAPIMutex());
121  return loc_sp->IsEnabled();
122  } else
123  return false;
124 }
125 
128 
129  BreakpointLocationSP loc_sp = GetSP();
130  if (loc_sp) {
131  std::lock_guard<std::recursive_mutex> guard(
132  loc_sp->GetTarget().GetAPIMutex());
133  return loc_sp->GetHitCount();
134  } else
135  return 0;
136 }
137 
140 
141  BreakpointLocationSP loc_sp = GetSP();
142  if (loc_sp) {
143  std::lock_guard<std::recursive_mutex> guard(
144  loc_sp->GetTarget().GetAPIMutex());
145  return loc_sp->GetIgnoreCount();
146  } else
147  return 0;
148 }
149 
152 
153  BreakpointLocationSP loc_sp = GetSP();
154  if (loc_sp) {
155  std::lock_guard<std::recursive_mutex> guard(
156  loc_sp->GetTarget().GetAPIMutex());
157  loc_sp->SetIgnoreCount(n);
158  }
159 }
160 
161 void SBBreakpointLocation::SetCondition(const char *condition) {
163  condition);
164 
165  BreakpointLocationSP loc_sp = GetSP();
166  if (loc_sp) {
167  std::lock_guard<std::recursive_mutex> guard(
168  loc_sp->GetTarget().GetAPIMutex());
169  loc_sp->SetCondition(condition);
170  }
171 }
172 
175 
176  BreakpointLocationSP loc_sp = GetSP();
177  if (loc_sp) {
178  std::lock_guard<std::recursive_mutex> guard(
179  loc_sp->GetTarget().GetAPIMutex());
180  return loc_sp->GetConditionText();
181  }
182  return NULL;
183 }
184 
185 void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
187  auto_continue);
188 
189  BreakpointLocationSP loc_sp = GetSP();
190  if (loc_sp) {
191  std::lock_guard<std::recursive_mutex> guard(
192  loc_sp->GetTarget().GetAPIMutex());
193  loc_sp->SetAutoContinue(auto_continue);
194  }
195 }
196 
199 
200  BreakpointLocationSP loc_sp = GetSP();
201  if (loc_sp) {
202  std::lock_guard<std::recursive_mutex> guard(
203  loc_sp->GetTarget().GetAPIMutex());
204  return loc_sp->IsAutoContinue();
205  }
206  return false;
207 }
208 
210  const char *callback_function_name) {
212  (const char *), callback_function_name);
213 
214  BreakpointLocationSP loc_sp = GetSP();
215 
216  if (loc_sp) {
217  std::lock_guard<std::recursive_mutex> guard(
218  loc_sp->GetTarget().GetAPIMutex());
219  BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
220  loc_sp->GetBreakpoint()
221  .GetTarget()
222  .GetDebugger()
223  .GetScriptInterpreter()
224  ->SetBreakpointCommandCallbackFunction(bp_options,
225  callback_function_name);
226  }
227 }
228 
229 SBError
230 SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) {
232  (const char *), callback_body_text);
233 
234  BreakpointLocationSP loc_sp = GetSP();
235 
236  SBError sb_error;
237  if (loc_sp) {
238  std::lock_guard<std::recursive_mutex> guard(
239  loc_sp->GetTarget().GetAPIMutex());
240  BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
241  Status error =
242  loc_sp->GetBreakpoint()
243  .GetTarget()
244  .GetDebugger()
245  .GetScriptInterpreter()
246  ->SetBreakpointCommandCallback(bp_options, callback_body_text);
247  sb_error.SetError(error);
248  } else
249  sb_error.SetErrorString("invalid breakpoint");
250 
251  return LLDB_RECORD_RESULT(sb_error);
252 }
253 
256  (lldb::SBStringList &), commands);
257 
258  BreakpointLocationSP loc_sp = GetSP();
259  if (!loc_sp)
260  return;
261  if (commands.GetSize() == 0)
262  return;
263 
264  std::lock_guard<std::recursive_mutex> guard(
265  loc_sp->GetTarget().GetAPIMutex());
266  std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
268 
269  loc_sp->GetLocationOptions()->SetCommandDataCallback(cmd_data_up);
270 }
271 
274  (lldb::SBStringList &), commands);
275 
276  BreakpointLocationSP loc_sp = GetSP();
277  if (!loc_sp)
278  return false;
279  StringList command_list;
280  bool has_commands =
281  loc_sp->GetLocationOptions()->GetCommandLineCallbacks(command_list);
282  if (has_commands)
283  commands.AppendList(command_list);
284  return has_commands;
285 }
286 
289  thread_id);
290 
291  BreakpointLocationSP loc_sp = GetSP();
292  if (loc_sp) {
293  std::lock_guard<std::recursive_mutex> guard(
294  loc_sp->GetTarget().GetAPIMutex());
295  loc_sp->SetThreadID(thread_id);
296  }
297 }
298 
301 
303  BreakpointLocationSP loc_sp = GetSP();
304  if (loc_sp) {
305  std::lock_guard<std::recursive_mutex> guard(
306  loc_sp->GetTarget().GetAPIMutex());
307  return loc_sp->GetThreadID();
308  }
309  return tid;
310 }
311 
314  index);
315 
316  BreakpointLocationSP loc_sp = GetSP();
317  if (loc_sp) {
318  std::lock_guard<std::recursive_mutex> guard(
319  loc_sp->GetTarget().GetAPIMutex());
320  loc_sp->SetThreadIndex(index);
321  }
322 }
323 
327 
328  uint32_t thread_idx = UINT32_MAX;
329  BreakpointLocationSP loc_sp = GetSP();
330  if (loc_sp) {
331  std::lock_guard<std::recursive_mutex> guard(
332  loc_sp->GetTarget().GetAPIMutex());
333  return loc_sp->GetThreadIndex();
334  }
335  return thread_idx;
336 }
337 
338 void SBBreakpointLocation::SetThreadName(const char *thread_name) {
340  thread_name);
341 
342  BreakpointLocationSP loc_sp = GetSP();
343  if (loc_sp) {
344  std::lock_guard<std::recursive_mutex> guard(
345  loc_sp->GetTarget().GetAPIMutex());
346  loc_sp->SetThreadName(thread_name);
347  }
348 }
349 
352  GetThreadName);
353 
354  BreakpointLocationSP loc_sp = GetSP();
355  if (loc_sp) {
356  std::lock_guard<std::recursive_mutex> guard(
357  loc_sp->GetTarget().GetAPIMutex());
358  return loc_sp->GetThreadName();
359  }
360  return NULL;
361 }
362 
363 void SBBreakpointLocation::SetQueueName(const char *queue_name) {
365  queue_name);
366 
367  BreakpointLocationSP loc_sp = GetSP();
368  if (loc_sp) {
369  std::lock_guard<std::recursive_mutex> guard(
370  loc_sp->GetTarget().GetAPIMutex());
371  loc_sp->SetQueueName(queue_name);
372  }
373 }
374 
377  GetQueueName);
378 
379  BreakpointLocationSP loc_sp = GetSP();
380  if (loc_sp) {
381  std::lock_guard<std::recursive_mutex> guard(
382  loc_sp->GetTarget().GetAPIMutex());
383  loc_sp->GetQueueName();
384  }
385  return NULL;
386 }
387 
390 
391  BreakpointLocationSP loc_sp = GetSP();
392  if (loc_sp) {
393  std::lock_guard<std::recursive_mutex> guard(
394  loc_sp->GetTarget().GetAPIMutex());
395  return loc_sp->IsResolved();
396  }
397  return false;
398 }
399 
400 void SBBreakpointLocation::SetLocation(
401  const lldb::BreakpointLocationSP &break_loc_sp) {
402  // Uninstall the callbacks?
403  m_opaque_wp = break_loc_sp;
404 }
405 
407  DescriptionLevel level) {
409  (lldb::SBStream &, lldb::DescriptionLevel), description,
410  level);
411 
412  Stream &strm = description.ref();
413  BreakpointLocationSP loc_sp = GetSP();
414 
415  if (loc_sp) {
416  std::lock_guard<std::recursive_mutex> guard(
417  loc_sp->GetTarget().GetAPIMutex());
418  loc_sp->GetDescription(&strm, level);
419  strm.EOL();
420  } else
421  strm.PutCString("No value");
422 
423  return true;
424 }
425 
428 
429  BreakpointLocationSP loc_sp = GetSP();
430  if (loc_sp) {
431  std::lock_guard<std::recursive_mutex> guard(
432  loc_sp->GetTarget().GetAPIMutex());
433  return loc_sp->GetID();
434  } else
435  return LLDB_INVALID_BREAK_ID;
436 }
437 
440  GetBreakpoint);
441 
442  BreakpointLocationSP loc_sp = GetSP();
443 
444  SBBreakpoint sb_bp;
445  if (loc_sp) {
446  std::lock_guard<std::recursive_mutex> guard(
447  loc_sp->GetTarget().GetAPIMutex());
448  sb_bp = loc_sp->GetBreakpoint().shared_from_this();
449  }
450 
451  return LLDB_RECORD_RESULT(sb_bp);
452 }
453 
454 namespace lldb_private {
455 namespace repro {
456 
457 template <>
461  (const lldb::BreakpointLocationSP &));
463  (const lldb::SBBreakpointLocation &));
466  SBBreakpointLocation, operator=,(const lldb::SBBreakpointLocation &));
468  LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointLocation, operator bool, ());
471  ());
477  (uint32_t));
479  (const char *));
484  (const char *));
486  SetScriptCallbackBody, (const char *));
488  (lldb::SBStringList &));
490  (lldb::SBStringList &));
492  (lldb::tid_t));
495  (uint32_t));
497  ());
499  (const char *));
501  GetThreadName, ());
503  (const char *));
505  ());
511  GetBreakpoint, ());
512 }
513 
514 }
515 }
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.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
int32_t break_id_t
Definition: lldb-types.h:88
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void SetThreadID(lldb::tid_t sb_thread_id)
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:97
void SetCommandLineCommands(SBStringList &commands)
void SetErrorString(const char *err_str)
Definition: SBError.cpp:124
void RegisterMethods< SBBreakpointLocation >(Registry &R)
void SetAutoContinue(bool auto_continue)
#define UINT32_MAX
Definition: lldb-defines.h:31
#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
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:127
void SetQueueName(const char *queue_name)
uint32_t GetSize() const
const char * GetThreadName() const
uint64_t tid_t
Definition: lldb-types.h:86
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
class LLDB_API SBAddress
Definition: SBDefines.h:22
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
bool GetDescription(lldb::SBStream &description, DescriptionLevel level)
SBError SetScriptCallbackBody(const char *script_body_text)
const lldb::SBBreakpointLocation & operator=(const lldb::SBBreakpointLocation &rhs)
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:93
uint64_t addr_t
Definition: lldb-types.h:83
void AppendList(const char **strv, int strc)
void SetThreadIndex(uint32_t index)
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
bool GetCommandLineCommands(SBStringList &commands)
void SetThreadName(const char *thread_name)
Definition: SBAddress.h:15
void SetScriptCallbackFunction(const char *callback_function_name)
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:49
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
void SetCondition(const char *condition)
An error handling class.
Definition: Status.h:44