LLDB  mainline
SBBreakpoint.cpp
Go to the documentation of this file.
1 //===-- SBBreakpoint.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"
12 #include "lldb/API/SBDebugger.h"
13 #include "lldb/API/SBEvent.h"
14 #include "lldb/API/SBProcess.h"
15 #include "lldb/API/SBStream.h"
16 #include "lldb/API/SBStringList.h"
17 #include "lldb/API/SBThread.h"
18 
25 #include "lldb/Core/Address.h"
26 #include "lldb/Core/Debugger.h"
27 #include "lldb/Core/StreamFile.h"
30 #include "lldb/Target/Process.h"
32 #include "lldb/Target/Target.h"
33 #include "lldb/Target/Thread.h"
34 #include "lldb/Target/ThreadSpec.h"
35 #include "lldb/Utility/Stream.h"
36 
38 
39 #include "lldb/lldb-enumerations.h"
40 
41 #include "llvm/ADT/STLExtras.h"
42 
43 using namespace lldb;
44 using namespace lldb_private;
45 
47 
49  : m_opaque_wp(rhs.m_opaque_wp) {
51 }
52 
53 SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
54  : m_opaque_wp(bp_sp) {
55  LLDB_RECORD_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &), bp_sp);
56 }
57 
58 SBBreakpoint::~SBBreakpoint() = default;
59 
62  SBBreakpoint, operator=,(const lldb::SBBreakpoint &), rhs);
63 
64  m_opaque_wp = rhs.m_opaque_wp;
65  return LLDB_RECORD_RESULT(*this);
66 }
67 
70  bool, SBBreakpoint, operator==,(const lldb::SBBreakpoint &), rhs);
71 
72  return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
73 }
74 
77  bool, SBBreakpoint, operator!=,(const lldb::SBBreakpoint &), rhs);
78 
79  return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
80 }
81 
84 
86  BreakpointSP bkpt_sp = GetSP();
87  if (bkpt_sp)
88  break_id = bkpt_sp->GetID();
89 
90  return break_id;
91 }
92 
93 bool SBBreakpoint::IsValid() const {
95  return this->operator bool();
96 }
97 SBBreakpoint::operator bool() const {
98  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, operator bool);
99 
100  BreakpointSP bkpt_sp = GetSP();
101  if (!bkpt_sp)
102  return false;
103  else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
104  return true;
105  else
106  return false;
107 }
108 
111 
112  BreakpointSP bkpt_sp = GetSP();
113  if (bkpt_sp) {
114  std::lock_guard<std::recursive_mutex> guard(
115  bkpt_sp->GetTarget().GetAPIMutex());
116  bkpt_sp->ClearAllBreakpointSites();
117  }
118 }
119 
122  FindLocationByAddress, (lldb::addr_t), vm_addr);
123 
124  SBBreakpointLocation sb_bp_location;
125 
126  BreakpointSP bkpt_sp = GetSP();
127  if (bkpt_sp) {
128  if (vm_addr != LLDB_INVALID_ADDRESS) {
129  std::lock_guard<std::recursive_mutex> guard(
130  bkpt_sp->GetTarget().GetAPIMutex());
131  Address address;
132  Target &target = bkpt_sp->GetTarget();
133  if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
134  address.SetRawAddress(vm_addr);
135  }
136  sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
137  }
138  }
139  return LLDB_RECORD_RESULT(sb_bp_location);
140 }
141 
144  (lldb::addr_t), vm_addr);
145 
147  BreakpointSP bkpt_sp = GetSP();
148 
149  if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
150  std::lock_guard<std::recursive_mutex> guard(
151  bkpt_sp->GetTarget().GetAPIMutex());
152  Address address;
153  Target &target = bkpt_sp->GetTarget();
154  if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
155  address.SetRawAddress(vm_addr);
156  }
157  break_id = bkpt_sp->FindLocationIDByAddress(address);
158  }
159 
160  return break_id;
161 }
162 
165  (lldb::break_id_t), bp_loc_id);
166 
167  SBBreakpointLocation sb_bp_location;
168  BreakpointSP bkpt_sp = GetSP();
169 
170  if (bkpt_sp) {
171  std::lock_guard<std::recursive_mutex> guard(
172  bkpt_sp->GetTarget().GetAPIMutex());
173  sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
174  }
175 
176  return LLDB_RECORD_RESULT(sb_bp_location);
177 }
178 
181  GetLocationAtIndex, (uint32_t), index);
182 
183  SBBreakpointLocation sb_bp_location;
184  BreakpointSP bkpt_sp = GetSP();
185 
186  if (bkpt_sp) {
187  std::lock_guard<std::recursive_mutex> guard(
188  bkpt_sp->GetTarget().GetAPIMutex());
189  sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
190  }
191 
192  return LLDB_RECORD_RESULT(sb_bp_location);
193 }
194 
195 void SBBreakpoint::SetEnabled(bool enable) {
196  LLDB_RECORD_METHOD(void, SBBreakpoint, SetEnabled, (bool), enable);
197 
198  BreakpointSP bkpt_sp = GetSP();
199 
200  if (bkpt_sp) {
201  std::lock_guard<std::recursive_mutex> guard(
202  bkpt_sp->GetTarget().GetAPIMutex());
203  bkpt_sp->SetEnabled(enable);
204  }
205 }
206 
209 
210  BreakpointSP bkpt_sp = GetSP();
211  if (bkpt_sp) {
212  std::lock_guard<std::recursive_mutex> guard(
213  bkpt_sp->GetTarget().GetAPIMutex());
214  return bkpt_sp->IsEnabled();
215  } else
216  return false;
217 }
218 
219 void SBBreakpoint::SetOneShot(bool one_shot) {
220  LLDB_RECORD_METHOD(void, SBBreakpoint, SetOneShot, (bool), one_shot);
221 
222  BreakpointSP bkpt_sp = GetSP();
223 
224  if (bkpt_sp) {
225  std::lock_guard<std::recursive_mutex> guard(
226  bkpt_sp->GetTarget().GetAPIMutex());
227  bkpt_sp->SetOneShot(one_shot);
228  }
229 }
230 
233 
234  BreakpointSP bkpt_sp = GetSP();
235  if (bkpt_sp) {
236  std::lock_guard<std::recursive_mutex> guard(
237  bkpt_sp->GetTarget().GetAPIMutex());
238  return bkpt_sp->IsOneShot();
239  } else
240  return false;
241 }
242 
245 
246  BreakpointSP bkpt_sp = GetSP();
247  if (bkpt_sp) {
248  std::lock_guard<std::recursive_mutex> guard(
249  bkpt_sp->GetTarget().GetAPIMutex());
250  return bkpt_sp->IsInternal();
251  } else
252  return false;
253 }
254 
257 
258  BreakpointSP bkpt_sp = GetSP();
259 
260  if (bkpt_sp) {
261  std::lock_guard<std::recursive_mutex> guard(
262  bkpt_sp->GetTarget().GetAPIMutex());
263  bkpt_sp->SetIgnoreCount(count);
264  }
265 }
266 
267 void SBBreakpoint::SetCondition(const char *condition) {
268  LLDB_RECORD_METHOD(void, SBBreakpoint, SetCondition, (const char *),
269  condition);
270 
271  BreakpointSP bkpt_sp = GetSP();
272  if (bkpt_sp) {
273  std::lock_guard<std::recursive_mutex> guard(
274  bkpt_sp->GetTarget().GetAPIMutex());
275  bkpt_sp->SetCondition(condition);
276  }
277 }
278 
281 
282  BreakpointSP bkpt_sp = GetSP();
283  if (bkpt_sp) {
284  std::lock_guard<std::recursive_mutex> guard(
285  bkpt_sp->GetTarget().GetAPIMutex());
286  return bkpt_sp->GetConditionText();
287  }
288  return nullptr;
289 }
290 
291 void SBBreakpoint::SetAutoContinue(bool auto_continue) {
293  auto_continue);
294 
295  BreakpointSP bkpt_sp = GetSP();
296  if (bkpt_sp) {
297  std::lock_guard<std::recursive_mutex> guard(
298  bkpt_sp->GetTarget().GetAPIMutex());
299  bkpt_sp->SetAutoContinue(auto_continue);
300  }
301 }
302 
305 
306  BreakpointSP bkpt_sp = GetSP();
307  if (bkpt_sp) {
308  std::lock_guard<std::recursive_mutex> guard(
309  bkpt_sp->GetTarget().GetAPIMutex());
310  return bkpt_sp->IsAutoContinue();
311  }
312  return false;
313 }
314 
317 
318  uint32_t count = 0;
319  BreakpointSP bkpt_sp = GetSP();
320  if (bkpt_sp) {
321  std::lock_guard<std::recursive_mutex> guard(
322  bkpt_sp->GetTarget().GetAPIMutex());
323  count = bkpt_sp->GetHitCount();
324  }
325 
326  return count;
327 }
328 
331 
332  uint32_t count = 0;
333  BreakpointSP bkpt_sp = GetSP();
334  if (bkpt_sp) {
335  std::lock_guard<std::recursive_mutex> guard(
336  bkpt_sp->GetTarget().GetAPIMutex());
337  count = bkpt_sp->GetIgnoreCount();
338  }
339 
340  return count;
341 }
342 
345 
346  BreakpointSP bkpt_sp = GetSP();
347  if (bkpt_sp) {
348  std::lock_guard<std::recursive_mutex> guard(
349  bkpt_sp->GetTarget().GetAPIMutex());
350  bkpt_sp->SetThreadID(tid);
351  }
352 }
353 
356 
358  BreakpointSP bkpt_sp = GetSP();
359  if (bkpt_sp) {
360  std::lock_guard<std::recursive_mutex> guard(
361  bkpt_sp->GetTarget().GetAPIMutex());
362  tid = bkpt_sp->GetThreadID();
363  }
364 
365  return tid;
366 }
367 
370 
371  BreakpointSP bkpt_sp = GetSP();
372  if (bkpt_sp) {
373  std::lock_guard<std::recursive_mutex> guard(
374  bkpt_sp->GetTarget().GetAPIMutex());
375  bkpt_sp->GetOptions()->GetThreadSpec()->SetIndex(index);
376  }
377 }
378 
381 
382  uint32_t thread_idx = UINT32_MAX;
383  BreakpointSP bkpt_sp = GetSP();
384  if (bkpt_sp) {
385  std::lock_guard<std::recursive_mutex> guard(
386  bkpt_sp->GetTarget().GetAPIMutex());
387  const ThreadSpec *thread_spec =
388  bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
389  if (thread_spec != nullptr)
390  thread_idx = thread_spec->GetIndex();
391  }
392 
393  return thread_idx;
394 }
395 
396 void SBBreakpoint::SetThreadName(const char *thread_name) {
397  LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadName, (const char *),
398  thread_name);
399 
400  BreakpointSP bkpt_sp = GetSP();
401 
402  if (bkpt_sp) {
403  std::lock_guard<std::recursive_mutex> guard(
404  bkpt_sp->GetTarget().GetAPIMutex());
405  bkpt_sp->GetOptions()->GetThreadSpec()->SetName(thread_name);
406  }
407 }
408 
409 const char *SBBreakpoint::GetThreadName() const {
411 
412  const char *name = nullptr;
413  BreakpointSP bkpt_sp = GetSP();
414  if (bkpt_sp) {
415  std::lock_guard<std::recursive_mutex> guard(
416  bkpt_sp->GetTarget().GetAPIMutex());
417  const ThreadSpec *thread_spec =
418  bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
419  if (thread_spec != nullptr)
420  name = thread_spec->GetName();
421  }
422 
423  return name;
424 }
425 
426 void SBBreakpoint::SetQueueName(const char *queue_name) {
427  LLDB_RECORD_METHOD(void, SBBreakpoint, SetQueueName, (const char *),
428  queue_name);
429 
430  BreakpointSP bkpt_sp = GetSP();
431  if (bkpt_sp) {
432  std::lock_guard<std::recursive_mutex> guard(
433  bkpt_sp->GetTarget().GetAPIMutex());
434  bkpt_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name);
435  }
436 }
437 
438 const char *SBBreakpoint::GetQueueName() const {
440 
441  const char *name = nullptr;
442  BreakpointSP bkpt_sp = GetSP();
443  if (bkpt_sp) {
444  std::lock_guard<std::recursive_mutex> guard(
445  bkpt_sp->GetTarget().GetAPIMutex());
446  const ThreadSpec *thread_spec =
447  bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
448  if (thread_spec)
449  name = thread_spec->GetQueueName();
450  }
451 
452  return name;
453 }
454 
458 
459  size_t num_resolved = 0;
460  BreakpointSP bkpt_sp = GetSP();
461  if (bkpt_sp) {
462  std::lock_guard<std::recursive_mutex> guard(
463  bkpt_sp->GetTarget().GetAPIMutex());
464  num_resolved = bkpt_sp->GetNumResolvedLocations();
465  }
466  return num_resolved;
467 }
468 
471 
472  BreakpointSP bkpt_sp = GetSP();
473  size_t num_locs = 0;
474  if (bkpt_sp) {
475  std::lock_guard<std::recursive_mutex> guard(
476  bkpt_sp->GetTarget().GetAPIMutex());
477  num_locs = bkpt_sp->GetNumLocations();
478  }
479  return num_locs;
480 }
481 
484  (lldb::SBStringList &), commands);
485 
486  BreakpointSP bkpt_sp = GetSP();
487  if (!bkpt_sp)
488  return;
489  if (commands.GetSize() == 0)
490  return;
491 
492  std::lock_guard<std::recursive_mutex> guard(
493  bkpt_sp->GetTarget().GetAPIMutex());
494  std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
496 
497  bkpt_sp->GetOptions()->SetCommandDataCallback(cmd_data_up);
498 }
499 
502  (lldb::SBStringList &), commands);
503 
504  BreakpointSP bkpt_sp = GetSP();
505  if (!bkpt_sp)
506  return false;
507  StringList command_list;
508  bool has_commands =
509  bkpt_sp->GetOptions()->GetCommandLineCallbacks(command_list);
510  if (has_commands)
511  commands.AppendList(command_list);
512  return has_commands;
513 }
514 
517 
518  return GetDescription(s, true);
519 }
520 
521 bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
523  (lldb::SBStream &, bool), s, include_locations);
524 
525  BreakpointSP bkpt_sp = GetSP();
526  if (bkpt_sp) {
527  std::lock_guard<std::recursive_mutex> guard(
528  bkpt_sp->GetTarget().GetAPIMutex());
529  s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
530  bkpt_sp->GetResolverDescription(s.get());
531  bkpt_sp->GetFilterDescription(s.get());
532  if (include_locations) {
533  const size_t num_locations = bkpt_sp->GetNumLocations();
534  s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
535  }
536  return true;
537  }
538  s.Printf("No value");
539  return false;
540 }
541 
544  (lldb::SBAddress &), address);
545 
546  BreakpointSP bkpt_sp = GetSP();
547  SBError error;
548 
549  if (!address.IsValid()) {
550  error.SetErrorString("Can't add an invalid address.");
551  return LLDB_RECORD_RESULT(error);
552  }
553 
554  if (!bkpt_sp) {
555  error.SetErrorString("No breakpoint to add a location to.");
556  return LLDB_RECORD_RESULT(error);
557  }
558 
559  if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
560  error.SetErrorString("Only a scripted resolver can add locations.");
561  return LLDB_RECORD_RESULT(error);
562  }
563 
564  if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
565  bkpt_sp->AddLocation(address.ref());
566  else {
567  StreamString s;
568  address.get()->Dump(&s, &bkpt_sp->GetTarget(),
569  Address::DumpStyleModuleWithFileAddress);
570  error.SetErrorStringWithFormat("Address: %s didn't pass the filter.",
571  s.GetData());
572  }
573  return LLDB_RECORD_RESULT(error);
574 }
575 
578  (lldb::SBBreakpointHitCallback, void *), callback, baton);
579 
580  BreakpointSP bkpt_sp = GetSP();
581 
582  if (bkpt_sp) {
583  std::lock_guard<std::recursive_mutex> guard(
584  bkpt_sp->GetTarget().GetAPIMutex());
585  BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
586  bkpt_sp->SetCallback(SBBreakpointCallbackBaton
587  ::PrivateBreakpointHitCallback, baton_sp,
588  false);
589  }
590 }
591 
593  const char *callback_function_name) {
595  (const char *), callback_function_name);
596 
597  BreakpointSP bkpt_sp = GetSP();
598 
599  if (bkpt_sp) {
600  std::lock_guard<std::recursive_mutex> guard(
601  bkpt_sp->GetTarget().GetAPIMutex());
602  BreakpointOptions *bp_options = bkpt_sp->GetOptions();
603  bkpt_sp->GetTarget()
604  .GetDebugger()
605  .GetScriptInterpreter()
606  ->SetBreakpointCommandCallbackFunction(bp_options,
607  callback_function_name);
608  }
609 }
610 
611 SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
613  (const char *), callback_body_text);
614 
615  BreakpointSP bkpt_sp = GetSP();
616 
617  SBError sb_error;
618  if (bkpt_sp) {
619  std::lock_guard<std::recursive_mutex> guard(
620  bkpt_sp->GetTarget().GetAPIMutex());
621  BreakpointOptions *bp_options = bkpt_sp->GetOptions();
622  Status error =
623  bkpt_sp->GetTarget()
624  .GetDebugger()
625  .GetScriptInterpreter()
626  ->SetBreakpointCommandCallback(bp_options, callback_body_text);
627  sb_error.SetError(error);
628  } else
629  sb_error.SetErrorString("invalid breakpoint");
630 
631  return LLDB_RECORD_RESULT(sb_error);
632 }
633 
634 bool SBBreakpoint::AddName(const char *new_name) {
635  LLDB_RECORD_METHOD(bool, SBBreakpoint, AddName, (const char *), new_name);
636 
637  BreakpointSP bkpt_sp = GetSP();
638 
639  if (bkpt_sp) {
640  std::lock_guard<std::recursive_mutex> guard(
641  bkpt_sp->GetTarget().GetAPIMutex());
642  Status error; // Think I'm just going to swallow the error here, it's
643  // probably more annoying to have to provide it.
644  bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
645  if (error.Fail())
646  return false;
647  }
648 
649  return true;
650 }
651 
652 void SBBreakpoint::RemoveName(const char *name_to_remove) {
653  LLDB_RECORD_METHOD(void, SBBreakpoint, RemoveName, (const char *),
654  name_to_remove);
655 
656  BreakpointSP bkpt_sp = GetSP();
657 
658  if (bkpt_sp) {
659  std::lock_guard<std::recursive_mutex> guard(
660  bkpt_sp->GetTarget().GetAPIMutex());
661  bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
662  ConstString(name_to_remove));
663  }
664 }
665 
666 bool SBBreakpoint::MatchesName(const char *name) {
667  LLDB_RECORD_METHOD(bool, SBBreakpoint, MatchesName, (const char *), name);
668 
669  BreakpointSP bkpt_sp = GetSP();
670 
671  if (bkpt_sp) {
672  std::lock_guard<std::recursive_mutex> guard(
673  bkpt_sp->GetTarget().GetAPIMutex());
674  return bkpt_sp->MatchesName(name);
675  }
676 
677  return false;
678 }
679 
682  names);
683 
684  BreakpointSP bkpt_sp = GetSP();
685 
686  if (bkpt_sp) {
687  std::lock_guard<std::recursive_mutex> guard(
688  bkpt_sp->GetTarget().GetAPIMutex());
689  std::vector<std::string> names_vec;
690  bkpt_sp->GetNames(names_vec);
691  for (std::string name : names_vec) {
692  names.AppendString(name.c_str());
693  }
694  }
695 }
696 
699  (const lldb::SBEvent &), event);
700 
701  return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
702  nullptr;
703 }
704 
705 BreakpointEventType
707  LLDB_RECORD_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
709  (const lldb::SBEvent &), event);
710 
711  if (event.IsValid())
712  return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
713  event.GetSP());
714  return eBreakpointEventTypeInvalidType;
715 }
716 
720  event);
721 
722  if (event.IsValid())
723  return LLDB_RECORD_RESULT(
724  SBBreakpoint(Breakpoint::BreakpointEventData::GetBreakpointFromEvent(
725  event.GetSP())));
727 }
728 
731  uint32_t loc_idx) {
734  (const lldb::SBEvent &, uint32_t), event, loc_idx);
735 
736  SBBreakpointLocation sb_breakpoint_loc;
737  if (event.IsValid())
738  sb_breakpoint_loc.SetLocation(
739  Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
740  event.GetSP(), loc_idx));
741  return LLDB_RECORD_RESULT(sb_breakpoint_loc);
742 }
743 
744 uint32_t
748  (const lldb::SBEvent &), event);
749 
750  uint32_t num_locations = 0;
751  if (event.IsValid())
752  num_locations =
753  (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
754  event.GetSP()));
755  return num_locations;
756 }
757 
760 
761  BreakpointSP bkpt_sp = GetSP();
762  if (bkpt_sp)
763  return bkpt_sp->IsHardware();
764  return false;
765 }
766 
767 BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
768 
769 // This is simple collection of breakpoint id's and their target.
771 public:
772  SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() {
773  if (target_sp && target_sp->IsValid())
774  m_target_wp = target_sp;
775  }
776 
777  ~SBBreakpointListImpl() = default;
778 
779  size_t GetSize() { return m_break_ids.size(); }
780 
781  BreakpointSP GetBreakpointAtIndex(size_t idx) {
782  if (idx >= m_break_ids.size())
783  return BreakpointSP();
784  TargetSP target_sp = m_target_wp.lock();
785  if (!target_sp)
786  return BreakpointSP();
787  lldb::break_id_t bp_id = m_break_ids[idx];
788  return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
789  }
790 
791  BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
792  TargetSP target_sp = m_target_wp.lock();
793  if (!target_sp)
794  return BreakpointSP();
795 
796  for (lldb::break_id_t &break_id : m_break_ids) {
797  if (break_id == desired_id)
798  return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
799  }
800  return BreakpointSP();
801  }
802 
803  bool Append(BreakpointSP bkpt) {
804  TargetSP target_sp = m_target_wp.lock();
805  if (!target_sp || !bkpt)
806  return false;
807  if (bkpt->GetTargetSP() != target_sp)
808  return false;
809  m_break_ids.push_back(bkpt->GetID());
810  return true;
811  }
812 
813  bool AppendIfUnique(BreakpointSP bkpt) {
814  TargetSP target_sp = m_target_wp.lock();
815  if (!target_sp || !bkpt)
816  return false;
817  if (bkpt->GetTargetSP() != target_sp)
818  return false;
819  lldb::break_id_t bp_id = bkpt->GetID();
820  if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) ==
821  m_break_ids.end())
822  return false;
823 
824  m_break_ids.push_back(bkpt->GetID());
825  return true;
826  }
827 
829  TargetSP target_sp = m_target_wp.lock();
830  if (!target_sp)
831  return false;
832  if (id == LLDB_INVALID_BREAK_ID)
833  return false;
834  m_break_ids.push_back(id);
835  return true;
836  }
837 
838  void Clear() { m_break_ids.clear(); }
839 
841  for (lldb::break_id_t id : m_break_ids) {
842  bp_list.AddBreakpointID(BreakpointID(id));
843  }
844  }
845 
846  TargetSP GetTarget() { return m_target_wp.lock(); }
847 
848 private:
849  std::vector<lldb::break_id_t> m_break_ids;
850  TargetWP m_target_wp;
851 };
852 
854  : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
856 }
857 
859 
862 
863  if (!m_opaque_sp)
864  return 0;
865  else
866  return m_opaque_sp->GetSize();
867 }
868 
871  (size_t), idx);
872 
873  if (!m_opaque_sp)
875 
876  BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
877  return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
878 }
879 
882  (lldb::break_id_t), id);
883 
884  if (!m_opaque_sp)
886  BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
887  return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
888 }
889 
892  (const lldb::SBBreakpoint &), sb_bkpt);
893 
894  if (!sb_bkpt.IsValid())
895  return;
896  if (!m_opaque_sp)
897  return;
898  m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
899 }
900 
903  id);
904 
905  if (!m_opaque_sp)
906  return;
907  m_opaque_sp->AppendByID(id);
908 }
909 
912  (const lldb::SBBreakpoint &), sb_bkpt);
913 
914  if (!sb_bkpt.IsValid())
915  return false;
916  if (!m_opaque_sp)
917  return false;
918  return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
919 }
920 
923 
924  if (m_opaque_sp)
925  m_opaque_sp->Clear();
926 }
927 
929  lldb_private::BreakpointIDList &bp_id_list) {
930  if (m_opaque_sp)
931  m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
932 }
933 
934 namespace lldb_private {
935 namespace repro {
936 
937 template <>
941  LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &));
943  SBBreakpoint, operator=,(const lldb::SBBreakpoint &));
945  SBBreakpoint, operator==,(const lldb::SBBreakpoint &));
947  SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
949  LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
950  LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool, ());
951  LLDB_REGISTER_METHOD(void, SBBreakpoint, ClearAllBreakpointSites, ());
953  FindLocationByAddress, (lldb::addr_t));
955  FindLocationIDByAddress, (lldb::addr_t));
957  FindLocationByID, (lldb::break_id_t));
959  GetLocationAtIndex, (uint32_t));
960  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetEnabled, (bool));
961  LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsEnabled, ());
962  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetOneShot, (bool));
963  LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsOneShot, ());
964  LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsInternal, ());
965  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetIgnoreCount, (uint32_t));
966  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCondition, (const char *));
967  LLDB_REGISTER_METHOD(const char *, SBBreakpoint, GetCondition, ());
968  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetAutoContinue, (bool));
969  LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetAutoContinue, ());
971  LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetIgnoreCount, ());
972  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadID, (lldb::tid_t));
973  LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpoint, GetThreadID, ());
974  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadIndex, (uint32_t));
975  LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetThreadIndex, ());
976  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadName, (const char *));
977  LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetThreadName, ());
978  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetQueueName, (const char *));
979  LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetQueueName, ());
980  LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumResolvedLocations,
981  ());
982  LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumLocations, ());
983  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCommandLineCommands,
984  (lldb::SBStringList &));
985  LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetCommandLineCommands,
986  (lldb::SBStringList &));
987  LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
988  (lldb::SBStream &));
989  LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
990  (lldb::SBStream &, bool));
992  (lldb::SBAddress &));
993  LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
994  (const char *));
995  LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
996  (const char *));
997  LLDB_REGISTER_METHOD(bool, SBBreakpoint, AddName, (const char *));
998  LLDB_REGISTER_METHOD(void, SBBreakpoint, RemoveName, (const char *));
999  LLDB_REGISTER_METHOD(bool, SBBreakpoint, MatchesName, (const char *));
1001  LLDB_REGISTER_STATIC_METHOD(bool, SBBreakpoint, EventIsBreakpointEvent,
1002  (const lldb::SBEvent &));
1003  LLDB_REGISTER_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
1004  GetBreakpointEventTypeFromEvent,
1005  (const lldb::SBEvent &));
1007  GetBreakpointFromEvent,
1008  (const lldb::SBEvent &));
1010  GetBreakpointLocationAtIndexFromEvent,
1011  (const lldb::SBEvent &, uint32_t));
1013  GetNumBreakpointLocationsFromEvent,
1014  (const lldb::SBEvent &));
1015  LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsHardware, ());
1016 }
1017 
1018 template <>
1023  GetBreakpointAtIndex, (size_t));
1027  (const lldb::SBBreakpoint &));
1029  (lldb::break_id_t));
1031  (const lldb::SBBreakpoint &));
1033 }
1034 
1035 }
1036 }
static lldb::SBBreakpointLocation GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event, uint32_t loc_idx)
The registry contains a unique mapping between functions and their ID.
bool GetDescription(lldb::SBStream &description)
void SetEnabled(bool enable)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool IsHardware() const
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
int32_t break_id_t
Definition: lldb-types.h:88
void SetThreadIndex(uint32_t index)
bool operator!=(const lldb::SBBreakpoint &rhs)
static lldb::BreakpointEventType GetBreakpointEventTypeFromEvent(const lldb::SBEvent &event)
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: SBError.cpp:131
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
#define LLDB_RECORD_DUMMY(Result, Class, Method, Signature,...)
The LLDB_RECORD_DUMMY macro is special because it doesn&#39;t actually record anything.
const char * GetQueueName() const
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX) const
Dump a description of this object to a Stream.
Definition: Address.cpp:374
SBBreakpoint GetBreakpointAtIndex(size_t idx)
void SetScriptCallbackFunction(const char *callback_function_name)
void RegisterMethods< SBBreakpoint >(Registry &R)
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:97
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:139
bool(* SBBreakpointHitCallback)(void *baton, SBProcess &process, SBThread &thread, lldb::SBBreakpointLocation &location)
Definition: SBDefines.h:96
const char * GetCondition()
const char * GetData() const
Definition: StreamString.h:43
lldb_private::Event * get() const
Definition: SBEvent.cpp:141
void SetCommandLineCommands(SBStringList &commands)
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr)
void AppendString(const char *str)
bool IsValid() const
Definition: SBEvent.cpp:162
bool operator==(const lldb::SBBreakpoint &rhs)
void SetErrorString(const char *err_str)
Definition: SBError.cpp:124
bool Append(BreakpointSP bkpt)
void SetCondition(const char *condition)
static uint32_t GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event_sp)
const lldb::SBBreakpoint & operator=(const lldb::SBBreakpoint &rhs)
const char * GetName() const
Definition: ThreadSpec.cpp:82
const char * GetQueueName() const
Definition: ThreadSpec.cpp:86
static bool EventIsBreakpointEvent(const lldb::SBEvent &event)
#define UINT32_MAX
Definition: lldb-defines.h:31
bool IsOneShot() const
#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
break_id_t GetID() const
lldb_private::Address & ref()
Definition: SBAddress.cpp:188
bool AppendIfUnique(BreakpointSP bkpt)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1012
uint32_t GetSize() const
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:62
void SetQueueName(const char *queue_name)
uint32_t GetIgnoreCount() const
void SetThreadName(const char *thread_name)
uint64_t tid_t
Definition: lldb-types.h:86
lldb::SBBreakpointLocation GetLocationAtIndex(uint32_t index)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list)
BreakpointSP GetBreakpointAtIndex(size_t idx)
lldb::tid_t GetThreadID()
BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id)
A section + offset based address class.
Definition: Address.h:80
size_t GetNumResolvedLocations() const
uint32_t GetThreadIndex() const
SBBreakpointListImpl(lldb::TargetSP target_sp)
void GetNames(SBStringList &names)
void ClearAllBreakpointSites()
void SetCallback(SBBreakpointHitCallback callback, void *baton)
SBBreakpoint FindBreakpointByID(lldb::break_id_t)
SBBreakpointList(SBTarget &target)
lldb::SBBreakpointLocation FindLocationByID(lldb::break_id_t bp_loc_id)
void AppendByID(lldb::break_id_t id)
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list)
bool MatchesName(const char *name)
void SetOneShot(bool one_shot)
#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)
A uniqued constant string class.
Definition: ConstString.h:38
static lldb::SBBreakpoint GetBreakpointFromEvent(const lldb::SBEvent &event)
"lldb/Breakpoint/BreakpointOptions.h" Class that manages the options on a breakpoint or breakpoint lo...
Definition: SBAddress.h:15
lldb_private::Stream * get()
Definition: SBStream.cpp:160
void SetAutoContinue(bool auto_continue)
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:49
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
bool AppendByID(lldb::break_id_t id)
lldb_private::Address * get()
Definition: SBAddress.cpp:201
size_t GetSize() const
void Append(const SBBreakpoint &sb_bkpt)
bool IsValid() const
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
SBError SetScriptCallbackBody(const char *script_body_text)
class LLDB_API SBBreakpoint
Definition: SBDefines.h:24
void RegisterMethods< SBBreakpointList >(Registry &R)
void SetThreadID(lldb::tid_t sb_thread_id)
void SetIgnoreCount(uint32_t count)
bool AppendIfUnique(const SBBreakpoint &sb_bkpt)
void RemoveName(const char *name_to_remove)
SBError AddLocation(SBAddress &address)
size_t GetNumLocations() const
#define LLDB_RECORD_RESULT(Result)
uint32_t GetHitCount() const
lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr)
bool AddName(const char *new_name)
bool AddBreakpointID(BreakpointID bp_id)
bool IsValid() const
Definition: SBAddress.cpp:79
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
bool GetCommandLineCommands(SBStringList &commands)
An error handling class.
Definition: Status.h:44
const char * GetThreadName() const