LLDB  mainline
SBBreakpoint.cpp
Go to the documentation of this file.
1 //===-- SBBreakpoint.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 
11 #include "lldb/API/SBDebugger.h"
12 #include "lldb/API/SBEvent.h"
13 #include "lldb/API/SBProcess.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/API/SBStringList.h"
17 #include "lldb/API/SBThread.h"
19 
26 #include "lldb/Core/Address.h"
27 #include "lldb/Core/Debugger.h"
28 #include "lldb/Core/StreamFile.h"
32 #include "lldb/Target/Process.h"
34 #include "lldb/Target/Target.h"
35 #include "lldb/Target/Thread.h"
36 #include "lldb/Target/ThreadSpec.h"
37 #include "lldb/Utility/Stream.h"
38 
40 
41 #include "lldb/lldb-enumerations.h"
42 
43 #include "llvm/ADT/STLExtras.h"
44 
45 using namespace lldb;
46 using namespace lldb_private;
47 
49 
51  : m_opaque_wp(rhs.m_opaque_wp) {
52  LLDB_INSTRUMENT_VA(this, rhs);
53 }
54 
55 SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
56  : m_opaque_wp(bp_sp) {
57  LLDB_INSTRUMENT_VA(this, bp_sp);
58 }
59 
60 SBBreakpoint::~SBBreakpoint() = default;
61 
63  LLDB_INSTRUMENT_VA(this, rhs);
64 
66  return *this;
67 }
68 
70  LLDB_INSTRUMENT_VA(this, rhs);
71 
72  return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
73 }
74 
76  LLDB_INSTRUMENT_VA(this, rhs);
77 
78  return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
79 }
80 
82  LLDB_INSTRUMENT_VA(this);
83 
84  BreakpointSP bkpt_sp = GetSP();
85  if (bkpt_sp)
86  return SBTarget(bkpt_sp->GetTargetSP());
87 
88  return SBTarget();
89 }
90 
92  LLDB_INSTRUMENT_VA(this);
93 
95  BreakpointSP bkpt_sp = GetSP();
96  if (bkpt_sp)
97  break_id = bkpt_sp->GetID();
98 
99  return break_id;
100 }
101 
102 bool SBBreakpoint::IsValid() const {
103  LLDB_INSTRUMENT_VA(this);
104  return this->operator bool();
105 }
106 SBBreakpoint::operator bool() const {
107  LLDB_INSTRUMENT_VA(this);
108 
109  BreakpointSP bkpt_sp = GetSP();
110  if (!bkpt_sp)
111  return false;
112  else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
113  return true;
114  else
115  return false;
116 }
117 
119  LLDB_INSTRUMENT_VA(this);
120 
121  BreakpointSP bkpt_sp = GetSP();
122  if (bkpt_sp) {
123  std::lock_guard<std::recursive_mutex> guard(
124  bkpt_sp->GetTarget().GetAPIMutex());
125  bkpt_sp->ClearAllBreakpointSites();
126  }
127 }
128 
130  LLDB_INSTRUMENT_VA(this, vm_addr);
131 
132  SBBreakpointLocation sb_bp_location;
133 
134  BreakpointSP bkpt_sp = GetSP();
135  if (bkpt_sp) {
136  if (vm_addr != LLDB_INVALID_ADDRESS) {
137  std::lock_guard<std::recursive_mutex> guard(
138  bkpt_sp->GetTarget().GetAPIMutex());
139  Address address;
140  Target &target = bkpt_sp->GetTarget();
141  if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
142  address.SetRawAddress(vm_addr);
143  }
144  sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
145  }
146  }
147  return sb_bp_location;
148 }
149 
151  LLDB_INSTRUMENT_VA(this, vm_addr);
152 
154  BreakpointSP bkpt_sp = GetSP();
155 
156  if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
157  std::lock_guard<std::recursive_mutex> guard(
158  bkpt_sp->GetTarget().GetAPIMutex());
159  Address address;
160  Target &target = bkpt_sp->GetTarget();
161  if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
162  address.SetRawAddress(vm_addr);
163  }
164  break_id = bkpt_sp->FindLocationIDByAddress(address);
165  }
166 
167  return break_id;
168 }
169 
171  LLDB_INSTRUMENT_VA(this, bp_loc_id);
172 
173  SBBreakpointLocation sb_bp_location;
174  BreakpointSP bkpt_sp = GetSP();
175 
176  if (bkpt_sp) {
177  std::lock_guard<std::recursive_mutex> guard(
178  bkpt_sp->GetTarget().GetAPIMutex());
179  sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
180  }
181 
182  return sb_bp_location;
183 }
184 
186  LLDB_INSTRUMENT_VA(this, index);
187 
188  SBBreakpointLocation sb_bp_location;
189  BreakpointSP bkpt_sp = GetSP();
190 
191  if (bkpt_sp) {
192  std::lock_guard<std::recursive_mutex> guard(
193  bkpt_sp->GetTarget().GetAPIMutex());
194  sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
195  }
196 
197  return sb_bp_location;
198 }
199 
200 void SBBreakpoint::SetEnabled(bool enable) {
201  LLDB_INSTRUMENT_VA(this, enable);
202 
203  BreakpointSP bkpt_sp = GetSP();
204 
205  if (bkpt_sp) {
206  std::lock_guard<std::recursive_mutex> guard(
207  bkpt_sp->GetTarget().GetAPIMutex());
208  bkpt_sp->SetEnabled(enable);
209  }
210 }
211 
213  LLDB_INSTRUMENT_VA(this);
214 
215  BreakpointSP bkpt_sp = GetSP();
216  if (bkpt_sp) {
217  std::lock_guard<std::recursive_mutex> guard(
218  bkpt_sp->GetTarget().GetAPIMutex());
219  return bkpt_sp->IsEnabled();
220  } else
221  return false;
222 }
223 
224 void SBBreakpoint::SetOneShot(bool one_shot) {
225  LLDB_INSTRUMENT_VA(this, one_shot);
226 
227  BreakpointSP bkpt_sp = GetSP();
228 
229  if (bkpt_sp) {
230  std::lock_guard<std::recursive_mutex> guard(
231  bkpt_sp->GetTarget().GetAPIMutex());
232  bkpt_sp->SetOneShot(one_shot);
233  }
234 }
235 
237  LLDB_INSTRUMENT_VA(this);
238 
239  BreakpointSP bkpt_sp = GetSP();
240  if (bkpt_sp) {
241  std::lock_guard<std::recursive_mutex> guard(
242  bkpt_sp->GetTarget().GetAPIMutex());
243  return bkpt_sp->IsOneShot();
244  } else
245  return false;
246 }
247 
249  LLDB_INSTRUMENT_VA(this);
250 
251  BreakpointSP bkpt_sp = GetSP();
252  if (bkpt_sp) {
253  std::lock_guard<std::recursive_mutex> guard(
254  bkpt_sp->GetTarget().GetAPIMutex());
255  return bkpt_sp->IsInternal();
256  } else
257  return false;
258 }
259 
261  LLDB_INSTRUMENT_VA(this, count);
262 
263  BreakpointSP bkpt_sp = GetSP();
264 
265  if (bkpt_sp) {
266  std::lock_guard<std::recursive_mutex> guard(
267  bkpt_sp->GetTarget().GetAPIMutex());
268  bkpt_sp->SetIgnoreCount(count);
269  }
270 }
271 
272 void SBBreakpoint::SetCondition(const char *condition) {
273  LLDB_INSTRUMENT_VA(this, condition);
274 
275  BreakpointSP bkpt_sp = GetSP();
276  if (bkpt_sp) {
277  std::lock_guard<std::recursive_mutex> guard(
278  bkpt_sp->GetTarget().GetAPIMutex());
279  bkpt_sp->SetCondition(condition);
280  }
281 }
282 
284  LLDB_INSTRUMENT_VA(this);
285 
286  BreakpointSP bkpt_sp = GetSP();
287  if (bkpt_sp) {
288  std::lock_guard<std::recursive_mutex> guard(
289  bkpt_sp->GetTarget().GetAPIMutex());
290  return bkpt_sp->GetConditionText();
291  }
292  return nullptr;
293 }
294 
295 void SBBreakpoint::SetAutoContinue(bool auto_continue) {
296  LLDB_INSTRUMENT_VA(this, auto_continue);
297 
298  BreakpointSP bkpt_sp = GetSP();
299  if (bkpt_sp) {
300  std::lock_guard<std::recursive_mutex> guard(
301  bkpt_sp->GetTarget().GetAPIMutex());
302  bkpt_sp->SetAutoContinue(auto_continue);
303  }
304 }
305 
307  LLDB_INSTRUMENT_VA(this);
308 
309  BreakpointSP bkpt_sp = GetSP();
310  if (bkpt_sp) {
311  std::lock_guard<std::recursive_mutex> guard(
312  bkpt_sp->GetTarget().GetAPIMutex());
313  return bkpt_sp->IsAutoContinue();
314  }
315  return false;
316 }
317 
319  LLDB_INSTRUMENT_VA(this);
320 
321  uint32_t count = 0;
322  BreakpointSP bkpt_sp = GetSP();
323  if (bkpt_sp) {
324  std::lock_guard<std::recursive_mutex> guard(
325  bkpt_sp->GetTarget().GetAPIMutex());
326  count = bkpt_sp->GetHitCount();
327  }
328 
329  return count;
330 }
331 
333  LLDB_INSTRUMENT_VA(this);
334 
335  uint32_t count = 0;
336  BreakpointSP bkpt_sp = GetSP();
337  if (bkpt_sp) {
338  std::lock_guard<std::recursive_mutex> guard(
339  bkpt_sp->GetTarget().GetAPIMutex());
340  count = bkpt_sp->GetIgnoreCount();
341  }
342 
343  return count;
344 }
345 
347  LLDB_INSTRUMENT_VA(this, tid);
348 
349  BreakpointSP bkpt_sp = GetSP();
350  if (bkpt_sp) {
351  std::lock_guard<std::recursive_mutex> guard(
352  bkpt_sp->GetTarget().GetAPIMutex());
353  bkpt_sp->SetThreadID(tid);
354  }
355 }
356 
358  LLDB_INSTRUMENT_VA(this);
359 
361  BreakpointSP bkpt_sp = GetSP();
362  if (bkpt_sp) {
363  std::lock_guard<std::recursive_mutex> guard(
364  bkpt_sp->GetTarget().GetAPIMutex());
365  tid = bkpt_sp->GetThreadID();
366  }
367 
368  return tid;
369 }
370 
372  LLDB_INSTRUMENT_VA(this, index);
373 
374  BreakpointSP bkpt_sp = GetSP();
375  if (bkpt_sp) {
376  std::lock_guard<std::recursive_mutex> guard(
377  bkpt_sp->GetTarget().GetAPIMutex());
378  bkpt_sp->GetOptions().GetThreadSpec()->SetIndex(index);
379  }
380 }
381 
383  LLDB_INSTRUMENT_VA(this);
384 
385  uint32_t thread_idx = UINT32_MAX;
386  BreakpointSP bkpt_sp = GetSP();
387  if (bkpt_sp) {
388  std::lock_guard<std::recursive_mutex> guard(
389  bkpt_sp->GetTarget().GetAPIMutex());
390  const ThreadSpec *thread_spec =
391  bkpt_sp->GetOptions().GetThreadSpecNoCreate();
392  if (thread_spec != nullptr)
393  thread_idx = thread_spec->GetIndex();
394  }
395 
396  return thread_idx;
397 }
398 
399 void SBBreakpoint::SetThreadName(const char *thread_name) {
400  LLDB_INSTRUMENT_VA(this, thread_name);
401 
402  BreakpointSP bkpt_sp = GetSP();
403 
404  if (bkpt_sp) {
405  std::lock_guard<std::recursive_mutex> guard(
406  bkpt_sp->GetTarget().GetAPIMutex());
407  bkpt_sp->GetOptions().GetThreadSpec()->SetName(thread_name);
408  }
409 }
410 
411 const char *SBBreakpoint::GetThreadName() const {
412  LLDB_INSTRUMENT_VA(this);
413 
414  const char *name = nullptr;
415  BreakpointSP bkpt_sp = GetSP();
416  if (bkpt_sp) {
417  std::lock_guard<std::recursive_mutex> guard(
418  bkpt_sp->GetTarget().GetAPIMutex());
419  const ThreadSpec *thread_spec =
420  bkpt_sp->GetOptions().GetThreadSpecNoCreate();
421  if (thread_spec != nullptr)
422  name = thread_spec->GetName();
423  }
424 
425  return name;
426 }
427 
428 void SBBreakpoint::SetQueueName(const char *queue_name) {
429  LLDB_INSTRUMENT_VA(this, queue_name);
430 
431  BreakpointSP bkpt_sp = GetSP();
432  if (bkpt_sp) {
433  std::lock_guard<std::recursive_mutex> guard(
434  bkpt_sp->GetTarget().GetAPIMutex());
435  bkpt_sp->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
436  }
437 }
438 
439 const char *SBBreakpoint::GetQueueName() const {
440  LLDB_INSTRUMENT_VA(this);
441 
442  const char *name = nullptr;
443  BreakpointSP bkpt_sp = GetSP();
444  if (bkpt_sp) {
445  std::lock_guard<std::recursive_mutex> guard(
446  bkpt_sp->GetTarget().GetAPIMutex());
447  const ThreadSpec *thread_spec =
448  bkpt_sp->GetOptions().GetThreadSpecNoCreate();
449  if (thread_spec)
450  name = thread_spec->GetQueueName();
451  }
452 
453  return name;
454 }
455 
457  LLDB_INSTRUMENT_VA(this);
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 
470  LLDB_INSTRUMENT_VA(this);
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 
483  LLDB_INSTRUMENT_VA(this, commands);
484 
485  BreakpointSP bkpt_sp = GetSP();
486  if (!bkpt_sp)
487  return;
488  if (commands.GetSize() == 0)
489  return;
490 
491  std::lock_guard<std::recursive_mutex> guard(
492  bkpt_sp->GetTarget().GetAPIMutex());
493  std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
495 
496  bkpt_sp->GetOptions().SetCommandDataCallback(cmd_data_up);
497 }
498 
500  LLDB_INSTRUMENT_VA(this, commands);
501 
502  BreakpointSP bkpt_sp = GetSP();
503  if (!bkpt_sp)
504  return false;
505  StringList command_list;
506  bool has_commands =
507  bkpt_sp->GetOptions().GetCommandLineCallbacks(command_list);
508  if (has_commands)
509  commands.AppendList(command_list);
510  return has_commands;
511 }
512 
514  LLDB_INSTRUMENT_VA(this, s);
515 
516  return GetDescription(s, true);
517 }
518 
519 bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
520  LLDB_INSTRUMENT_VA(this, s, include_locations);
521 
522  BreakpointSP bkpt_sp = GetSP();
523  if (bkpt_sp) {
524  std::lock_guard<std::recursive_mutex> guard(
525  bkpt_sp->GetTarget().GetAPIMutex());
526  s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
527  bkpt_sp->GetResolverDescription(s.get());
528  bkpt_sp->GetFilterDescription(s.get());
529  if (include_locations) {
530  const size_t num_locations = bkpt_sp->GetNumLocations();
531  s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
532  }
533  return true;
534  }
535  s.Printf("No value");
536  return false;
537 }
538 
540  LLDB_INSTRUMENT_VA(this, address);
541 
542  BreakpointSP bkpt_sp = GetSP();
543  SBError error;
544 
545  if (!address.IsValid()) {
546  error.SetErrorString("Can't add an invalid address.");
547  return error;
548  }
549 
550  if (!bkpt_sp) {
551  error.SetErrorString("No breakpoint to add a location to.");
552  return error;
553  }
554 
555  if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
556  error.SetErrorString("Only a scripted resolver can add locations.");
557  return error;
558  }
559 
560  if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
561  bkpt_sp->AddLocation(address.ref());
562  else {
563  StreamString s;
564  address.get()->Dump(&s, &bkpt_sp->GetTarget(),
565  Address::DumpStyleModuleWithFileAddress);
566  error.SetErrorStringWithFormat("Address: %s didn't pass the filter.",
567  s.GetData());
568  }
569  return error;
570 }
571 
573  LLDB_INSTRUMENT_VA(this);
574 
575  SBStructuredData data;
576  BreakpointSP bkpt_sp = GetSP();
577 
578  if (!bkpt_sp)
579  return data;
580 
581  StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
582  data.m_impl_up->SetObjectSP(bkpt_dict);
583  return data;
584 }
585 
587  LLDB_INSTRUMENT_VA(this, callback, baton);
588 
589  BreakpointSP bkpt_sp = GetSP();
590 
591  if (bkpt_sp) {
592  std::lock_guard<std::recursive_mutex> guard(
593  bkpt_sp->GetTarget().GetAPIMutex());
594  BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
595  bkpt_sp->SetCallback(SBBreakpointCallbackBaton
596  ::PrivateBreakpointHitCallback, baton_sp,
597  false);
598  }
599 }
600 
602  const char *callback_function_name) {
603  LLDB_INSTRUMENT_VA(this, callback_function_name);
604  SBStructuredData empty_args;
605  SetScriptCallbackFunction(callback_function_name, empty_args);
606 }
607 
609  const char *callback_function_name,
610  SBStructuredData &extra_args) {
611  LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
612  SBError sb_error;
613  BreakpointSP bkpt_sp = GetSP();
614 
615  if (bkpt_sp) {
616  Status error;
617  std::lock_guard<std::recursive_mutex> guard(
618  bkpt_sp->GetTarget().GetAPIMutex());
619  BreakpointOptions &bp_options = bkpt_sp->GetOptions();
620  error = bkpt_sp->GetTarget()
621  .GetDebugger()
622  .GetScriptInterpreter()
623  ->SetBreakpointCommandCallbackFunction(bp_options,
624  callback_function_name,
625  extra_args.m_impl_up
626  ->GetObjectSP());
627  sb_error.SetError(error);
628  } else
629  sb_error.SetErrorString("invalid breakpoint");
630 
631  return sb_error;
632 }
633 
634 SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
635  LLDB_INSTRUMENT_VA(this, callback_body_text);
636 
637  BreakpointSP bkpt_sp = GetSP();
638 
639  SBError sb_error;
640  if (bkpt_sp) {
641  std::lock_guard<std::recursive_mutex> guard(
642  bkpt_sp->GetTarget().GetAPIMutex());
643  BreakpointOptions &bp_options = bkpt_sp->GetOptions();
644  Status error =
645  bkpt_sp->GetTarget()
646  .GetDebugger()
647  .GetScriptInterpreter()
648  ->SetBreakpointCommandCallback(bp_options, callback_body_text);
649  sb_error.SetError(error);
650  } else
651  sb_error.SetErrorString("invalid breakpoint");
652 
653  return sb_error;
654 }
655 
656 bool SBBreakpoint::AddName(const char *new_name) {
657  LLDB_INSTRUMENT_VA(this, new_name);
658 
659  SBError status = AddNameWithErrorHandling(new_name);
660  return status.Success();
661 }
662 
664  LLDB_INSTRUMENT_VA(this, new_name);
665 
666  BreakpointSP bkpt_sp = GetSP();
667 
668  SBError status;
669  if (bkpt_sp) {
670  std::lock_guard<std::recursive_mutex> guard(
671  bkpt_sp->GetTarget().GetAPIMutex());
672  Status error;
673  bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
674  status.SetError(error);
675  } else {
676  status.SetErrorString("invalid breakpoint");
677  }
678 
679  return status;
680 }
681 
682 void SBBreakpoint::RemoveName(const char *name_to_remove) {
683  LLDB_INSTRUMENT_VA(this, name_to_remove);
684 
685  BreakpointSP bkpt_sp = GetSP();
686 
687  if (bkpt_sp) {
688  std::lock_guard<std::recursive_mutex> guard(
689  bkpt_sp->GetTarget().GetAPIMutex());
690  bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
691  ConstString(name_to_remove));
692  }
693 }
694 
695 bool SBBreakpoint::MatchesName(const char *name) {
696  LLDB_INSTRUMENT_VA(this, name);
697 
698  BreakpointSP bkpt_sp = GetSP();
699 
700  if (bkpt_sp) {
701  std::lock_guard<std::recursive_mutex> guard(
702  bkpt_sp->GetTarget().GetAPIMutex());
703  return bkpt_sp->MatchesName(name);
704  }
705 
706  return false;
707 }
708 
710  LLDB_INSTRUMENT_VA(this, names);
711 
712  BreakpointSP bkpt_sp = GetSP();
713 
714  if (bkpt_sp) {
715  std::lock_guard<std::recursive_mutex> guard(
716  bkpt_sp->GetTarget().GetAPIMutex());
717  std::vector<std::string> names_vec;
718  bkpt_sp->GetNames(names_vec);
719  for (std::string name : names_vec) {
720  names.AppendString(name.c_str());
721  }
722  }
723 }
724 
726  LLDB_INSTRUMENT_VA(event);
727 
728  return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
729  nullptr;
730 }
731 
732 BreakpointEventType
734  LLDB_INSTRUMENT_VA(event);
735 
736  if (event.IsValid())
737  return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
738  event.GetSP());
739  return eBreakpointEventTypeInvalidType;
740 }
741 
743  LLDB_INSTRUMENT_VA(event);
744 
745  if (event.IsValid())
746  return SBBreakpoint(
747  Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event.GetSP()));
748  return SBBreakpoint();
749 }
750 
753  uint32_t loc_idx) {
754  LLDB_INSTRUMENT_VA(event, loc_idx);
755 
756  SBBreakpointLocation sb_breakpoint_loc;
757  if (event.IsValid())
758  sb_breakpoint_loc.SetLocation(
759  Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
760  event.GetSP(), loc_idx));
761  return sb_breakpoint_loc;
762 }
763 
764 uint32_t
766  LLDB_INSTRUMENT_VA(event);
767 
768  uint32_t num_locations = 0;
769  if (event.IsValid())
770  num_locations =
771  (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
772  event.GetSP()));
773  return num_locations;
774 }
775 
777  LLDB_INSTRUMENT_VA(this);
778 
779  BreakpointSP bkpt_sp = GetSP();
780  if (bkpt_sp)
781  return bkpt_sp->IsHardware();
782  return false;
783 }
784 
785 BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
786 
787 // This is simple collection of breakpoint id's and their target.
789 public:
790  SBBreakpointListImpl(lldb::TargetSP target_sp) {
791  if (target_sp && target_sp->IsValid())
792  m_target_wp = target_sp;
793  }
794 
795  ~SBBreakpointListImpl() = default;
796 
797  size_t GetSize() { return m_break_ids.size(); }
798 
799  BreakpointSP GetBreakpointAtIndex(size_t idx) {
800  if (idx >= m_break_ids.size())
801  return BreakpointSP();
802  TargetSP target_sp = m_target_wp.lock();
803  if (!target_sp)
804  return BreakpointSP();
805  lldb::break_id_t bp_id = m_break_ids[idx];
806  return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
807  }
808 
809  BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
810  TargetSP target_sp = m_target_wp.lock();
811  if (!target_sp)
812  return BreakpointSP();
813 
814  for (lldb::break_id_t &break_id : m_break_ids) {
815  if (break_id == desired_id)
816  return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
817  }
818  return BreakpointSP();
819  }
820 
821  bool Append(BreakpointSP bkpt) {
822  TargetSP target_sp = m_target_wp.lock();
823  if (!target_sp || !bkpt)
824  return false;
825  if (bkpt->GetTargetSP() != target_sp)
826  return false;
827  m_break_ids.push_back(bkpt->GetID());
828  return true;
829  }
830 
831  bool AppendIfUnique(BreakpointSP bkpt) {
832  TargetSP target_sp = m_target_wp.lock();
833  if (!target_sp || !bkpt)
834  return false;
835  if (bkpt->GetTargetSP() != target_sp)
836  return false;
837  lldb::break_id_t bp_id = bkpt->GetID();
838  if (!llvm::is_contained(m_break_ids, bp_id))
839  return false;
840 
841  m_break_ids.push_back(bkpt->GetID());
842  return true;
843  }
844 
846  TargetSP target_sp = m_target_wp.lock();
847  if (!target_sp)
848  return false;
849  if (id == LLDB_INVALID_BREAK_ID)
850  return false;
851  m_break_ids.push_back(id);
852  return true;
853  }
854 
855  void Clear() { m_break_ids.clear(); }
856 
858  for (lldb::break_id_t id : m_break_ids) {
859  bp_list.AddBreakpointID(BreakpointID(id));
860  }
861  }
862 
863  TargetSP GetTarget() { return m_target_wp.lock(); }
864 
865 private:
866  std::vector<lldb::break_id_t> m_break_ids;
867  TargetWP m_target_wp;
868 };
869 
871  : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
872  LLDB_INSTRUMENT_VA(this, target);
873 }
874 
876 
878  LLDB_INSTRUMENT_VA(this);
879 
880  if (!m_opaque_sp)
881  return 0;
882  else
883  return m_opaque_sp->GetSize();
884 }
885 
887  LLDB_INSTRUMENT_VA(this, idx);
888 
889  if (!m_opaque_sp)
890  return SBBreakpoint();
891 
892  BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
893  return SBBreakpoint(bkpt_sp);
894 }
895 
897  LLDB_INSTRUMENT_VA(this, id);
898 
899  if (!m_opaque_sp)
900  return SBBreakpoint();
901  BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
902  return SBBreakpoint(bkpt_sp);
903 }
904 
906  LLDB_INSTRUMENT_VA(this, sb_bkpt);
907 
908  if (!sb_bkpt.IsValid())
909  return;
910  if (!m_opaque_sp)
911  return;
912  m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
913 }
914 
916  LLDB_INSTRUMENT_VA(this, id);
917 
918  if (!m_opaque_sp)
919  return;
920  m_opaque_sp->AppendByID(id);
921 }
922 
924  LLDB_INSTRUMENT_VA(this, sb_bkpt);
925 
926  if (!sb_bkpt.IsValid())
927  return false;
928  if (!m_opaque_sp)
929  return false;
930  return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
931 }
932 
934  LLDB_INSTRUMENT_VA(this);
935 
936  if (m_opaque_sp)
937  m_opaque_sp->Clear();
938 }
939 
941  lldb_private::BreakpointIDList &bp_id_list) {
942  if (m_opaque_sp)
943  m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
944 }
lldb::SBBreakpointLocation
Definition: SBBreakpointLocation.h:17
SBBreakpointListImpl::AppendIfUnique
bool AppendIfUnique(BreakpointSP bkpt)
Definition: SBBreakpoint.cpp:831
lldb::SBStringList
Definition: SBStringList.h:16
Instrumentation.h
lldb::SBEvent::get
lldb_private::Event * get() const
Definition: SBEvent.cpp:133
lldb::SBBreakpoint::GetCondition
const char * GetCondition()
Definition: SBBreakpoint.cpp:283
SBBreakpointListImpl::GetSize
size_t GetSize()
Definition: SBBreakpoint.cpp:797
lldb::SBStringList::AppendString
void AppendString(const char *str)
Definition: SBStringList.cpp:58
lldb::SBStringList::GetSize
uint32_t GetSize() const
Definition: SBStringList.cpp:96
SBBreakpointListImpl
Definition: SBBreakpoint.cpp:788
lldb::SBBreakpoint::AddName
bool AddName(const char *new_name)
Definition: SBBreakpoint.cpp:656
lldb::SBBreakpoint::operator=
const lldb::SBBreakpoint & operator=(const lldb::SBBreakpoint &rhs)
Definition: SBBreakpoint.cpp:62
lldb::SBStream::Printf
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:70
lldb_private::BreakpointOptions::CommandData
Definition: BreakpointOptions.h:45
lldb::SBBreakpoint::AddNameWithErrorHandling
SBError AddNameWithErrorHandling(const char *new_name)
Definition: SBBreakpoint.cpp:663
lldb::SBBreakpoint::RemoveName
void RemoveName(const char *name_to_remove)
Definition: SBBreakpoint.cpp:682
lldb::SBError
Definition: SBError.h:20
lldb::SBBreakpoint::GetAutoContinue
bool GetAutoContinue()
Definition: SBBreakpoint.cpp:306
SBBreakpointOptionCommon.h
SBStringList.h
lldb::SBBreakpoint::GetNumBreakpointLocationsFromEvent
static uint32_t GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event_sp)
Definition: SBBreakpoint.cpp:765
SBBreakpointListImpl::Clear
void Clear()
Definition: SBBreakpoint.cpp:855
lldb::SBBreakpoint::SerializeToStructuredData
SBStructuredData SerializeToStructuredData()
Definition: SBBreakpoint.cpp:572
SBBreakpointListImpl::Append
bool Append(BreakpointSP bkpt)
Definition: SBBreakpoint.cpp:821
BreakpointLocation.h
StoppointCallbackContext.h
lldb::SBBreakpointList::CopyToBreakpointIDList
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list)
Definition: SBBreakpoint.cpp:940
BreakpointResolver.h
lldb::SBBreakpoint::m_opaque_wp
lldb::BreakpointWP m_opaque_wp
Definition: SBBreakpoint.h:156
SectionLoadList.h
lldb::SBBreakpoint::GetThreadName
const char * GetThreadName() const
Definition: SBBreakpoint.cpp:411
lldb::SBEvent
Definition: SBEvent.h:21
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb::SBBreakpoint::SetIgnoreCount
void SetIgnoreCount(uint32_t count)
Definition: SBBreakpoint.cpp:260
Debugger.h
lldb_private::Target
Definition: Target.h:469
SBBreakpointListImpl::FindBreakpointByID
BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id)
Definition: SBBreakpoint.cpp:809
lldb::SBBreakpoint::FindLocationByID
lldb::SBBreakpointLocation FindLocationByID(lldb::break_id_t bp_loc_id)
Definition: SBBreakpoint.cpp:170
lldb::SBBreakpoint::SetThreadName
void SetThreadName(const char *thread_name)
Definition: SBBreakpoint.cpp:399
lldb::SBStructuredData::m_impl_up
StructuredDataImplUP m_impl_up
Definition: SBStructuredData.h:104
Process.h
lldb::eScriptLanguageNone
@ eScriptLanguageNone
Definition: lldb-enumerations.h:218
Target.h
lldb::SBBreakpointList::~SBBreakpointList
~SBBreakpointList()
lldb::SBBreakpoint::GetLocationAtIndex
lldb::SBBreakpointLocation GetLocationAtIndex(uint32_t index)
Definition: SBBreakpoint.cpp:185
lldb::SBBreakpoint::SetQueueName
void SetQueueName(const char *queue_name)
Definition: SBBreakpoint.cpp:428
lldb::SBTarget
Definition: SBTarget.h:29
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::SBError::Success
bool Success() const
Definition: SBError.cpp:69
SBStream.h
lldb::SBBreakpoint::SetCommandLineCommands
void SetCommandLineCommands(SBStringList &commands)
Definition: SBBreakpoint.cpp:482
lldb::SBStream::get
lldb_private::Stream * get()
Definition: SBStream.cpp:174
lldb::SBBreakpoint::operator==
bool operator==(const lldb::SBBreakpoint &rhs)
Definition: SBBreakpoint.cpp:69
lldb::SBBreakpoint::ClearAllBreakpointSites
void ClearAllBreakpointSites()
Definition: SBBreakpoint.cpp:118
lldb::SBBreakpoint::IsHardware
bool IsHardware() const
Definition: SBBreakpoint.cpp:776
lldb::SBBreakpoint::SetCondition
void SetCondition(const char *condition)
Definition: SBBreakpoint.cpp:272
SBThread.h
lldb::SBBreakpoint::SBBreakpoint
SBBreakpoint()
Definition: SBBreakpoint.cpp:48
SBBreakpointListImpl::GetBreakpointAtIndex
BreakpointSP GetBreakpointAtIndex(size_t idx)
Definition: SBBreakpoint.cpp:799
ThreadSpec.h
lldb::SBEvent::GetSP
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:131
SBBreakpointListImpl::SBBreakpointListImpl
SBBreakpointListImpl(lldb::TargetSP target_sp)
Definition: SBBreakpoint.cpp:790
lldb::SBBreakpoint::IsValid
bool IsValid() const
Definition: SBBreakpoint.cpp:102
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb::SBBreakpointCallbackBaton
Definition: SBBreakpointOptionCommon.h:22
lldb::SBBreakpoint::FindLocationIDByAddress
lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr)
Definition: SBBreakpoint.cpp:150
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb::SBBreakpoint::SetEnabled
void SetEnabled(bool enable)
Definition: SBBreakpoint.cpp:200
lldb_private::StringList
Definition: StringList.h:26
lldb_private::ConstString
Definition: ConstString.h:39
lldb::SBBreakpoint::~SBBreakpoint
~SBBreakpoint()
lldb_private::StreamString
Definition: StreamString.h:23
lldb::SBError::SetErrorString
void SetErrorString(const char *err_str)
Definition: SBError.cpp:126
lldb_private::BreakpointOptions
Definition: BreakpointOptions.h:27
lldb::SBBreakpoint::GetNumResolvedLocations
size_t GetNumResolvedLocations() const
Definition: SBBreakpoint.cpp:456
lldb-enumerations.h
lldb::SBAddress::IsValid
bool IsValid() const
Definition: SBAddress.cpp:72
lldb::SBBreakpoint::SetScriptCallbackBody
SBError SetScriptCallbackBody(const char *script_body_text)
Definition: SBBreakpoint.cpp:634
lldb::SBBreakpoint::SetCallback
void SetCallback(SBBreakpointHitCallback callback, void *baton)
Definition: SBBreakpoint.cpp:586
lldb::SBBreakpoint::EventIsBreakpointEvent
static bool EventIsBreakpointEvent(const lldb::SBEvent &event)
Definition: SBBreakpoint.cpp:725
SBDebugger.h
SBBreakpointListImpl::AppendByID
bool AppendByID(lldb::break_id_t id)
Definition: SBBreakpoint.cpp:845
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb::SBBreakpointList::SBBreakpointList
SBBreakpointList(SBTarget &target)
Definition: SBBreakpoint.cpp:870
lldb::SBBreakpoint
class LLDB_API SBBreakpoint
Definition: SBDefines.h:35
lldb::SBBreakpointList::FindBreakpointByID
SBBreakpoint FindBreakpointByID(lldb::break_id_t)
Definition: SBBreakpoint.cpp:896
Thread.h
lldb::SBError::SetError
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:100
lldb::SBBreakpointList::AppendIfUnique
bool AppendIfUnique(const SBBreakpoint &sb_bkpt)
Definition: SBBreakpoint.cpp:923
lldb_private::SectionLoadList::ResolveLoadAddress
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
Definition: SectionLoadList.cpp:219
Address.h
lldb_private::ThreadSpec
Definition: ThreadSpec.h:33
lldb_private::Address::SetRawAddress
void SetRawAddress(lldb::addr_t addr)
Definition: Address.h:444
LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
lldb::SBBreakpoint::GetIgnoreCount
uint32_t GetIgnoreCount() const
Definition: SBBreakpoint.cpp:332
StreamFile.h
lldb_private::ThreadSpec::GetName
const char * GetName() const
Definition: ThreadSpec.cpp:68
lldb::SBBreakpointHitCallback
bool(* SBBreakpointHitCallback)(void *baton, SBProcess &process, SBThread &thread, lldb::SBBreakpointLocation &location)
Definition: SBDefines.h:110
lldb::SBBreakpoint::GetThreadIndex
uint32_t GetThreadIndex() const
Definition: SBBreakpoint.cpp:382
lldb_private::ThreadSpec::GetIndex
uint32_t GetIndex() const
Definition: ThreadSpec.h:55
lldb::SBBreakpoint::GetBreakpointEventTypeFromEvent
static lldb::BreakpointEventType GetBreakpointEventTypeFromEvent(const lldb::SBEvent &event)
Definition: SBBreakpoint.cpp:733
lldb::SBBreakpoint::SetThreadIndex
void SetThreadIndex(uint32_t index)
Definition: SBBreakpoint.cpp:371
lldb_private::Status
Definition: Status.h:44
lldb::SBBreakpoint::AddLocation
SBError AddLocation(SBAddress &address)
Definition: SBBreakpoint.cpp:539
lldb_private::Address::Dump
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false) const
Dump a description of this object to a Stream.
Definition: Address.cpp:406
lldb_private::ThreadSpec::GetQueueName
const char * GetQueueName() const
Definition: ThreadSpec.cpp:72
lldb::SBBreakpointList::Clear
void Clear()
Definition: SBBreakpoint.cpp:933
BreakpointIDList.h
uint32_t
lldb_private::Address
Definition: Address.h:59
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::SBBreakpointList::m_opaque_sp
std::shared_ptr< SBBreakpointListImpl > m_opaque_sp
Definition: SBBreakpoint.h:185
lldb::SBBreakpoint
Definition: SBBreakpoint.h:18
lldb_private::BreakpointID
Definition: BreakpointID.h:22
SBBreakpointLocation.h
lldb::SBBreakpoint::GetCommandLineCommands
bool GetCommandLineCommands(SBStringList &commands)
Definition: SBBreakpoint.cpp:499
lldb::SBBreakpoint::MatchesName
bool MatchesName(const char *name)
Definition: SBBreakpoint.cpp:695
lldb::SBBreakpointList::AppendByID
void AppendByID(lldb::break_id_t id)
Definition: SBBreakpoint.cpp:915
lldb::SBBreakpointList::GetSize
size_t GetSize() const
Definition: SBBreakpoint.cpp:877
lldb::SBBreakpoint::SetOneShot
void SetOneShot(bool one_shot)
Definition: SBBreakpoint.cpp:224
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb::SBBreakpoint::GetBreakpointFromEvent
static lldb::SBBreakpoint GetBreakpointFromEvent(const lldb::SBEvent &event)
Definition: SBBreakpoint.cpp:742
lldb::SBBreakpoint::GetHitCount
uint32_t GetHitCount() const
Definition: SBBreakpoint.cpp:318
lldb_private::Target::GetSectionLoadList
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1102
lldb::SBBreakpoint::SBTarget
friend class SBTarget
Definition: SBBreakpoint.h:152
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
SBStructuredData.h
lldb_private::BreakpointIDList::AddBreakpointID
bool AddBreakpointID(BreakpointID bp_id)
Definition: BreakpointIDList.cpp:46
lldb::SBBreakpoint::IsOneShot
bool IsOneShot() const
Definition: SBBreakpoint.cpp:236
StructuredDataImpl.h
lldb::SBBreakpoint::GetID
break_id_t GetID() const
Definition: SBBreakpoint.cpp:91
SBEvent.h
lldb::SBBreakpoint::SetAutoContinue
void SetAutoContinue(bool auto_continue)
Definition: SBBreakpoint.cpp:295
lldb::SBBreakpoint::GetQueueName
const char * GetQueueName() const
Definition: SBBreakpoint.cpp:439
SBBreakpointListImpl::m_break_ids
std::vector< lldb::break_id_t > m_break_ids
Definition: SBBreakpoint.cpp:866
lldb::SBBreakpoint::SetThreadID
void SetThreadID(lldb::tid_t sb_thread_id)
Definition: SBBreakpoint.cpp:346
lldb::SBAddress
Definition: SBAddress.h:17
lldb::SBAddress::ref
lldb_private::Address & ref()
Definition: SBAddress.cpp:173
lldb::SBBreakpoint::FindLocationByAddress
lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr)
Definition: SBBreakpoint.cpp:129
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBBreakpoint::operator!=
bool operator!=(const lldb::SBBreakpoint &rhs)
Definition: SBBreakpoint.cpp:75
lldb::SBBreakpoint::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBBreakpoint.cpp:513
lldb::SBBreakpoint::GetSP
lldb::BreakpointSP GetSP() const
Definition: SBBreakpoint.cpp:785
Breakpoint.h
lldb::SBBreakpoint::GetTarget
lldb::SBTarget GetTarget() const
Definition: SBBreakpoint.cpp:81
lldb::SBBreakpoint::GetBreakpointLocationAtIndexFromEvent
static lldb::SBBreakpointLocation GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event, uint32_t loc_idx)
Definition: SBBreakpoint.cpp:752
lldb::SBBreakpoint::GetNames
void GetNames(SBStringList &names)
Definition: SBBreakpoint.cpp:709
lldb::SBEvent::IsValid
bool IsValid() const
Definition: SBEvent.cpp:154
SBBreakpointListImpl::m_target_wp
TargetWP m_target_wp
Definition: SBBreakpoint.cpp:867
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBBreakpoint::IsEnabled
bool IsEnabled()
Definition: SBBreakpoint.cpp:212
CommandInterpreter.h
lldb::SBAddress::get
lldb_private::Address * get()
Definition: SBAddress.cpp:186
SBProcess.h
lldb::SBBreakpointLocation::SetLocation
void SetLocation(const lldb::BreakpointLocationSP &break_loc_sp)
Definition: SBBreakpointLocation.cpp:411
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:82
Stream.h
lldb::SBBreakpointList::Append
void Append(const SBBreakpoint &sb_bkpt)
Definition: SBBreakpoint.cpp:905
lldb::SBStream
Definition: SBStream.h:18
SBBreakpointListImpl::CopyToBreakpointIDList
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list)
Definition: SBBreakpoint.cpp:857
BreakpointResolverScripted.h
lldb::SBBreakpoint::SetScriptCallbackFunction
void SetScriptCallbackFunction(const char *callback_function_name)
Definition: SBBreakpoint.cpp:601
ScriptInterpreter.h
lldb::SBBreakpointList::GetBreakpointAtIndex
SBBreakpoint GetBreakpointAtIndex(size_t idx)
Definition: SBBreakpoint.cpp:886
lldb
Definition: SBAddress.h:15
lldb::SBBreakpoint::IsInternal
bool IsInternal()
Definition: SBBreakpoint.cpp:248
lldb::SBBreakpoint::GetThreadID
lldb::tid_t GetThreadID()
Definition: SBBreakpoint.cpp:357
lldb_private::BreakpointIDList
Definition: BreakpointIDList.h:25
lldb::SBStringList::AppendList
void AppendList(const char **strv, int strc)
Definition: SBStringList.cpp:69
SBBreakpoint.h
lldb::SBBreakpoint::GetNumLocations
size_t GetNumLocations() const
Definition: SBBreakpoint.cpp:469
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
SBBreakpointListImpl::GetTarget
TargetSP GetTarget()
Definition: SBBreakpoint.cpp:863