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