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) {
653 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
654 std::lock_guard<TargetAPIMutex> guard(api_lock);
655 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
656 llvm::Error error = bkpt_sp->GetTarget()
657 .GetDebugger()
658 .GetScriptInterpreter()
659 ->SetBreakpointCommandCallbackFunction(
660 bp_options, callback_function_name,
661 extra_args.m_impl_up->GetObjectSP());
662 sb_error.SetError(Status::FromError(std::move(error)));
663 } else
664 sb_error = Status::FromErrorString("invalid breakpoint");
665
666 return sb_error;
667}
668
669SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
670 LLDB_INSTRUMENT_VA(this, callback_body_text);
671
672 BreakpointSP bkpt_sp = GetSP();
673
674 SBError sb_error;
675 if (bkpt_sp) {
676 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
677 std::lock_guard<TargetAPIMutex> guard(api_lock);
678 BreakpointOptions &bp_options = bkpt_sp->GetOptions();
679 llvm::Error error =
680 bkpt_sp->GetTarget()
681 .GetDebugger()
682 .GetScriptInterpreter()
683 ->SetBreakpointCommandCallback(bp_options, callback_body_text,
684 /*is_callback=*/false);
685 sb_error.SetError(Status::FromError(std::move(error)));
686 } else
687 sb_error = Status::FromErrorString("invalid breakpoint");
688
689 return sb_error;
690}
691
692bool SBBreakpoint::AddName(const char *new_name) {
693 LLDB_INSTRUMENT_VA(this, new_name);
694
695 SBError status = AddNameWithErrorHandling(new_name);
696 return status.Success();
697}
698
700 LLDB_INSTRUMENT_VA(this, new_name);
701
702 BreakpointSP bkpt_sp = GetSP();
703
704 SBError status;
705 if (bkpt_sp) {
706 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
707 std::lock_guard<TargetAPIMutex> guard(api_lock);
709 bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
710 status.SetError(std::move(error));
711 } else {
712 status = Status::FromErrorString("invalid breakpoint");
713 }
714
715 return status;
716}
717
718void SBBreakpoint::RemoveName(const char *name_to_remove) {
719 LLDB_INSTRUMENT_VA(this, name_to_remove);
720
721 BreakpointSP bkpt_sp = GetSP();
722
723 if (bkpt_sp) {
724 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
725 std::lock_guard<TargetAPIMutex> guard(api_lock);
726 bkpt_sp->GetTarget().RemoveNameFromBreakpoint(
727 bkpt_sp, llvm::StringRef(name_to_remove));
728 }
729}
730
731bool SBBreakpoint::MatchesName(const char *name) {
732 LLDB_INSTRUMENT_VA(this, name);
733
734 BreakpointSP bkpt_sp = GetSP();
735
736 if (bkpt_sp) {
737 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
738 std::lock_guard<TargetAPIMutex> guard(api_lock);
739 return bkpt_sp->MatchesName(name);
740 }
741
742 return false;
743}
744
746 LLDB_INSTRUMENT_VA(this, names);
747
748 BreakpointSP bkpt_sp = GetSP();
749
750 if (bkpt_sp) {
751 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
752 std::lock_guard<TargetAPIMutex> guard(api_lock);
753 std::vector<std::string> names_vec;
754 bkpt_sp->GetNames(names_vec);
755 for (const std::string &name : names_vec) {
756 names.AppendString(name.c_str());
757 }
758 }
759}
760
767
768BreakpointEventType
770 LLDB_INSTRUMENT_VA(event);
771
772 if (event.IsValid())
774 event.GetSP());
775 return eBreakpointEventTypeInvalidType;
776}
777
786
789 uint32_t loc_idx) {
790 LLDB_INSTRUMENT_VA(event, loc_idx);
791
792 SBBreakpointLocation sb_breakpoint_loc;
793 if (event.IsValid())
794 sb_breakpoint_loc.SetLocation(
796 event.GetSP(), loc_idx));
797 return sb_breakpoint_loc;
798}
799
800uint32_t
802 LLDB_INSTRUMENT_VA(event);
803
804 uint32_t num_locations = 0;
805 if (event.IsValid())
806 num_locations =
808 event.GetSP()));
809 return num_locations;
810}
811
813 LLDB_INSTRUMENT_VA(this);
814
815 BreakpointSP bkpt_sp = GetSP();
816 if (bkpt_sp)
817 return bkpt_sp->IsHardware();
818 return false;
819}
820
822 LLDB_INSTRUMENT_VA(this, is_hardware);
823
824 BreakpointSP bkpt_sp = GetSP();
825 if (bkpt_sp) {
826 TargetAPIMutex api_lock = bkpt_sp->GetTarget().GetAPIMutex();
827 std::lock_guard<TargetAPIMutex> guard(api_lock);
828 return SBError(Status::FromError(bkpt_sp->SetIsHardware(is_hardware)));
829 }
830 return SBError();
831}
832
834
835// This is simple collection of breakpoint id's and their target.
837public:
839 if (target_sp && target_sp->IsValid())
840 m_target_wp = target_sp;
841 }
842
844
845 size_t GetSize() { return m_break_ids.size(); }
846
848 if (idx >= m_break_ids.size())
849 return BreakpointSP();
850 TargetSP target_sp = m_target_wp.lock();
851 if (!target_sp)
852 return BreakpointSP();
853 lldb::break_id_t bp_id = m_break_ids[idx];
854 return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
855 }
856
858 TargetSP target_sp = m_target_wp.lock();
859 if (!target_sp)
860 return BreakpointSP();
861
862 for (lldb::break_id_t &break_id : m_break_ids) {
863 if (break_id == desired_id)
864 return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
865 }
866 return BreakpointSP();
867 }
868
869 bool Append(BreakpointSP bkpt) {
870 TargetSP target_sp = m_target_wp.lock();
871 if (!target_sp || !bkpt)
872 return false;
873 if (bkpt->GetTargetSP() != target_sp)
874 return false;
875 m_break_ids.push_back(bkpt->GetID());
876 return true;
877 }
878
880 TargetSP target_sp = m_target_wp.lock();
881 if (!target_sp || !bkpt)
882 return false;
883 if (bkpt->GetTargetSP() != target_sp)
884 return false;
885 lldb::break_id_t bp_id = bkpt->GetID();
886 if (!llvm::is_contained(m_break_ids, bp_id))
887 return false;
888
889 m_break_ids.push_back(bkpt->GetID());
890 return true;
891 }
892
894 TargetSP target_sp = m_target_wp.lock();
895 if (!target_sp)
896 return false;
897 if (id == LLDB_INVALID_BREAK_ID)
898 return false;
899 m_break_ids.push_back(id);
900 return true;
901 }
902
903 void Clear() { m_break_ids.clear(); }
904
910
911 TargetSP GetTarget() { return m_target_wp.lock(); }
912
913private:
914 std::vector<lldb::break_id_t> m_break_ids;
916};
917
919 : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
920 LLDB_INSTRUMENT_VA(this, target);
921}
922
924
926 LLDB_INSTRUMENT_VA(this);
927
928 if (!m_opaque_sp)
929 return 0;
930 else
931 return m_opaque_sp->GetSize();
932}
933
935 LLDB_INSTRUMENT_VA(this, idx);
936
937 if (!m_opaque_sp)
938 return SBBreakpoint();
939
940 BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
941 return SBBreakpoint(bkpt_sp);
942}
943
945 LLDB_INSTRUMENT_VA(this, id);
946
947 if (!m_opaque_sp)
948 return SBBreakpoint();
949 BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
950 return SBBreakpoint(bkpt_sp);
951}
952
954 LLDB_INSTRUMENT_VA(this, sb_bkpt);
955
956 if (!sb_bkpt.IsValid())
957 return;
958 if (!m_opaque_sp)
959 return;
960 m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
961}
962
964 LLDB_INSTRUMENT_VA(this, id);
965
966 if (!m_opaque_sp)
967 return;
968 m_opaque_sp->AppendByID(id);
969}
970
972 LLDB_INSTRUMENT_VA(this, sb_bkpt);
973
974 if (!sb_bkpt.IsValid())
975 return false;
976 if (!m_opaque_sp)
977 return false;
978 return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
979}
980
982 LLDB_INSTRUMENT_VA(this);
983
984 if (m_opaque_sp)
985 m_opaque_sp->Clear();
986}
987
989 lldb_private::BreakpointIDList &bp_id_list) {
990 if (m_opaque_sp)
991 m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
992}
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:3525
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