1 //===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBBreakpoint.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBBreakpointLocation.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"
16 #include "lldb/API/SBStringList.h"
17 #include "lldb/API/SBThread.h"
19 #include "lldb/Breakpoint/Breakpoint.h"
20 #include "lldb/Breakpoint/BreakpointIDList.h"
21 #include "lldb/Breakpoint/BreakpointLocation.h"
22 #include "lldb/Breakpoint/BreakpointResolver.h"
23 #include "lldb/Breakpoint/BreakpointResolverScripted.h"
24 #include "lldb/Breakpoint/StoppointCallbackContext.h"
25 #include "lldb/Core/Address.h"
26 #include "lldb/Core/Debugger.h"
27 #include "lldb/Core/StreamFile.h"
28 #include "lldb/Interpreter/CommandInterpreter.h"
29 #include "lldb/Interpreter/ScriptInterpreter.h"
30 #include "lldb/Target/Process.h"
31 #include "lldb/Target/SectionLoadList.h"
32 #include "lldb/Target/Target.h"
33 #include "lldb/Target/Thread.h"
34 #include "lldb/Target/ThreadSpec.h"
35 #include "lldb/Utility/Stream.h"
37 #include "SBBreakpointOptionCommon.h"
39 #include "lldb/lldb-enumerations.h"
41 #include "llvm/ADT/STLExtras.h"
44 using namespace lldb_private;
46 SBBreakpoint::SBBreakpoint() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBreakpoint); }
48 SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs)
49 : m_opaque_wp(rhs.m_opaque_wp) {
50 LLDB_RECORD_CONSTRUCTOR(SBBreakpoint, (const lldb::SBBreakpoint &), rhs);
53 SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
54 : m_opaque_wp(bp_sp) {
55 LLDB_RECORD_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &), bp_sp);
58 SBBreakpoint::~SBBreakpoint() = default;
60 const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) {
61 LLDB_RECORD_METHOD(const lldb::SBBreakpoint &,
62 SBBreakpoint, operator=,(const lldb::SBBreakpoint &), rhs);
64 m_opaque_wp = rhs.m_opaque_wp;
65 return LLDB_RECORD_RESULT(*this);
68 bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) {
70 bool, SBBreakpoint, operator==,(const lldb::SBBreakpoint &), rhs);
72 return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
75 bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) {
77 bool, SBBreakpoint, operator!=,(const lldb::SBBreakpoint &), rhs);
79 return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
82 break_id_t SBBreakpoint::GetID() const {
83 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::break_id_t, SBBreakpoint, GetID);
85 break_id_t break_id = LLDB_INVALID_BREAK_ID;
86 BreakpointSP bkpt_sp = GetSP();
88 break_id = bkpt_sp->GetID();
93 bool SBBreakpoint::IsValid() const {
94 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsValid);
95 return this->operator bool();
97 SBBreakpoint::operator bool() const {
98 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, operator bool);
100 BreakpointSP bkpt_sp = GetSP();
103 else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
109 void SBBreakpoint::ClearAllBreakpointSites() {
110 LLDB_RECORD_METHOD_NO_ARGS(void, SBBreakpoint, ClearAllBreakpointSites);
112 BreakpointSP bkpt_sp = GetSP();
114 std::lock_guard<std::recursive_mutex> guard(
115 bkpt_sp->GetTarget().GetAPIMutex());
116 bkpt_sp->ClearAllBreakpointSites();
120 SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
121 LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
122 FindLocationByAddress, (lldb::addr_t), vm_addr);
124 SBBreakpointLocation sb_bp_location;
126 BreakpointSP bkpt_sp = GetSP();
128 if (vm_addr != LLDB_INVALID_ADDRESS) {
129 std::lock_guard<std::recursive_mutex> guard(
130 bkpt_sp->GetTarget().GetAPIMutex());
132 Target &target = bkpt_sp->GetTarget();
133 if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
134 address.SetRawAddress(vm_addr);
136 sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
139 return LLDB_RECORD_RESULT(sb_bp_location);
142 break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
143 LLDB_RECORD_METHOD(lldb::break_id_t, SBBreakpoint, FindLocationIDByAddress,
144 (lldb::addr_t), vm_addr);
146 break_id_t break_id = LLDB_INVALID_BREAK_ID;
147 BreakpointSP bkpt_sp = GetSP();
149 if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
150 std::lock_guard<std::recursive_mutex> guard(
151 bkpt_sp->GetTarget().GetAPIMutex());
153 Target &target = bkpt_sp->GetTarget();
154 if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
155 address.SetRawAddress(vm_addr);
157 break_id = bkpt_sp->FindLocationIDByAddress(address);
163 SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) {
164 LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint, FindLocationByID,
165 (lldb::break_id_t), bp_loc_id);
167 SBBreakpointLocation sb_bp_location;
168 BreakpointSP bkpt_sp = GetSP();
171 std::lock_guard<std::recursive_mutex> guard(
172 bkpt_sp->GetTarget().GetAPIMutex());
173 sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
176 return LLDB_RECORD_RESULT(sb_bp_location);
179 SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) {
180 LLDB_RECORD_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
181 GetLocationAtIndex, (uint32_t), index);
183 SBBreakpointLocation sb_bp_location;
184 BreakpointSP bkpt_sp = GetSP();
187 std::lock_guard<std::recursive_mutex> guard(
188 bkpt_sp->GetTarget().GetAPIMutex());
189 sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
192 return LLDB_RECORD_RESULT(sb_bp_location);
195 void SBBreakpoint::SetEnabled(bool enable) {
196 LLDB_RECORD_METHOD(void, SBBreakpoint, SetEnabled, (bool), enable);
198 BreakpointSP bkpt_sp = GetSP();
201 std::lock_guard<std::recursive_mutex> guard(
202 bkpt_sp->GetTarget().GetAPIMutex());
203 bkpt_sp->SetEnabled(enable);
207 bool SBBreakpoint::IsEnabled() {
208 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, IsEnabled);
210 BreakpointSP bkpt_sp = GetSP();
212 std::lock_guard<std::recursive_mutex> guard(
213 bkpt_sp->GetTarget().GetAPIMutex());
214 return bkpt_sp->IsEnabled();
219 void SBBreakpoint::SetOneShot(bool one_shot) {
220 LLDB_RECORD_METHOD(void, SBBreakpoint, SetOneShot, (bool), one_shot);
222 BreakpointSP bkpt_sp = GetSP();
225 std::lock_guard<std::recursive_mutex> guard(
226 bkpt_sp->GetTarget().GetAPIMutex());
227 bkpt_sp->SetOneShot(one_shot);
231 bool SBBreakpoint::IsOneShot() const {
232 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsOneShot);
234 BreakpointSP bkpt_sp = GetSP();
236 std::lock_guard<std::recursive_mutex> guard(
237 bkpt_sp->GetTarget().GetAPIMutex());
238 return bkpt_sp->IsOneShot();
243 bool SBBreakpoint::IsInternal() {
244 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, IsInternal);
246 BreakpointSP bkpt_sp = GetSP();
248 std::lock_guard<std::recursive_mutex> guard(
249 bkpt_sp->GetTarget().GetAPIMutex());
250 return bkpt_sp->IsInternal();
255 void SBBreakpoint::SetIgnoreCount(uint32_t count) {
256 LLDB_RECORD_METHOD(void, SBBreakpoint, SetIgnoreCount, (uint32_t), count);
258 BreakpointSP bkpt_sp = GetSP();
261 std::lock_guard<std::recursive_mutex> guard(
262 bkpt_sp->GetTarget().GetAPIMutex());
263 bkpt_sp->SetIgnoreCount(count);
267 void SBBreakpoint::SetCondition(const char *condition) {
268 LLDB_RECORD_METHOD(void, SBBreakpoint, SetCondition, (const char *),
271 BreakpointSP bkpt_sp = GetSP();
273 std::lock_guard<std::recursive_mutex> guard(
274 bkpt_sp->GetTarget().GetAPIMutex());
275 bkpt_sp->SetCondition(condition);
279 const char *SBBreakpoint::GetCondition() {
280 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBBreakpoint, GetCondition);
282 BreakpointSP bkpt_sp = GetSP();
284 std::lock_guard<std::recursive_mutex> guard(
285 bkpt_sp->GetTarget().GetAPIMutex());
286 return bkpt_sp->GetConditionText();
291 void SBBreakpoint::SetAutoContinue(bool auto_continue) {
292 LLDB_RECORD_METHOD(void, SBBreakpoint, SetAutoContinue, (bool),
295 BreakpointSP bkpt_sp = GetSP();
297 std::lock_guard<std::recursive_mutex> guard(
298 bkpt_sp->GetTarget().GetAPIMutex());
299 bkpt_sp->SetAutoContinue(auto_continue);
303 bool SBBreakpoint::GetAutoContinue() {
304 LLDB_RECORD_METHOD_NO_ARGS(bool, SBBreakpoint, GetAutoContinue);
306 BreakpointSP bkpt_sp = GetSP();
308 std::lock_guard<std::recursive_mutex> guard(
309 bkpt_sp->GetTarget().GetAPIMutex());
310 return bkpt_sp->IsAutoContinue();
315 uint32_t SBBreakpoint::GetHitCount() const {
316 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetHitCount);
319 BreakpointSP bkpt_sp = GetSP();
321 std::lock_guard<std::recursive_mutex> guard(
322 bkpt_sp->GetTarget().GetAPIMutex());
323 count = bkpt_sp->GetHitCount();
329 uint32_t SBBreakpoint::GetIgnoreCount() const {
330 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetIgnoreCount);
333 BreakpointSP bkpt_sp = GetSP();
335 std::lock_guard<std::recursive_mutex> guard(
336 bkpt_sp->GetTarget().GetAPIMutex());
337 count = bkpt_sp->GetIgnoreCount();
343 void SBBreakpoint::SetThreadID(tid_t tid) {
344 LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadID, (lldb::tid_t), tid);
346 BreakpointSP bkpt_sp = GetSP();
348 std::lock_guard<std::recursive_mutex> guard(
349 bkpt_sp->GetTarget().GetAPIMutex());
350 bkpt_sp->SetThreadID(tid);
354 tid_t SBBreakpoint::GetThreadID() {
355 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t, SBBreakpoint, GetThreadID);
357 tid_t tid = LLDB_INVALID_THREAD_ID;
358 BreakpointSP bkpt_sp = GetSP();
360 std::lock_guard<std::recursive_mutex> guard(
361 bkpt_sp->GetTarget().GetAPIMutex());
362 tid = bkpt_sp->GetThreadID();
368 void SBBreakpoint::SetThreadIndex(uint32_t index) {
369 LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadIndex, (uint32_t), index);
371 BreakpointSP bkpt_sp = GetSP();
373 std::lock_guard<std::recursive_mutex> guard(
374 bkpt_sp->GetTarget().GetAPIMutex());
375 bkpt_sp->GetOptions()->GetThreadSpec()->SetIndex(index);
379 uint32_t SBBreakpoint::GetThreadIndex() const {
380 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBBreakpoint, GetThreadIndex);
382 uint32_t thread_idx = UINT32_MAX;
383 BreakpointSP bkpt_sp = GetSP();
385 std::lock_guard<std::recursive_mutex> guard(
386 bkpt_sp->GetTarget().GetAPIMutex());
387 const ThreadSpec *thread_spec =
388 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
389 if (thread_spec != nullptr)
390 thread_idx = thread_spec->GetIndex();
396 void SBBreakpoint::SetThreadName(const char *thread_name) {
397 LLDB_RECORD_METHOD(void, SBBreakpoint, SetThreadName, (const char *),
400 BreakpointSP bkpt_sp = GetSP();
403 std::lock_guard<std::recursive_mutex> guard(
404 bkpt_sp->GetTarget().GetAPIMutex());
405 bkpt_sp->GetOptions()->GetThreadSpec()->SetName(thread_name);
409 const char *SBBreakpoint::GetThreadName() const {
410 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpoint, GetThreadName);
412 const char *name = nullptr;
413 BreakpointSP bkpt_sp = GetSP();
415 std::lock_guard<std::recursive_mutex> guard(
416 bkpt_sp->GetTarget().GetAPIMutex());
417 const ThreadSpec *thread_spec =
418 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
419 if (thread_spec != nullptr)
420 name = thread_spec->GetName();
426 void SBBreakpoint::SetQueueName(const char *queue_name) {
427 LLDB_RECORD_METHOD(void, SBBreakpoint, SetQueueName, (const char *),
430 BreakpointSP bkpt_sp = GetSP();
432 std::lock_guard<std::recursive_mutex> guard(
433 bkpt_sp->GetTarget().GetAPIMutex());
434 bkpt_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name);
438 const char *SBBreakpoint::GetQueueName() const {
439 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBreakpoint, GetQueueName);
441 const char *name = nullptr;
442 BreakpointSP bkpt_sp = GetSP();
444 std::lock_guard<std::recursive_mutex> guard(
445 bkpt_sp->GetTarget().GetAPIMutex());
446 const ThreadSpec *thread_spec =
447 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
449 name = thread_spec->GetQueueName();
455 size_t SBBreakpoint::GetNumResolvedLocations() const {
456 LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpoint,
457 GetNumResolvedLocations);
459 size_t num_resolved = 0;
460 BreakpointSP bkpt_sp = GetSP();
462 std::lock_guard<std::recursive_mutex> guard(
463 bkpt_sp->GetTarget().GetAPIMutex());
464 num_resolved = bkpt_sp->GetNumResolvedLocations();
469 size_t SBBreakpoint::GetNumLocations() const {
470 LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpoint, GetNumLocations);
472 BreakpointSP bkpt_sp = GetSP();
475 std::lock_guard<std::recursive_mutex> guard(
476 bkpt_sp->GetTarget().GetAPIMutex());
477 num_locs = bkpt_sp->GetNumLocations();
482 void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) {
483 LLDB_RECORD_METHOD(void, SBBreakpoint, SetCommandLineCommands,
484 (lldb::SBStringList &), commands);
486 BreakpointSP bkpt_sp = GetSP();
489 if (commands.GetSize() == 0)
492 std::lock_guard<std::recursive_mutex> guard(
493 bkpt_sp->GetTarget().GetAPIMutex());
494 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
495 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
497 bkpt_sp->GetOptions()->SetCommandDataCallback(cmd_data_up);
500 bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) {
501 LLDB_RECORD_METHOD(bool, SBBreakpoint, GetCommandLineCommands,
502 (lldb::SBStringList &), commands);
504 BreakpointSP bkpt_sp = GetSP();
507 StringList command_list;
509 bkpt_sp->GetOptions()->GetCommandLineCallbacks(command_list);
511 commands.AppendList(command_list);
515 bool SBBreakpoint::GetDescription(SBStream &s) {
516 LLDB_RECORD_METHOD(bool, SBBreakpoint, GetDescription, (lldb::SBStream &), s);
518 return GetDescription(s, true);
521 bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
522 LLDB_RECORD_METHOD(bool, SBBreakpoint, GetDescription,
523 (lldb::SBStream &, bool), s, include_locations);
525 BreakpointSP bkpt_sp = GetSP();
527 std::lock_guard<std::recursive_mutex> guard(
528 bkpt_sp->GetTarget().GetAPIMutex());
529 s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
530 bkpt_sp->GetResolverDescription(s.get());
531 bkpt_sp->GetFilterDescription(s.get());
532 if (include_locations) {
533 const size_t num_locations = bkpt_sp->GetNumLocations();
534 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
538 s.Printf("No value");
542 SBError SBBreakpoint::AddLocation(SBAddress &address) {
543 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
544 (lldb::SBAddress &), address);
546 BreakpointSP bkpt_sp = GetSP();
549 if (!address.IsValid()) {
550 error.SetErrorString("Can't add an invalid address.");
551 return LLDB_RECORD_RESULT(error);
555 error.SetErrorString("No breakpoint to add a location to.");
556 return LLDB_RECORD_RESULT(error);
559 if (!llvm::isa<BreakpointResolverScripted>(bkpt_sp->GetResolver().get())) {
560 error.SetErrorString("Only a scripted resolver can add locations.");
561 return LLDB_RECORD_RESULT(error);
564 if (bkpt_sp->GetSearchFilter()->AddressPasses(address.ref()))
565 bkpt_sp->AddLocation(address.ref());
568 address.get()->Dump(&s, &bkpt_sp->GetTarget(),
569 Address::DumpStyleModuleWithFileAddress);
570 error.SetErrorStringWithFormat("Address: %s didn't pass the filter.",
573 return LLDB_RECORD_RESULT(error);
576 void SBBreakpoint ::SetCallback(SBBreakpointHitCallback callback, void *baton) {
577 LLDB_RECORD_DUMMY(void, SBBreakpoint, SetCallback,
578 (lldb::SBBreakpointHitCallback, void *), callback, baton);
580 BreakpointSP bkpt_sp = GetSP();
583 std::lock_guard<std::recursive_mutex> guard(
584 bkpt_sp->GetTarget().GetAPIMutex());
585 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
586 bkpt_sp->SetCallback(SBBreakpointCallbackBaton
587 ::PrivateBreakpointHitCallback, baton_sp,
592 void SBBreakpoint::SetScriptCallbackFunction(
593 const char *callback_function_name) {
594 LLDB_RECORD_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
595 (const char *), callback_function_name);
597 BreakpointSP bkpt_sp = GetSP();
600 std::lock_guard<std::recursive_mutex> guard(
601 bkpt_sp->GetTarget().GetAPIMutex());
602 BreakpointOptions *bp_options = bkpt_sp->GetOptions();
605 .GetScriptInterpreter()
606 ->SetBreakpointCommandCallbackFunction(bp_options,
607 callback_function_name);
611 SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
612 LLDB_RECORD_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
613 (const char *), callback_body_text);
615 BreakpointSP bkpt_sp = GetSP();
619 std::lock_guard<std::recursive_mutex> guard(
620 bkpt_sp->GetTarget().GetAPIMutex());
621 BreakpointOptions *bp_options = bkpt_sp->GetOptions();
625 .GetScriptInterpreter()
626 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
627 sb_error.SetError(error);
629 sb_error.SetErrorString("invalid breakpoint");
631 return LLDB_RECORD_RESULT(sb_error);
634 bool SBBreakpoint::AddName(const char *new_name) {
635 LLDB_RECORD_METHOD(bool, SBBreakpoint, AddName, (const char *), new_name);
637 BreakpointSP bkpt_sp = GetSP();
640 std::lock_guard<std::recursive_mutex> guard(
641 bkpt_sp->GetTarget().GetAPIMutex());
642 Status error; // Think I'm just going to swallow the error here, it's
643 // probably more annoying to have to provide it.
644 bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
652 void SBBreakpoint::RemoveName(const char *name_to_remove) {
653 LLDB_RECORD_METHOD(void, SBBreakpoint, RemoveName, (const char *),
656 BreakpointSP bkpt_sp = GetSP();
659 std::lock_guard<std::recursive_mutex> guard(
660 bkpt_sp->GetTarget().GetAPIMutex());
661 bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
662 ConstString(name_to_remove));
666 bool SBBreakpoint::MatchesName(const char *name) {
667 LLDB_RECORD_METHOD(bool, SBBreakpoint, MatchesName, (const char *), name);
669 BreakpointSP bkpt_sp = GetSP();
672 std::lock_guard<std::recursive_mutex> guard(
673 bkpt_sp->GetTarget().GetAPIMutex());
674 return bkpt_sp->MatchesName(name);
680 void SBBreakpoint::GetNames(SBStringList &names) {
681 LLDB_RECORD_METHOD(void, SBBreakpoint, GetNames, (lldb::SBStringList &),
684 BreakpointSP bkpt_sp = GetSP();
687 std::lock_guard<std::recursive_mutex> guard(
688 bkpt_sp->GetTarget().GetAPIMutex());
689 std::vector<std::string> names_vec;
690 bkpt_sp->GetNames(names_vec);
691 for (std::string name : names_vec) {
692 names.AppendString(name.c_str());
697 bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) {
698 LLDB_RECORD_STATIC_METHOD(bool, SBBreakpoint, EventIsBreakpointEvent,
699 (const lldb::SBEvent &), event);
701 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
706 SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) {
707 LLDB_RECORD_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
708 GetBreakpointEventTypeFromEvent,
709 (const lldb::SBEvent &), event);
712 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
714 return eBreakpointEventTypeInvalidType;
717 SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) {
718 LLDB_RECORD_STATIC_METHOD(lldb::SBBreakpoint, SBBreakpoint,
719 GetBreakpointFromEvent, (const lldb::SBEvent &),
723 return LLDB_RECORD_RESULT(
724 SBBreakpoint(Breakpoint::BreakpointEventData::GetBreakpointFromEvent(
726 return LLDB_RECORD_RESULT(SBBreakpoint());
730 SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event,
732 LLDB_RECORD_STATIC_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
733 GetBreakpointLocationAtIndexFromEvent,
734 (const lldb::SBEvent &, uint32_t), event, loc_idx);
736 SBBreakpointLocation sb_breakpoint_loc;
738 sb_breakpoint_loc.SetLocation(
739 Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
740 event.GetSP(), loc_idx));
741 return LLDB_RECORD_RESULT(sb_breakpoint_loc);
745 SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) {
746 LLDB_RECORD_STATIC_METHOD(uint32_t, SBBreakpoint,
747 GetNumBreakpointLocationsFromEvent,
748 (const lldb::SBEvent &), event);
750 uint32_t num_locations = 0;
753 (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
755 return num_locations;
758 bool SBBreakpoint::IsHardware() const {
759 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBreakpoint, IsHardware);
761 BreakpointSP bkpt_sp = GetSP();
763 return bkpt_sp->IsHardware();
767 BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
769 // This is simple collection of breakpoint id's and their target.
770 class SBBreakpointListImpl {
772 SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() {
773 if (target_sp && target_sp->IsValid())
774 m_target_wp = target_sp;
777 ~SBBreakpointListImpl() = default;
779 size_t GetSize() { return m_break_ids.size(); }
781 BreakpointSP GetBreakpointAtIndex(size_t idx) {
782 if (idx >= m_break_ids.size())
783 return BreakpointSP();
784 TargetSP target_sp = m_target_wp.lock();
786 return BreakpointSP();
787 lldb::break_id_t bp_id = m_break_ids[idx];
788 return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
791 BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
792 TargetSP target_sp = m_target_wp.lock();
794 return BreakpointSP();
796 for (lldb::break_id_t &break_id : m_break_ids) {
797 if (break_id == desired_id)
798 return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
800 return BreakpointSP();
803 bool Append(BreakpointSP bkpt) {
804 TargetSP target_sp = m_target_wp.lock();
805 if (!target_sp || !bkpt)
807 if (bkpt->GetTargetSP() != target_sp)
809 m_break_ids.push_back(bkpt->GetID());
813 bool AppendIfUnique(BreakpointSP bkpt) {
814 TargetSP target_sp = m_target_wp.lock();
815 if (!target_sp || !bkpt)
817 if (bkpt->GetTargetSP() != target_sp)
819 lldb::break_id_t bp_id = bkpt->GetID();
820 if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) ==
824 m_break_ids.push_back(bkpt->GetID());
828 bool AppendByID(lldb::break_id_t id) {
829 TargetSP target_sp = m_target_wp.lock();
832 if (id == LLDB_INVALID_BREAK_ID)
834 m_break_ids.push_back(id);
838 void Clear() { m_break_ids.clear(); }
840 void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) {
841 for (lldb::break_id_t id : m_break_ids) {
842 bp_list.AddBreakpointID(BreakpointID(id));
846 TargetSP GetTarget() { return m_target_wp.lock(); }
849 std::vector<lldb::break_id_t> m_break_ids;
850 TargetWP m_target_wp;
853 SBBreakpointList::SBBreakpointList(SBTarget &target)
854 : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {
855 LLDB_RECORD_CONSTRUCTOR(SBBreakpointList, (lldb::SBTarget &), target);
858 SBBreakpointList::~SBBreakpointList() {}
860 size_t SBBreakpointList::GetSize() const {
861 LLDB_RECORD_METHOD_CONST_NO_ARGS(size_t, SBBreakpointList, GetSize);
866 return m_opaque_sp->GetSize();
869 SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) {
870 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBBreakpointList, GetBreakpointAtIndex,
874 return LLDB_RECORD_RESULT(SBBreakpoint());
876 BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
877 return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
880 SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) {
881 LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBBreakpointList, FindBreakpointByID,
882 (lldb::break_id_t), id);
885 return LLDB_RECORD_RESULT(SBBreakpoint());
886 BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
887 return LLDB_RECORD_RESULT(SBBreakpoint(bkpt_sp));
890 void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) {
891 LLDB_RECORD_METHOD(void, SBBreakpointList, Append,
892 (const lldb::SBBreakpoint &), sb_bkpt);
894 if (!sb_bkpt.IsValid())
898 m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
901 void SBBreakpointList::AppendByID(lldb::break_id_t id) {
902 LLDB_RECORD_METHOD(void, SBBreakpointList, AppendByID, (lldb::break_id_t),
907 m_opaque_sp->AppendByID(id);
910 bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) {
911 LLDB_RECORD_METHOD(bool, SBBreakpointList, AppendIfUnique,
912 (const lldb::SBBreakpoint &), sb_bkpt);
914 if (!sb_bkpt.IsValid())
918 return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
921 void SBBreakpointList::Clear() {
922 LLDB_RECORD_METHOD_NO_ARGS(void, SBBreakpointList, Clear);
925 m_opaque_sp->Clear();
928 void SBBreakpointList::CopyToBreakpointIDList(
929 lldb_private::BreakpointIDList &bp_id_list) {
931 m_opaque_sp->CopyToBreakpointIDList(bp_id_list);
934 namespace lldb_private {
938 void RegisterMethods<SBBreakpoint>(Registry &R) {
939 LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, ());
940 LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, (const lldb::SBBreakpoint &));
941 LLDB_REGISTER_CONSTRUCTOR(SBBreakpoint, (const lldb::BreakpointSP &));
942 LLDB_REGISTER_METHOD(const lldb::SBBreakpoint &,
943 SBBreakpoint, operator=,(const lldb::SBBreakpoint &));
944 LLDB_REGISTER_METHOD(bool,
945 SBBreakpoint, operator==,(const lldb::SBBreakpoint &));
946 LLDB_REGISTER_METHOD(bool,
947 SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
948 LLDB_REGISTER_METHOD_CONST(lldb::break_id_t, SBBreakpoint, GetID, ());
949 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
950 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool, ());
951 LLDB_REGISTER_METHOD(void, SBBreakpoint, ClearAllBreakpointSites, ());
952 LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
953 FindLocationByAddress, (lldb::addr_t));
954 LLDB_REGISTER_METHOD(lldb::break_id_t, SBBreakpoint,
955 FindLocationIDByAddress, (lldb::addr_t));
956 LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
957 FindLocationByID, (lldb::break_id_t));
958 LLDB_REGISTER_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
959 GetLocationAtIndex, (uint32_t));
960 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetEnabled, (bool));
961 LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsEnabled, ());
962 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetOneShot, (bool));
963 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsOneShot, ());
964 LLDB_REGISTER_METHOD(bool, SBBreakpoint, IsInternal, ());
965 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetIgnoreCount, (uint32_t));
966 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCondition, (const char *));
967 LLDB_REGISTER_METHOD(const char *, SBBreakpoint, GetCondition, ());
968 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetAutoContinue, (bool));
969 LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetAutoContinue, ());
970 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetHitCount, ());
971 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetIgnoreCount, ());
972 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadID, (lldb::tid_t));
973 LLDB_REGISTER_METHOD(lldb::tid_t, SBBreakpoint, GetThreadID, ());
974 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadIndex, (uint32_t));
975 LLDB_REGISTER_METHOD_CONST(uint32_t, SBBreakpoint, GetThreadIndex, ());
976 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetThreadName, (const char *));
977 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetThreadName, ());
978 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetQueueName, (const char *));
979 LLDB_REGISTER_METHOD_CONST(const char *, SBBreakpoint, GetQueueName, ());
980 LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumResolvedLocations,
982 LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpoint, GetNumLocations, ());
983 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetCommandLineCommands,
984 (lldb::SBStringList &));
985 LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetCommandLineCommands,
986 (lldb::SBStringList &));
987 LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
989 LLDB_REGISTER_METHOD(bool, SBBreakpoint, GetDescription,
990 (lldb::SBStream &, bool));
991 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
992 (lldb::SBAddress &));
993 LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
995 LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
997 LLDB_REGISTER_METHOD(bool, SBBreakpoint, AddName, (const char *));
998 LLDB_REGISTER_METHOD(void, SBBreakpoint, RemoveName, (const char *));
999 LLDB_REGISTER_METHOD(bool, SBBreakpoint, MatchesName, (const char *));
1000 LLDB_REGISTER_METHOD(void, SBBreakpoint, GetNames, (lldb::SBStringList &));
1001 LLDB_REGISTER_STATIC_METHOD(bool, SBBreakpoint, EventIsBreakpointEvent,
1002 (const lldb::SBEvent &));
1003 LLDB_REGISTER_STATIC_METHOD(lldb::BreakpointEventType, SBBreakpoint,
1004 GetBreakpointEventTypeFromEvent,
1005 (const lldb::SBEvent &));
1006 LLDB_REGISTER_STATIC_METHOD(lldb::SBBreakpoint, SBBreakpoint,
1007 GetBreakpointFromEvent,
1008 (const lldb::SBEvent &));
1009 LLDB_REGISTER_STATIC_METHOD(lldb::SBBreakpointLocation, SBBreakpoint,
1010 GetBreakpointLocationAtIndexFromEvent,
1011 (const lldb::SBEvent &, uint32_t));
1012 LLDB_REGISTER_STATIC_METHOD(uint32_t, SBBreakpoint,
1013 GetNumBreakpointLocationsFromEvent,
1014 (const lldb::SBEvent &));
1015 LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsHardware, ());
1019 void RegisterMethods<SBBreakpointList>(Registry &R) {
1020 LLDB_REGISTER_CONSTRUCTOR(SBBreakpointList, (lldb::SBTarget &));
1021 LLDB_REGISTER_METHOD_CONST(size_t, SBBreakpointList, GetSize, ());
1022 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointList,
1023 GetBreakpointAtIndex, (size_t));
1024 LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBBreakpointList,
1025 FindBreakpointByID, (lldb::break_id_t));
1026 LLDB_REGISTER_METHOD(void, SBBreakpointList, Append,
1027 (const lldb::SBBreakpoint &));
1028 LLDB_REGISTER_METHOD(void, SBBreakpointList, AppendByID,
1029 (lldb::break_id_t));
1030 LLDB_REGISTER_METHOD(bool, SBBreakpointList, AppendIfUnique,
1031 (const lldb::SBBreakpoint &));
1032 LLDB_REGISTER_METHOD(void, SBBreakpointList, Clear, ());