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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
123 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
137 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
157 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
177 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
192 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
206 std::lock_guard<TargetAPIMutex> guard(api_lock);
207 bkpt_sp->SetEnabled(enable);
208 }
209}
210
212 LLDB_INSTRUMENT_VA(this);
213
214 BreakpointSP bkpt_sp = GetSP();
215 if (bkpt_sp) {
216 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
217 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
230 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
241 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
253 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
266 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
277 std::lock_guard<TargetAPIMutex> guard(api_lock);
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 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
294 std::lock_guard<TargetAPIMutex> guard(api_lock);
295 StopCondition cond = bkpt_sp->GetCondition();
296 if (!cond)
297 return nullptr;
298 return ConstString(cond.GetText()).GetCString();
299}
300
302 LLDB_INSTRUMENT_VA(this, mode);
303
304 BreakpointSP bkpt_sp = GetSP();
305 if (bkpt_sp) {
306 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
307 std::lock_guard<TargetAPIMutex> guard(api_lock);
308 bkpt_sp->GetCondition().SetMode(mode);
309 }
310}
311
313 LLDB_INSTRUMENT_VA(this);
314
315 BreakpointSP bkpt_sp = GetSP();
316 if (bkpt_sp) {
317 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
318 std::lock_guard<TargetAPIMutex> guard(api_lock);
319 return bkpt_sp->GetCondition().GetMode();
320 }
322}
323
324void SBBreakpoint::SetAutoContinue(bool auto_continue) {
325 LLDB_INSTRUMENT_VA(this, auto_continue);
326
327 BreakpointSP bkpt_sp = GetSP();
328 if (bkpt_sp) {
329 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
330 std::lock_guard<TargetAPIMutex> guard(api_lock);
331 bkpt_sp->SetAutoContinue(auto_continue);
332 }
333}
334
336 LLDB_INSTRUMENT_VA(this);
337
338 BreakpointSP bkpt_sp = GetSP();
339 if (bkpt_sp) {
340 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
341 std::lock_guard<TargetAPIMutex> guard(api_lock);
342 return bkpt_sp->IsAutoContinue();
343 }
344 return false;
345}
346
348 LLDB_INSTRUMENT_VA(this);
349
350 uint32_t count = 0;
351 BreakpointSP bkpt_sp = GetSP();
352 if (bkpt_sp) {
353 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
354 std::lock_guard<TargetAPIMutex> guard(api_lock);
355 count = bkpt_sp->GetHitCount();
356 }
357
358 return count;
359}
360
362 LLDB_INSTRUMENT_VA(this);
363
364 uint32_t count = 0;
365 BreakpointSP bkpt_sp = GetSP();
366 if (bkpt_sp) {
367 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
368 std::lock_guard<TargetAPIMutex> guard(api_lock);
369 count = bkpt_sp->GetIgnoreCount();
370 }
371
372 return count;
373}
374
376 LLDB_INSTRUMENT_VA(this, tid);
377
378 BreakpointSP bkpt_sp = GetSP();
379 if (bkpt_sp) {
380 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
381 std::lock_guard<TargetAPIMutex> guard(api_lock);
382 bkpt_sp->SetThreadID(tid);
383 }
384}
385
387 LLDB_INSTRUMENT_VA(this);
388
390 BreakpointSP bkpt_sp = GetSP();
391 if (bkpt_sp) {
392 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
393 std::lock_guard<TargetAPIMutex> guard(api_lock);
394 tid = bkpt_sp->GetThreadID();
395 }
396
397 return tid;
398}
399
400void SBBreakpoint::SetThreadIndex(uint32_t index) {
401 LLDB_INSTRUMENT_VA(this, index);
402
403 BreakpointSP bkpt_sp = GetSP();
404 if (bkpt_sp) {
405 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
406 std::lock_guard<TargetAPIMutex> guard(api_lock);
407 bkpt_sp->GetOptions().GetThreadSpec()->SetIndex(index);
408 }
409}
410
412 LLDB_INSTRUMENT_VA(this);
413
414 uint32_t thread_idx = UINT32_MAX;
415 BreakpointSP bkpt_sp = GetSP();
416 if (bkpt_sp) {
417 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
418 std::lock_guard<TargetAPIMutex> guard(api_lock);
419 const ThreadSpec *thread_spec =
420 bkpt_sp->GetOptions().GetThreadSpecNoCreate();
421 if (thread_spec != nullptr)
422 thread_idx = thread_spec->GetIndex();
423 }
424
425 return thread_idx;
426}
427
428void SBBreakpoint::SetThreadName(const char *thread_name) {
429 LLDB_INSTRUMENT_VA(this, thread_name);
430
431 BreakpointSP bkpt_sp = GetSP();
432
433 if (bkpt_sp) {
434 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
435 std::lock_guard<TargetAPIMutex> guard(api_lock);
436 bkpt_sp->GetOptions().GetThreadSpec()->SetName(thread_name);
437 }
438}
439
440const char *SBBreakpoint::GetThreadName() const {
441 LLDB_INSTRUMENT_VA(this);
442
443 BreakpointSP bkpt_sp = GetSP();
444 if (!bkpt_sp)
445 return nullptr;
446
447 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
448 std::lock_guard<TargetAPIMutex> guard(api_lock);
449 if (const ThreadSpec *thread_spec =
450 bkpt_sp->GetOptions().GetThreadSpecNoCreate())
451 return ConstString(thread_spec->GetName()).GetCString();
452
453 return nullptr;
454}
455
456void SBBreakpoint::SetQueueName(const char *queue_name) {
457 LLDB_INSTRUMENT_VA(this, queue_name);
458
459 BreakpointSP bkpt_sp = GetSP();
460 if (bkpt_sp) {
461 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
462 std::lock_guard<TargetAPIMutex> guard(api_lock);
463 bkpt_sp->GetOptions().GetThreadSpec()->SetQueueName(queue_name);
464 }
465}
466
467const char *SBBreakpoint::GetQueueName() const {
468 LLDB_INSTRUMENT_VA(this);
469
470 BreakpointSP bkpt_sp = GetSP();
471 if (!bkpt_sp)
472 return nullptr;
473
474 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
475 std::lock_guard<TargetAPIMutex> guard(api_lock);
476 if (const ThreadSpec *thread_spec =
477 bkpt_sp->GetOptions().GetThreadSpecNoCreate())
478 return ConstString(thread_spec->GetQueueName()).GetCString();
479
480 return nullptr;
481}
482
484 LLDB_INSTRUMENT_VA(this);
485
486 size_t num_resolved = 0;
487 BreakpointSP bkpt_sp = GetSP();
488 if (bkpt_sp) {
489 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
490 std::lock_guard<TargetAPIMutex> guard(api_lock);
491 num_resolved = bkpt_sp->GetNumResolvedLocations();
492 }
493 return num_resolved;
494}
495
497 LLDB_INSTRUMENT_VA(this);
498
499 BreakpointSP bkpt_sp = GetSP();
500 size_t num_locs = 0;
501 if (bkpt_sp) {
502 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
503 std::lock_guard<TargetAPIMutex> guard(api_lock);
504 num_locs = bkpt_sp->GetNumLocations();
505 }
506 return num_locs;
507}
508
510 LLDB_INSTRUMENT_VA(this, commands);
511
512 BreakpointSP bkpt_sp = GetSP();
513 if (!bkpt_sp)
514 return;
515 if (commands.GetSize() == 0)
516 return;
517
518 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
519 std::lock_guard<TargetAPIMutex> guard(api_lock);
520 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
522
523 bkpt_sp->GetOptions().SetCommandDataCallback(cmd_data_up);
524}
525
527 LLDB_INSTRUMENT_VA(this, commands);
528
529 BreakpointSP bkpt_sp = GetSP();
530 if (!bkpt_sp)
531 return false;
532 StringList command_list;
533 bool has_commands =
534 bkpt_sp->GetOptions().GetCommandLineCallbacks(command_list);
535 if (has_commands)
536 commands.AppendList(command_list);
537 return has_commands;
538}
539
541 LLDB_INSTRUMENT_VA(this, s);
542
543 return GetDescription(s, true);
544}
545
546bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
547 LLDB_INSTRUMENT_VA(this, s, include_locations);
548
549 BreakpointSP bkpt_sp = GetSP();
550 if (bkpt_sp) {
551 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
552 std::lock_guard<TargetAPIMutex> guard(api_lock);
553 s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
554 bkpt_sp->GetResolverDescription(s.get());
555 bkpt_sp->GetFilterDescription(s.get());
556 if (include_locations) {
557 const size_t num_locations = bkpt_sp->GetNumLocations();
558 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
559 }
560 return true;
561 }
562 s.Printf("No value");
563 return false;
564}
565
567 LLDB_INSTRUMENT_VA(this, address);
568
569 BreakpointSP bkpt_sp = GetSP();
571
572 if (!address.IsValid()) {
573 error = Status::FromErrorString("Can't add an invalid address.");
574 return error;
575 }
576
577 if (!bkpt_sp) {
578 error = Status::FromErrorString("No breakpoint to add a location to.");
579 return error;
580 }
581
582 if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
583 error =
584 Status::FromErrorString("Only a scripted resolver can add locations.");
585 return error;
586 }
587
588 if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
589 bkpt_sp->AddLocation(address.ref());
590 else {
591 StreamString s;
592 address.get()->Dump(&s, &bkpt_sp->GetTarget(),
595 "Address: %s didn't pass the filter.", s.GetData());
596 }
597 return error;
598}
599
601 BreakpointSP bkpt_sp = GetSP();
602 if (!bkpt_sp)
603 return {};
604
605 BreakpointLocationSP loc_sp = bkpt_sp->AddFacadeLocation();
606 return SBBreakpointLocation(loc_sp);
607}
608
610 LLDB_INSTRUMENT_VA(this);
611
612 SBStructuredData data;
613 BreakpointSP bkpt_sp = GetSP();
614
615 if (!bkpt_sp)
616 return data;
617
618 StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
619 data.m_impl_up->SetObjectSP(bkpt_dict);
620 return data;
621}
622
624 LLDB_INSTRUMENT_VA(this, callback, baton);
625
626 BreakpointSP bkpt_sp = GetSP();
627
628 if (bkpt_sp) {
629 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
630 std::lock_guard<TargetAPIMutex> guard(api_lock);
631 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
632 bkpt_sp->SetCallback(SBBreakpointCallbackBaton
633 ::PrivateBreakpointHitCallback, baton_sp,
634 false);
635 }
636}
637
639 const char *callback_function_name) {
640 LLDB_INSTRUMENT_VA(this, callback_function_name);
641 SBStructuredData empty_args;
642 SetScriptCallbackFunction(callback_function_name, empty_args);
643}
644
646 const char *callback_function_name,
647 SBStructuredData &extra_args) {
648 LLDB_INSTRUMENT_VA(this, callback_function_name, extra_args);
649 SBError sb_error;
650 BreakpointSP bkpt_sp = GetSP();
651
652 if (bkpt_sp) {
654 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
655 std::lock_guard<TargetAPIMutex> guard(api_lock);
656 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
657 error = bkpt_sp->GetTarget()
658 .GetDebugger()
659 .GetScriptInterpreter()
660 ->SetBreakpointCommandCallbackFunction(bp_options,
661 callback_function_name,
662 extra_args.m_impl_up
663 ->GetObjectSP());
664 sb_error.SetError(std::move(error));
665 } else
666 sb_error = Status::FromErrorString("invalid breakpoint");
667
668 return sb_error;
669}
670
671SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
672 LLDB_INSTRUMENT_VA(this, callback_body_text);
673
674 BreakpointSP bkpt_sp = GetSP();
675
676 SBError sb_error;
677 if (bkpt_sp) {
678 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
679 std::lock_guard<TargetAPIMutex> guard(api_lock);
680 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
681 Status error =
682 bkpt_sp->GetTarget()
683 .GetDebugger()
684 .GetScriptInterpreter()
685 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
686 /*is_callback=*/false);
687 sb_error.SetError(std::move(error));
688 } else
689 sb_error = Status::FromErrorString("invalid breakpoint");
690
691 return sb_error;
692}
693
694bool SBBreakpoint::AddName(const char *new_name) {
695 LLDB_INSTRUMENT_VA(this, new_name);
696
697 SBError status = AddNameWithErrorHandling(new_name);
698 return status.Success();
699}
700
702 LLDB_INSTRUMENT_VA(this, new_name);
703
704 BreakpointSP bkpt_sp = GetSP();
705
706 SBError status;
707 if (bkpt_sp) {
708 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
709 std::lock_guard<TargetAPIMutex> guard(api_lock);
711 bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
712 status.SetError(std::move(error));
713 } else {
714 status = Status::FromErrorString("invalid breakpoint");
715 }
716
717 return status;
718}
719
720void SBBreakpoint::RemoveName(const char *name_to_remove) {
721 LLDB_INSTRUMENT_VA(this, name_to_remove);
722
723 BreakpointSP bkpt_sp = GetSP();
724
725 if (bkpt_sp) {
726 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
727 std::lock_guard<TargetAPIMutex> guard(api_lock);
728 bkpt_sp->GetTarget().RemoveNameFromBreakpoint(
729 bkpt_sp, llvm::StringRef(name_to_remove));
730 }
731}
732
733bool SBBreakpoint::MatchesName(const char *name) {
734 LLDB_INSTRUMENT_VA(this, name);
735
736 BreakpointSP bkpt_sp = GetSP();
737
738 if (bkpt_sp) {
739 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
740 std::lock_guard<TargetAPIMutex> guard(api_lock);
741 return bkpt_sp->MatchesName(name);
742 }
743
744 return false;
745}
746
748 LLDB_INSTRUMENT_VA(this, names);
749
750 BreakpointSP bkpt_sp = GetSP();
751
752 if (bkpt_sp) {
753 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
754 std::lock_guard<TargetAPIMutex> guard(api_lock);
755 std::vector<std::string> names_vec;
756 bkpt_sp->GetNames(names_vec);
757 for (const std::string &name : names_vec) {
758 names.AppendString(name.c_str());
759 }
760 }
761}
762
769
770BreakpointEventType
772 LLDB_INSTRUMENT_VA(event);
773
774 if (event.IsValid())
776 event.GetSP());
777 return eBreakpointEventTypeInvalidType;
778}
779
788
791 uint32_t loc_idx) {
792 LLDB_INSTRUMENT_VA(event, loc_idx);
793
794 SBBreakpointLocation sb_breakpoint_loc;
795 if (event.IsValid())
796 sb_breakpoint_loc.SetLocation(
798 event.GetSP(), loc_idx));
799 return sb_breakpoint_loc;
800}
801
802uint32_t
804 LLDB_INSTRUMENT_VA(event);
805
806 uint32_t num_locations = 0;
807 if (event.IsValid())
808 num_locations =
810 event.GetSP()));
811 return num_locations;
812}
813
815 LLDB_INSTRUMENT_VA(this);
816
817 BreakpointSP bkpt_sp = GetSP();
818 if (bkpt_sp)
819 return bkpt_sp->IsHardware();
820 return false;
821}
822
824 LLDB_INSTRUMENT_VA(this, is_hardware);
825
826 BreakpointSP bkpt_sp = GetSP();
827 if (bkpt_sp) {
828 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
829 std::lock_guard<TargetAPIMutex> guard(api_lock);
830 return SBError(Status::FromError(bkpt_sp->SetIsHardware(is_hardware)));
831 }
832 return SBError();
833}
834
836
837// This is simple collection of breakpoint id's and their target.
839public:
841 if (target_sp && target_sp->IsValid())
842 m_target_wp = target_sp;
843 }
844
846
847 size_t GetSize() { return m_break_ids.size(); }
848
850 if (idx >= m_break_ids.size())
851 return BreakpointSP();
852 TargetSP target_sp = m_target_wp.lock();
853 if (!target_sp)
854 return BreakpointSP();
855 lldb::break_id_t bp_id = m_break_ids[idx];
856 return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
857 }
858
860 TargetSP target_sp = m_target_wp.lock();
861 if (!target_sp)
862 return BreakpointSP();
863
864 for (lldb::break_id_t &break_id : m_break_ids) {
865 if (break_id == desired_id)
866 return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
867 }
868 return BreakpointSP();
869 }
870
871 bool Append(BreakpointSP bkpt) {
872 TargetSP target_sp = m_target_wp.lock();
873 if (!target_sp || !bkpt)
874 return false;
875 if (bkpt->GetTargetSP() != target_sp)
876 return false;
877 m_break_ids.push_back(bkpt->GetID());
878 return true;
879 }
880
882 TargetSP target_sp = m_target_wp.lock();
883 if (!target_sp || !bkpt)
884 return false;
885 if (bkpt->GetTargetSP() != target_sp)
886 return false;
887 lldb::break_id_t bp_id = bkpt->GetID();
888 if (!llvm::is_contained(m_break_ids, bp_id))
889 return false;
890
891 m_break_ids.push_back(bkpt->GetID());
892 return true;
893 }
894
896 TargetSP target_sp = m_target_wp.lock();
897 if (!target_sp)
898 return false;
899 if (id == LLDB_INVALID_BREAK_ID)
900 return false;
901 m_break_ids.push_back(id);
902 return true;
903 }
904
905 void Clear() { m_break_ids.clear(); }
906
912
913 TargetSP GetTarget() { return m_target_wp.lock(); }
914
915private:
916 std::vector<lldb::break_id_t> m_break_ids;
918};
919
921 : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
922 LLDB_INSTRUMENT_VA(this, target);
923}
924
926
928 LLDB_INSTRUMENT_VA(this);
929
930 if (!m_opaque_sp)
931 return 0;
932 else
933 return m_opaque_sp->GetSize();
934}
935
937 LLDB_INSTRUMENT_VA(this, idx);
938
939 if (!m_opaque_sp)
940 return SBBreakpoint();
941
942 BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
943 return SBBreakpoint(bkpt_sp);
944}
945
947 LLDB_INSTRUMENT_VA(this, id);
948
949 if (!m_opaque_sp)
950 return SBBreakpoint();
951 BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
952 return SBBreakpoint(bkpt_sp);
953}
954
956 LLDB_INSTRUMENT_VA(this, sb_bkpt);
957
958 if (!sb_bkpt.IsValid())
959 return;
960 if (!m_opaque_sp)
961 return;
962 m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
963}
964
966 LLDB_INSTRUMENT_VA(this, id);
967
968 if (!m_opaque_sp)
969 return;
970 m_opaque_sp->AppendByID(id);
971}
972
974 LLDB_INSTRUMENT_VA(this, sb_bkpt);
975
976 if (!sb_bkpt.IsValid())
977 return false;
978 if (!m_opaque_sp)
979 return false;
980 return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
981}
982
984 LLDB_INSTRUMENT_VA(this);
985
986 if (m_opaque_sp)
987 m_opaque_sp->Clear();
988}
989
991 lldb_private::BreakpointIDList &bp_id_list) {
992 if (m_opaque_sp)
993 m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
994}
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
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:134
bool IsValid() const
Definition SBEvent.cpp:155
lldb::EventSP & GetSP() const
Definition SBEvent.cpp:132
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)
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:136
llvm::StringRef GetText() const
const char * GetData() const
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:3505
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.
@ 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:144
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