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
10#include "Utils.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"
18#include "lldb/API/SBThread.h"
20
27#include "lldb/Core/Address.h"
28#include "lldb/Core/Debugger.h"
32#include "lldb/Target/Process.h"
34#include "lldb/Target/Target.h"
35#include "lldb/Target/Thread.h"
37#include "lldb/Utility/Stream.h"
38
40
42
43#include "llvm/ADT/STLExtras.h"
44
45using namespace lldb;
46using namespace lldb_private;
47
49
54
56 : m_opaque_wp(bp_sp) {
57 LLDB_INSTRUMENT_VA(this, bp_sp);
58}
59
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
83
84 BreakpointSP bkpt_sp = GetSP();
85 if (bkpt_sp)
86 return SBTarget(bkpt_sp->GetTargetSP());
87
88 return SBTarget();
89}
90
93
95 BreakpointSP bkpt_sp = GetSP();
96 if (bkpt_sp)
97 break_id = bkpt_sp->GetID();
98
99 return break_id;
100}
101
103 LLDB_INSTRUMENT_VA(this);
104 return this->operator bool();
105}
106SBBreakpoint::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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
124 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
138 std::lock_guard<TargetAPIMutex> guard(api_lock);
139 Address address;
140 Target &target = bkpt_sp->GetTarget();
141 if (!target.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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
158 std::lock_guard<TargetAPIMutex> guard(api_lock);
159 Address address;
160 Target &target = bkpt_sp->GetTarget();
161 if (!target.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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
178 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
193 std::lock_guard<TargetAPIMutex> guard(api_lock);
194 sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
195 }
196
197 return sb_bp_location;
198}
199
200void SBBreakpoint::SetEnabled(bool enable) {
201 LLDB_INSTRUMENT_VA(this, enable);
202
203 BreakpointSP bkpt_sp = GetSP();
204
205 if (bkpt_sp) {
206 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
207 std::lock_guard<TargetAPIMutex> guard(api_lock);
208 bkpt_sp->SetEnabled(enable);
209 }
210}
211
213 LLDB_INSTRUMENT_VA(this);
214
215 BreakpointSP bkpt_sp = GetSP();
216 if (bkpt_sp) {
217 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
218 std::lock_guard<TargetAPIMutex> guard(api_lock);
219 return bkpt_sp->IsEnabled();
220 } else
221 return false;
222}
223
224void SBBreakpoint::SetOneShot(bool one_shot) {
225 LLDB_INSTRUMENT_VA(this, one_shot);
226
227 BreakpointSP bkpt_sp = GetSP();
228
229 if (bkpt_sp) {
230 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
231 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
242 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
254 std::lock_guard<TargetAPIMutex> guard(api_lock);
255 return bkpt_sp->IsInternal();
256 } else
257 return false;
258}
259
260void SBBreakpoint::SetIgnoreCount(uint32_t count) {
261 LLDB_INSTRUMENT_VA(this, count);
262
263 BreakpointSP bkpt_sp = GetSP();
264
265 if (bkpt_sp) {
266 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
267 std::lock_guard<TargetAPIMutex> guard(api_lock);
268 bkpt_sp->SetIgnoreCount(count);
269 }
270}
271
272void SBBreakpoint::SetCondition(const char *condition) {
273 LLDB_INSTRUMENT_VA(this, condition);
274
275 BreakpointSP bkpt_sp = GetSP();
276 if (bkpt_sp) {
277 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
278 std::lock_guard<TargetAPIMutex> guard(api_lock);
279 // Treat a null pointer as resetting the condition.
280 if (!condition)
281 bkpt_sp->SetCondition(StopCondition());
282 else
283 bkpt_sp->SetCondition(StopCondition(condition));
284 }
285}
286
288 LLDB_INSTRUMENT_VA(this);
289
290 BreakpointSP bkpt_sp = GetSP();
291 if (!bkpt_sp)
292 return nullptr;
293
294 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
295 std::lock_guard<TargetAPIMutex> guard(api_lock);
296 StopCondition cond = bkpt_sp->GetCondition();
297 if (!cond)
298 return nullptr;
299 return GetDebuggerStringPool(bkpt_sp->GetTarget()).Intern(cond.GetText());
300}
301
303 LLDB_INSTRUMENT_VA(this, mode);
304
305 BreakpointSP bkpt_sp = GetSP();
306 if (bkpt_sp) {
307 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
308 std::lock_guard<TargetAPIMutex> guard(api_lock);
309 bkpt_sp->GetCondition().SetMode(mode);
310 }
311}
312
314 LLDB_INSTRUMENT_VA(this);
315
316 BreakpointSP bkpt_sp = GetSP();
317 if (bkpt_sp) {
318 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
319 std::lock_guard<TargetAPIMutex> guard(api_lock);
320 return bkpt_sp->GetCondition().GetMode();
321 }
323}
324
325void SBBreakpoint::SetAutoContinue(bool auto_continue) {
326 LLDB_INSTRUMENT_VA(this, auto_continue);
327
328 BreakpointSP bkpt_sp = GetSP();
329 if (bkpt_sp) {
330 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
331 std::lock_guard<TargetAPIMutex> guard(api_lock);
332 bkpt_sp->SetAutoContinue(auto_continue);
333 }
334}
335
337 LLDB_INSTRUMENT_VA(this);
338
339 BreakpointSP bkpt_sp = GetSP();
340 if (bkpt_sp) {
341 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
342 std::lock_guard<TargetAPIMutex> guard(api_lock);
343 return bkpt_sp->IsAutoContinue();
344 }
345 return false;
346}
347
349 LLDB_INSTRUMENT_VA(this);
350
351 uint32_t count = 0;
352 BreakpointSP bkpt_sp = GetSP();
353 if (bkpt_sp) {
354 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
355 std::lock_guard<TargetAPIMutex> guard(api_lock);
356 count = bkpt_sp->GetHitCount();
357 }
358
359 return count;
360}
361
363 LLDB_INSTRUMENT_VA(this);
364
365 uint32_t count = 0;
366 BreakpointSP bkpt_sp = GetSP();
367 if (bkpt_sp) {
368 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
369 std::lock_guard<TargetAPIMutex> guard(api_lock);
370 count = bkpt_sp->GetIgnoreCount();
371 }
372
373 return count;
374}
375
377 LLDB_INSTRUMENT_VA(this, tid);
378
379 BreakpointSP bkpt_sp = GetSP();
380 if (bkpt_sp) {
381 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
382 std::lock_guard<TargetAPIMutex> guard(api_lock);
383 bkpt_sp->SetThreadID(tid);
384 }
385}
386
388 LLDB_INSTRUMENT_VA(this);
389
391 BreakpointSP bkpt_sp = GetSP();
392 if (bkpt_sp) {
393 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
394 std::lock_guard<TargetAPIMutex> guard(api_lock);
395 tid = bkpt_sp->GetThreadID();
396 }
397
398 return tid;
399}
400
401void SBBreakpoint::SetThreadIndex(uint32_t index) {
402 LLDB_INSTRUMENT_VA(this, index);
403
404 BreakpointSP bkpt_sp = GetSP();
405 if (bkpt_sp) {
406 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
407 std::lock_guard<TargetAPIMutex> guard(api_lock);
408 bkpt_sp->GetOptions().GetThreadSpec()->SetIndex(index);
409 }
410}
411
413 LLDB_INSTRUMENT_VA(this);
414
415 uint32_t thread_idx = UINT32_MAX;
416 BreakpointSP bkpt_sp = GetSP();
417 if (bkpt_sp) {
418 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
419 std::lock_guard<TargetAPIMutex> guard(api_lock);
420 const ThreadSpec *thread_spec =
421 bkpt_sp->GetOptions().GetThreadSpecNoCreate();
422 if (thread_spec != nullptr)
423 thread_idx = thread_spec->GetIndex();
424 }
425
426 return thread_idx;
427}
428
429void SBBreakpoint::SetThreadName(const char *thread_name) {
430 LLDB_INSTRUMENT_VA(this, thread_name);
431
432 BreakpointSP bkpt_sp = GetSP();
433
434 if (bkpt_sp) {
435 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
436 std::lock_guard<TargetAPIMutex> guard(api_lock);
437 bkpt_sp->GetOptions().GetThreadSpec()->SetName(thread_name);
438 }
439}
440
441const char *SBBreakpoint::GetThreadName() const {
442 LLDB_INSTRUMENT_VA(this);
443
444 BreakpointSP bkpt_sp = GetSP();
445 if (!bkpt_sp)
446 return nullptr;
447
448 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
449 std::lock_guard<TargetAPIMutex> guard(api_lock);
450 if (const ThreadSpec *thread_spec =
451 bkpt_sp->GetOptions().GetThreadSpecNoCreate())
452 return GetDebuggerStringPool(bkpt_sp->GetTarget())
453 .Intern(thread_spec->GetName());
454
455 return nullptr;
456}
457
458void SBBreakpoint::SetQueueName(const char *queue_name) {
459 LLDB_INSTRUMENT_VA(this, queue_name);
460
461 BreakpointSP bkpt_sp = GetSP();
462 if (bkpt_sp) {
463 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
464 std::lock_guard<TargetAPIMutex> guard(api_lock);
465 bkpt_sp->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
466 }
467}
468
469const char *SBBreakpoint::GetQueueName() const {
470 LLDB_INSTRUMENT_VA(this);
471
472 BreakpointSP bkpt_sp = GetSP();
473 if (!bkpt_sp)
474 return nullptr;
475
476 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
477 std::lock_guard<TargetAPIMutex> guard(api_lock);
478 if (const ThreadSpec *thread_spec =
479 bkpt_sp->GetOptions().GetThreadSpecNoCreate())
480 return GetDebuggerStringPool(bkpt_sp->GetTarget())
481 .Intern(thread_spec->GetQueueName());
482
483 return nullptr;
484}
485
487 LLDB_INSTRUMENT_VA(this);
488
489 size_t num_resolved = 0;
490 BreakpointSP bkpt_sp = GetSP();
491 if (bkpt_sp) {
492 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
493 std::lock_guard<TargetAPIMutex> guard(api_lock);
494 num_resolved = bkpt_sp->GetNumResolvedLocations();
495 }
496 return num_resolved;
497}
498
500 LLDB_INSTRUMENT_VA(this);
501
502 BreakpointSP bkpt_sp = GetSP();
503 size_t num_locs = 0;
504 if (bkpt_sp) {
505 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
506 std::lock_guard<TargetAPIMutex> guard(api_lock);
507 num_locs = bkpt_sp->GetNumLocations();
508 }
509 return num_locs;
510}
511
513 LLDB_INSTRUMENT_VA(this, commands);
514
515 BreakpointSP bkpt_sp = GetSP();
516 if (!bkpt_sp)
517 return;
518 if (commands.GetSize() == 0)
519 return;
520
521 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
522 std::lock_guard<TargetAPIMutex> guard(api_lock);
523 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
525
526 bkpt_sp->GetOptions().SetCommandDataCallback(cmd_data_up);
527}
528
530 LLDB_INSTRUMENT_VA(this, commands);
531
532 BreakpointSP bkpt_sp = GetSP();
533 if (!bkpt_sp)
534 return false;
535 StringList command_list;
536 bool has_commands =
537 bkpt_sp->GetOptions().GetCommandLineCallbacks(command_list);
538 if (has_commands)
539 commands.AppendList(command_list);
540 return has_commands;
541}
542
544 LLDB_INSTRUMENT_VA(this, s);
545
546 return GetDescription(s, true);
547}
548
549bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
550 LLDB_INSTRUMENT_VA(this, s, include_locations);
551
552 BreakpointSP bkpt_sp = GetSP();
553 if (bkpt_sp) {
554 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
555 std::lock_guard<TargetAPIMutex> guard(api_lock);
556 s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
557 bkpt_sp->GetResolverDescription(s.get());
558 bkpt_sp->GetFilterDescription(s.get());
559 if (include_locations) {
560 const size_t num_locations = bkpt_sp->GetNumLocations();
561 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
562 }
563 return true;
564 }
565 s.Printf("No value");
566 return false;
567}
568
570 LLDB_INSTRUMENT_VA(this, address);
571
572 BreakpointSP bkpt_sp = GetSP();
574
575 if (!address.IsValid()) {
576 error = Status::FromErrorString("Can't add an invalid address.");
577 return error;
578 }
579
580 if (!bkpt_sp) {
581 error = Status::FromErrorString("No breakpoint to add a location to.");
582 return error;
583 }
584
585 if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
586 error =
587 Status::FromErrorString("Only a scripted resolver can add locations.");
588 return error;
589 }
590
591 if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
592 bkpt_sp->AddLocation(address.ref());
593 else {
594 StreamString s;
595 address.get()->Dump(&s, &bkpt_sp->GetTarget(),
598 "Address: %s didn't pass the filter.", s.GetData());
599 }
600 return error;
601}
602
604 BreakpointSP bkpt_sp = GetSP();
605 if (!bkpt_sp)
606 return {};
607
608 BreakpointLocationSP loc_sp = bkpt_sp->AddFacadeLocation();
609 return SBBreakpointLocation(loc_sp);
610}
611
613 LLDB_INSTRUMENT_VA(this);
614
615 SBStructuredData data;
616 BreakpointSP bkpt_sp = GetSP();
617
618 if (!bkpt_sp)
619 return data;
620
621 StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
622 data.m_impl_up->SetObjectSP(bkpt_dict);
623 return data;
624}
625
627 LLDB_INSTRUMENT_VA(this, callback, baton);
628
629 BreakpointSP bkpt_sp = GetSP();
630
631 if (bkpt_sp) {
632 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
633 std::lock_guard<TargetAPIMutex> guard(api_lock);
634 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
635 bkpt_sp->SetCallback(SBBreakpointCallbackBaton
636 ::PrivateBreakpointHitCallback, baton_sp,
637 false);
638 }
639}
640
642 const char *callback_function_name) {
643 LLDB_INSTRUMENT_VA(this, callback_function_name);
644 SBStructuredData empty_args;
645 SetScriptCallbackFunction(callback_function_name, empty_args);
646}
647
649 const char *callback_function_name,
650 SBStructuredData &extra_args) {
651 LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
652 SBError sb_error;
653 BreakpointSP bkpt_sp = GetSP();
654
655 if (bkpt_sp) {
656 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
657 std::lock_guard<TargetAPIMutex> guard(api_lock);
658 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
659 llvm::Error error = bkpt_sp->GetTarget()
660 .GetDebugger()
661 .GetScriptInterpreter()
662 ->SetBreakpointCommandCallbackFunction(
663 bp_options, callback_function_name,
664 extra_args.m_impl_up->GetObjectSP());
665 sb_error.SetError(Status::FromError(std::move(error)));
666 } else
667 sb_error = Status::FromErrorString("invalid breakpoint");
668
669 return sb_error;
670}
671
672SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
673 LLDB_INSTRUMENT_VA(this, callback_body_text);
674
675 BreakpointSP bkpt_sp = GetSP();
676
677 SBError sb_error;
678 if (bkpt_sp) {
679 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
680 std::lock_guard<TargetAPIMutex> guard(api_lock);
681 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
682 llvm::Error error =
683 bkpt_sp->GetTarget()
684 .GetDebugger()
685 .GetScriptInterpreter()
686 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
687 /*is_callback=*/false);
688 sb_error.SetError(Status::FromError(std::move(error)));
689 } else
690 sb_error = Status::FromErrorString("invalid breakpoint");
691
692 return sb_error;
693}
694
695bool SBBreakpoint::AddName(const char *new_name) {
696 LLDB_INSTRUMENT_VA(this, new_name);
697
698 SBError status = AddNameWithErrorHandling(new_name);
699 return status.Success();
700}
701
703 LLDB_INSTRUMENT_VA(this, new_name);
704
705 BreakpointSP bkpt_sp = GetSP();
706
707 SBError status;
708 if (bkpt_sp) {
709 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
710 std::lock_guard<TargetAPIMutex> guard(api_lock);
712 bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
713 status.SetError(std::move(error));
714 } else {
715 status = Status::FromErrorString("invalid breakpoint");
716 }
717
718 return status;
719}
720
721void SBBreakpoint::RemoveName(const char *name_to_remove) {
722 LLDB_INSTRUMENT_VA(this, name_to_remove);
723
724 BreakpointSP bkpt_sp = GetSP();
725
726 if (bkpt_sp) {
727 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
728 std::lock_guard<TargetAPIMutex> guard(api_lock);
729 bkpt_sp->GetTarget().RemoveNameFromBreakpoint(
730 bkpt_sp, llvm::StringRef(name_to_remove));
731 }
732}
733
734bool SBBreakpoint::MatchesName(const char *name) {
735 LLDB_INSTRUMENT_VA(this, name);
736
737 BreakpointSP bkpt_sp = GetSP();
738
739 if (bkpt_sp) {
740 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
741 std::lock_guard<TargetAPIMutex> guard(api_lock);
742 return bkpt_sp->MatchesName(name);
743 }
744
745 return false;
746}
747
749 LLDB_INSTRUMENT_VA(this, names);
750
751 BreakpointSP bkpt_sp = GetSP();
752
753 if (bkpt_sp) {
754 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
755 std::lock_guard<TargetAPIMutex> guard(api_lock);
756 std::vector<std::string> names_vec;
757 bkpt_sp->GetNames(names_vec);
758 for (const std::string &name : names_vec) {
759 names.AppendString(name.c_str());
760 }
761 }
762}
763
770
771BreakpointEventType
773 LLDB_INSTRUMENT_VA(event);
774
775 if (event.IsValid())
777 event.GetSP());
778 return eBreakpointEventTypeInvalidType;
779}
780
789
792 uint32_t loc_idx) {
793 LLDB_INSTRUMENT_VA(event, loc_idx);
794
795 SBBreakpointLocation sb_breakpoint_loc;
796 if (event.IsValid())
797 sb_breakpoint_loc.SetLocation(
799 event.GetSP(), loc_idx));
800 return sb_breakpoint_loc;
801}
802
803uint32_t
805 LLDB_INSTRUMENT_VA(event);
806
807 uint32_t num_locations = 0;
808 if (event.IsValid())
809 num_locations =
811 event.GetSP()));
812 return num_locations;
813}
814
816 LLDB_INSTRUMENT_VA(this);
817
818 BreakpointSP bkpt_sp = GetSP();
819 if (bkpt_sp)
820 return bkpt_sp->IsHardware();
821 return false;
822}
823
825 LLDB_INSTRUMENT_VA(this, is_hardware);
826
827 BreakpointSP bkpt_sp = GetSP();
828 if (bkpt_sp) {
829 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
830 std::lock_guard<TargetAPIMutex> guard(api_lock);
831 return SBError(Status::FromError(bkpt_sp->SetIsHardware(is_hardware)));
832 }
833 return SBError();
834}
835
837
838// This is simple collection of breakpoint id's and their target.
840public:
842 if (target_sp && target_sp->IsValid())
843 m_target_wp = target_sp;
844 }
845
847
848 size_t GetSize() { return m_break_ids.size(); }
849
851 if (idx >= m_break_ids.size())
852 return BreakpointSP();
853 TargetSP target_sp = m_target_wp.lock();
854 if (!target_sp)
855 return BreakpointSP();
856 lldb::break_id_t bp_id = m_break_ids[idx];
857 return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
858 }
859
861 TargetSP target_sp = m_target_wp.lock();
862 if (!target_sp)
863 return BreakpointSP();
864
865 for (lldb::break_id_t &break_id : m_break_ids) {
866 if (break_id == desired_id)
867 return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
868 }
869 return BreakpointSP();
870 }
871
872 bool Append(BreakpointSP bkpt) {
873 TargetSP target_sp = m_target_wp.lock();
874 if (!target_sp || !bkpt)
875 return false;
876 if (bkpt->GetTargetSP() != target_sp)
877 return false;
878 m_break_ids.push_back(bkpt->GetID());
879 return true;
880 }
881
883 TargetSP target_sp = m_target_wp.lock();
884 if (!target_sp || !bkpt)
885 return false;
886 if (bkpt->GetTargetSP() != target_sp)
887 return false;
888 lldb::break_id_t bp_id = bkpt->GetID();
889 if (llvm::is_contained(m_break_ids, bp_id))
890 return false;
891
892 m_break_ids.push_back(bkpt->GetID());
893 return true;
894 }
895
897 TargetSP target_sp = m_target_wp.lock();
898 if (!target_sp)
899 return false;
900 if (id == LLDB_INVALID_BREAK_ID)
901 return false;
902 m_break_ids.push_back(id);
903 return true;
904 }
905
906 void Clear() { m_break_ids.clear(); }
907
913
914 TargetSP GetTarget() { return m_target_wp.lock(); }
915
916private:
917 std::vector<lldb::break_id_t> m_break_ids;
919};
920
922 : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
923 LLDB_INSTRUMENT_VA(this, target);
924}
925
930
932 LLDB_INSTRUMENT_VA(this, rhs);
933
934 if (this != &rhs)
936 return *this;
937}
938
940
942 LLDB_INSTRUMENT_VA(this);
943
944 if (!m_opaque_sp)
945 return 0;
946 else
947 return m_opaque_sp->GetSize();
948}
949
951 LLDB_INSTRUMENT_VA(this, idx);
952
953 if (!m_opaque_sp)
954 return SBBreakpoint();
955
956 BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
957 return SBBreakpoint(bkpt_sp);
958}
959
961 LLDB_INSTRUMENT_VA(this, id);
962
963 if (!m_opaque_sp)
964 return SBBreakpoint();
965 BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
966 return SBBreakpoint(bkpt_sp);
967}
968
970 LLDB_INSTRUMENT_VA(this, sb_bkpt);
971
972 if (!sb_bkpt.IsValid())
973 return;
974 if (!m_opaque_sp)
975 return;
976 m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
977}
978
980 LLDB_INSTRUMENT_VA(this, id);
981
982 if (!m_opaque_sp)
983 return;
984 m_opaque_sp->AppendByID(id);
985}
986
988 LLDB_INSTRUMENT_VA(this, sb_bkpt);
989
990 if (!sb_bkpt.IsValid())
991 return false;
992 if (!m_opaque_sp)
993 return false;
994 return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
995}
996
998 LLDB_INSTRUMENT_VA(this);
999
1000 if (m_opaque_sp)
1001 m_opaque_sp->Clear();
1002}
1003
1005 lldb_private::BreakpointIDList &bp_id_list) {
1006 if (m_opaque_sp)
1007 m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
1008}
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:74
std::shared_ptr< SBBreakpointListImpl > m_opaque_sp
lldb::SBBreakpointList & operator=(const lldb::SBBreakpointList &rhs)
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()
void SetConditionMode(lldb::BreakpointConditionMode mode)
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)
lldb::BreakpointConditionMode GetConditionMode()
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:136
bool IsValid() const
Definition SBEvent.cpp:157
lldb::EventSP & GetSP() const
Definition SBEvent.cpp:134
lldb_private::Stream * get()
Definition SBStream.cpp:177
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:441
@ 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:398
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)
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:136
llvm::StringRef GetText() const
const char * GetData() const
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
std::shared_ptr< Object > ObjectSP
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3638
uint32_t GetIndex() const
Definition ThreadSpec.h:57
#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.
StringPoolRef GetDebuggerStringPool(const Target &target)
Strings interned here live as long as target's debugger.
Definition Utils.h:21
@ eScriptLanguageNone
BreakpointConditionMode
Modes for evaluating breakpoint conditions.
@ eBreakpointConditionModeDefault
Use the mode specified by the target.breakpoints-condition-mode setting.
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
int32_t break_id_t
Definition lldb-types.h:88
std::shared_ptr< lldb_private::Baton > BatonSP
bool(* SBBreakpointHitCallback)(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location)
Definition SBDefines.h:145
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:70
class LLDB_API SBBreakpoint
Definition SBDefines.h:51
uint64_t tid_t
Definition lldb-types.h:85