1 //===-- SBBreakpoint.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/API/SBBreakpoint.h"
15 #include "lldb/API/SBBreakpointLocation.h"
16 #include "lldb/API/SBDebugger.h"
17 #include "lldb/API/SBEvent.h"
18 #include "lldb/API/SBProcess.h"
19 #include "lldb/API/SBStream.h"
20 #include "lldb/API/SBStringList.h"
21 #include "lldb/API/SBThread.h"
23 #include "lldb/Breakpoint/Breakpoint.h"
24 #include "lldb/Breakpoint/BreakpointIDList.h"
25 #include "lldb/Breakpoint/BreakpointLocation.h"
26 #include "lldb/Breakpoint/StoppointCallbackContext.h"
27 #include "lldb/Core/Address.h"
28 #include "lldb/Core/Debugger.h"
29 #include "lldb/Core/StreamFile.h"
30 #include "lldb/Interpreter/CommandInterpreter.h"
31 #include "lldb/Interpreter/ScriptInterpreter.h"
32 #include "lldb/Target/Process.h"
33 #include "lldb/Target/SectionLoadList.h"
34 #include "lldb/Target/Target.h"
35 #include "lldb/Target/Thread.h"
36 #include "lldb/Target/ThreadSpec.h"
37 #include "lldb/Utility/Log.h"
38 #include "lldb/Utility/Stream.h"
40 #include "SBBreakpointOptionCommon.h"
42 #include "lldb/lldb-enumerations.h"
44 #include "llvm/ADT/STLExtras.h"
47 using namespace lldb_private;
49 SBBreakpoint::SBBreakpoint() {}
51 SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs)
52 : m_opaque_wp(rhs.m_opaque_wp) {}
54 SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp)
55 : m_opaque_wp(bp_sp) {}
57 SBBreakpoint::~SBBreakpoint() = default;
59 const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) {
60 m_opaque_wp = rhs.m_opaque_wp;
64 bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) {
65 return m_opaque_wp.lock() == rhs.m_opaque_wp.lock();
68 bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) {
69 return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
72 break_id_t SBBreakpoint::GetID() const {
73 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
75 break_id_t break_id = LLDB_INVALID_BREAK_ID;
76 BreakpointSP bkpt_sp = GetSP();
78 break_id = bkpt_sp->GetID();
80 LLDB_LOG(log, "breakpoint = {0}, id = {1}", bkpt_sp.get(), break_id);
84 bool SBBreakpoint::IsValid() const {
85 BreakpointSP bkpt_sp = GetSP();
88 else if (bkpt_sp->GetTarget().GetBreakpointByID(bkpt_sp->GetID()))
94 void SBBreakpoint::ClearAllBreakpointSites() {
95 BreakpointSP bkpt_sp = GetSP();
97 std::lock_guard<std::recursive_mutex> guard(
98 bkpt_sp->GetTarget().GetAPIMutex());
99 bkpt_sp->ClearAllBreakpointSites();
103 SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
104 SBBreakpointLocation sb_bp_location;
106 BreakpointSP bkpt_sp = GetSP();
108 if (vm_addr != LLDB_INVALID_ADDRESS) {
109 std::lock_guard<std::recursive_mutex> guard(
110 bkpt_sp->GetTarget().GetAPIMutex());
112 Target &target = bkpt_sp->GetTarget();
113 if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
114 address.SetRawAddress(vm_addr);
116 sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
119 return sb_bp_location;
122 break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
123 break_id_t break_id = LLDB_INVALID_BREAK_ID;
124 BreakpointSP bkpt_sp = GetSP();
126 if (bkpt_sp && vm_addr != LLDB_INVALID_ADDRESS) {
127 std::lock_guard<std::recursive_mutex> guard(
128 bkpt_sp->GetTarget().GetAPIMutex());
130 Target &target = bkpt_sp->GetTarget();
131 if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
132 address.SetRawAddress(vm_addr);
134 break_id = bkpt_sp->FindLocationIDByAddress(address);
140 SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) {
141 SBBreakpointLocation sb_bp_location;
142 BreakpointSP bkpt_sp = GetSP();
145 std::lock_guard<std::recursive_mutex> guard(
146 bkpt_sp->GetTarget().GetAPIMutex());
147 sb_bp_location.SetLocation(bkpt_sp->FindLocationByID(bp_loc_id));
150 return sb_bp_location;
153 SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) {
154 SBBreakpointLocation sb_bp_location;
155 BreakpointSP bkpt_sp = GetSP();
158 std::lock_guard<std::recursive_mutex> guard(
159 bkpt_sp->GetTarget().GetAPIMutex());
160 sb_bp_location.SetLocation(bkpt_sp->GetLocationAtIndex(index));
163 return sb_bp_location;
166 void SBBreakpoint::SetEnabled(bool enable) {
167 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
168 BreakpointSP bkpt_sp = GetSP();
170 LLDB_LOG(log, "breakpoint = {0}, enable = {1}", bkpt_sp.get(), enable);
173 std::lock_guard<std::recursive_mutex> guard(
174 bkpt_sp->GetTarget().GetAPIMutex());
175 bkpt_sp->SetEnabled(enable);
179 bool SBBreakpoint::IsEnabled() {
180 BreakpointSP bkpt_sp = GetSP();
182 std::lock_guard<std::recursive_mutex> guard(
183 bkpt_sp->GetTarget().GetAPIMutex());
184 return bkpt_sp->IsEnabled();
189 void SBBreakpoint::SetOneShot(bool one_shot) {
190 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
191 BreakpointSP bkpt_sp = GetSP();
193 LLDB_LOG(log, "breakpoint = {0}, one_shot = {1}", bkpt_sp.get(), one_shot);
196 std::lock_guard<std::recursive_mutex> guard(
197 bkpt_sp->GetTarget().GetAPIMutex());
198 bkpt_sp->SetOneShot(one_shot);
202 bool SBBreakpoint::IsOneShot() const {
203 BreakpointSP bkpt_sp = GetSP();
205 std::lock_guard<std::recursive_mutex> guard(
206 bkpt_sp->GetTarget().GetAPIMutex());
207 return bkpt_sp->IsOneShot();
212 bool SBBreakpoint::IsInternal() {
213 BreakpointSP bkpt_sp = GetSP();
215 std::lock_guard<std::recursive_mutex> guard(
216 bkpt_sp->GetTarget().GetAPIMutex());
217 return bkpt_sp->IsInternal();
222 void SBBreakpoint::SetIgnoreCount(uint32_t count) {
223 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
224 BreakpointSP bkpt_sp = GetSP();
226 LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count);
229 std::lock_guard<std::recursive_mutex> guard(
230 bkpt_sp->GetTarget().GetAPIMutex());
231 bkpt_sp->SetIgnoreCount(count);
235 void SBBreakpoint::SetCondition(const char *condition) {
236 BreakpointSP bkpt_sp = GetSP();
238 std::lock_guard<std::recursive_mutex> guard(
239 bkpt_sp->GetTarget().GetAPIMutex());
240 bkpt_sp->SetCondition(condition);
244 const char *SBBreakpoint::GetCondition() {
245 BreakpointSP bkpt_sp = GetSP();
247 std::lock_guard<std::recursive_mutex> guard(
248 bkpt_sp->GetTarget().GetAPIMutex());
249 return bkpt_sp->GetConditionText();
254 void SBBreakpoint::SetAutoContinue(bool auto_continue) {
255 BreakpointSP bkpt_sp = GetSP();
257 std::lock_guard<std::recursive_mutex> guard(
258 bkpt_sp->GetTarget().GetAPIMutex());
259 bkpt_sp->SetAutoContinue(auto_continue);
263 bool SBBreakpoint::GetAutoContinue() {
264 BreakpointSP bkpt_sp = GetSP();
266 std::lock_guard<std::recursive_mutex> guard(
267 bkpt_sp->GetTarget().GetAPIMutex());
268 return bkpt_sp->IsAutoContinue();
273 uint32_t SBBreakpoint::GetHitCount() const {
275 BreakpointSP bkpt_sp = GetSP();
277 std::lock_guard<std::recursive_mutex> guard(
278 bkpt_sp->GetTarget().GetAPIMutex());
279 count = bkpt_sp->GetHitCount();
282 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
283 LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count);
288 uint32_t SBBreakpoint::GetIgnoreCount() const {
290 BreakpointSP bkpt_sp = GetSP();
292 std::lock_guard<std::recursive_mutex> guard(
293 bkpt_sp->GetTarget().GetAPIMutex());
294 count = bkpt_sp->GetIgnoreCount();
297 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
298 LLDB_LOG(log, "breakpoint = {0}, count = {1}", bkpt_sp.get(), count);
303 void SBBreakpoint::SetThreadID(tid_t tid) {
304 BreakpointSP bkpt_sp = GetSP();
306 std::lock_guard<std::recursive_mutex> guard(
307 bkpt_sp->GetTarget().GetAPIMutex());
308 bkpt_sp->SetThreadID(tid);
310 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
311 LLDB_LOG(log, "breakpoint = {0}, tid = {1:x}", bkpt_sp.get(), tid);
314 tid_t SBBreakpoint::GetThreadID() {
315 tid_t tid = LLDB_INVALID_THREAD_ID;
316 BreakpointSP bkpt_sp = GetSP();
318 std::lock_guard<std::recursive_mutex> guard(
319 bkpt_sp->GetTarget().GetAPIMutex());
320 tid = bkpt_sp->GetThreadID();
323 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
324 LLDB_LOG(log, "breakpoint = {0}, tid = {1:x}", bkpt_sp.get(), tid);
328 void SBBreakpoint::SetThreadIndex(uint32_t index) {
329 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
330 BreakpointSP bkpt_sp = GetSP();
331 LLDB_LOG(log, "breakpoint = {0}, index = {1}", bkpt_sp.get(), index);
333 std::lock_guard<std::recursive_mutex> guard(
334 bkpt_sp->GetTarget().GetAPIMutex());
335 bkpt_sp->GetOptions()->GetThreadSpec()->SetIndex(index);
339 uint32_t SBBreakpoint::GetThreadIndex() const {
340 uint32_t thread_idx = UINT32_MAX;
341 BreakpointSP bkpt_sp = GetSP();
343 std::lock_guard<std::recursive_mutex> guard(
344 bkpt_sp->GetTarget().GetAPIMutex());
345 const ThreadSpec *thread_spec =
346 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
347 if (thread_spec != nullptr)
348 thread_idx = thread_spec->GetIndex();
350 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
351 LLDB_LOG(log, "breakpoint = {0}, index = {1}", bkpt_sp.get(), thread_idx);
356 void SBBreakpoint::SetThreadName(const char *thread_name) {
357 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
358 BreakpointSP bkpt_sp = GetSP();
359 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), thread_name);
362 std::lock_guard<std::recursive_mutex> guard(
363 bkpt_sp->GetTarget().GetAPIMutex());
364 bkpt_sp->GetOptions()->GetThreadSpec()->SetName(thread_name);
368 const char *SBBreakpoint::GetThreadName() const {
369 const char *name = nullptr;
370 BreakpointSP bkpt_sp = GetSP();
372 std::lock_guard<std::recursive_mutex> guard(
373 bkpt_sp->GetTarget().GetAPIMutex());
374 const ThreadSpec *thread_spec =
375 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
376 if (thread_spec != nullptr)
377 name = thread_spec->GetName();
379 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
380 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name);
385 void SBBreakpoint::SetQueueName(const char *queue_name) {
386 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
387 BreakpointSP bkpt_sp = GetSP();
388 LLDB_LOG(log, "breakpoint = {0}, queue_name = {1}", bkpt_sp.get(),
391 std::lock_guard<std::recursive_mutex> guard(
392 bkpt_sp->GetTarget().GetAPIMutex());
393 bkpt_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name);
397 const char *SBBreakpoint::GetQueueName() const {
398 const char *name = nullptr;
399 BreakpointSP bkpt_sp = GetSP();
401 std::lock_guard<std::recursive_mutex> guard(
402 bkpt_sp->GetTarget().GetAPIMutex());
403 const ThreadSpec *thread_spec =
404 bkpt_sp->GetOptions()->GetThreadSpecNoCreate();
406 name = thread_spec->GetQueueName();
408 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
409 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name);
414 size_t SBBreakpoint::GetNumResolvedLocations() const {
415 size_t num_resolved = 0;
416 BreakpointSP bkpt_sp = GetSP();
418 std::lock_guard<std::recursive_mutex> guard(
419 bkpt_sp->GetTarget().GetAPIMutex());
420 num_resolved = bkpt_sp->GetNumResolvedLocations();
422 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
423 LLDB_LOG(log, "breakpoint = {0}, num_resolved = {1}", bkpt_sp.get(),
428 size_t SBBreakpoint::GetNumLocations() const {
429 BreakpointSP bkpt_sp = GetSP();
432 std::lock_guard<std::recursive_mutex> guard(
433 bkpt_sp->GetTarget().GetAPIMutex());
434 num_locs = bkpt_sp->GetNumLocations();
436 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
437 LLDB_LOG(log, "breakpoint = {0}, num_locs = {1}", bkpt_sp.get(), num_locs);
441 void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) {
442 BreakpointSP bkpt_sp = GetSP();
445 if (commands.GetSize() == 0)
448 std::lock_guard<std::recursive_mutex> guard(
449 bkpt_sp->GetTarget().GetAPIMutex());
450 std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up(
451 new BreakpointOptions::CommandData(*commands, eScriptLanguageNone));
453 bkpt_sp->GetOptions()->SetCommandDataCallback(cmd_data_up);
456 bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) {
457 BreakpointSP bkpt_sp = GetSP();
460 StringList command_list;
462 bkpt_sp->GetOptions()->GetCommandLineCallbacks(command_list);
464 commands.AppendList(command_list);
468 bool SBBreakpoint::GetDescription(SBStream &s) {
469 return GetDescription(s, true);
472 bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) {
473 BreakpointSP bkpt_sp = GetSP();
475 std::lock_guard<std::recursive_mutex> guard(
476 bkpt_sp->GetTarget().GetAPIMutex());
477 s.Printf("SBBreakpoint: id = %i, ", bkpt_sp->GetID());
478 bkpt_sp->GetResolverDescription(s.get());
479 bkpt_sp->GetFilterDescription(s.get());
480 if (include_locations) {
481 const size_t num_locations = bkpt_sp->GetNumLocations();
482 s.Printf(", locations = %" PRIu64, (uint64_t)num_locations);
486 s.Printf("No value");
491 ::SetCallback(SBBreakpointHitCallback callback,
493 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
494 BreakpointSP bkpt_sp = GetSP();
495 LLDB_LOG(log, "breakpoint = {0}, callback = {1}, baton = {2}", bkpt_sp.get(),
499 std::lock_guard<std::recursive_mutex> guard(
500 bkpt_sp->GetTarget().GetAPIMutex());
501 BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton));
502 bkpt_sp->SetCallback(SBBreakpointCallbackBaton
503 ::PrivateBreakpointHitCallback, baton_sp,
508 void SBBreakpoint::SetScriptCallbackFunction(
509 const char *callback_function_name) {
510 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
511 BreakpointSP bkpt_sp = GetSP();
512 LLDB_LOG(log, "breakpoint = {0}, callback = {1}", bkpt_sp.get(),
513 callback_function_name);
516 std::lock_guard<std::recursive_mutex> guard(
517 bkpt_sp->GetTarget().GetAPIMutex());
518 BreakpointOptions *bp_options = bkpt_sp->GetOptions();
521 .GetCommandInterpreter()
522 .GetScriptInterpreter()
523 ->SetBreakpointCommandCallbackFunction(bp_options,
524 callback_function_name);
528 SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
529 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
530 BreakpointSP bkpt_sp = GetSP();
531 LLDB_LOG(log, "breakpoint = {0}, callback body:\n{1}", bkpt_sp.get(),
536 std::lock_guard<std::recursive_mutex> guard(
537 bkpt_sp->GetTarget().GetAPIMutex());
538 BreakpointOptions *bp_options = bkpt_sp->GetOptions();
542 .GetCommandInterpreter()
543 .GetScriptInterpreter()
544 ->SetBreakpointCommandCallback(bp_options, callback_body_text);
545 sb_error.SetError(error);
547 sb_error.SetErrorString("invalid breakpoint");
552 bool SBBreakpoint::AddName(const char *new_name) {
553 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
554 BreakpointSP bkpt_sp = GetSP();
555 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), new_name);
558 std::lock_guard<std::recursive_mutex> guard(
559 bkpt_sp->GetTarget().GetAPIMutex());
560 Status error; // Think I'm just going to swallow the error here, it's
561 // probably more annoying to have to provide it.
562 bkpt_sp->GetTarget().AddNameToBreakpoint(bkpt_sp, new_name, error);
566 log->Printf("Failed to add name: '%s' to breakpoint: %s",
567 new_name, error.AsCString());
575 void SBBreakpoint::RemoveName(const char *name_to_remove) {
576 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
577 BreakpointSP bkpt_sp = GetSP();
578 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name_to_remove);
581 std::lock_guard<std::recursive_mutex> guard(
582 bkpt_sp->GetTarget().GetAPIMutex());
583 bkpt_sp->GetTarget().RemoveNameFromBreakpoint(bkpt_sp,
584 ConstString(name_to_remove));
588 bool SBBreakpoint::MatchesName(const char *name) {
589 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
590 BreakpointSP bkpt_sp = GetSP();
591 LLDB_LOG(log, "breakpoint = {0}, name = {1}", bkpt_sp.get(), name);
594 std::lock_guard<std::recursive_mutex> guard(
595 bkpt_sp->GetTarget().GetAPIMutex());
596 return bkpt_sp->MatchesName(name);
602 void SBBreakpoint::GetNames(SBStringList &names) {
603 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
604 BreakpointSP bkpt_sp = GetSP();
605 LLDB_LOG(log, "breakpoint = {0}", bkpt_sp.get());
608 std::lock_guard<std::recursive_mutex> guard(
609 bkpt_sp->GetTarget().GetAPIMutex());
610 std::vector<std::string> names_vec;
611 bkpt_sp->GetNames(names_vec);
612 for (std::string name : names_vec) {
613 names.AppendString(name.c_str());
618 bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) {
619 return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) !=
624 SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) {
626 return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent(
628 return eBreakpointEventTypeInvalidType;
631 SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) {
634 Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event.GetSP()));
635 return SBBreakpoint();
639 SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event,
641 SBBreakpointLocation sb_breakpoint_loc;
643 sb_breakpoint_loc.SetLocation(
644 Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent(
645 event.GetSP(), loc_idx));
646 return sb_breakpoint_loc;
650 SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) {
651 uint32_t num_locations = 0;
654 (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent(
656 return num_locations;
659 BreakpointSP SBBreakpoint::GetSP() const { return m_opaque_wp.lock(); }
661 // This is simple collection of breakpoint id's and their target.
662 class SBBreakpointListImpl {
664 SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() {
665 if (target_sp && target_sp->IsValid())
666 m_target_wp = target_sp;
669 ~SBBreakpointListImpl() = default;
671 size_t GetSize() { return m_break_ids.size(); }
673 BreakpointSP GetBreakpointAtIndex(size_t idx) {
674 if (idx >= m_break_ids.size())
675 return BreakpointSP();
676 TargetSP target_sp = m_target_wp.lock();
678 return BreakpointSP();
679 lldb::break_id_t bp_id = m_break_ids[idx];
680 return target_sp->GetBreakpointList().FindBreakpointByID(bp_id);
683 BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) {
684 TargetSP target_sp = m_target_wp.lock();
686 return BreakpointSP();
688 for (lldb::break_id_t &break_id : m_break_ids) {
689 if (break_id == desired_id)
690 return target_sp->GetBreakpointList().FindBreakpointByID(break_id);
692 return BreakpointSP();
695 bool Append(BreakpointSP bkpt) {
696 TargetSP target_sp = m_target_wp.lock();
697 if (!target_sp || !bkpt)
699 if (bkpt->GetTargetSP() != target_sp)
701 m_break_ids.push_back(bkpt->GetID());
705 bool AppendIfUnique(BreakpointSP bkpt) {
706 TargetSP target_sp = m_target_wp.lock();
707 if (!target_sp || !bkpt)
709 if (bkpt->GetTargetSP() != target_sp)
711 lldb::break_id_t bp_id = bkpt->GetID();
712 if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) ==
716 m_break_ids.push_back(bkpt->GetID());
720 bool AppendByID(lldb::break_id_t id) {
721 TargetSP target_sp = m_target_wp.lock();
724 if (id == LLDB_INVALID_BREAK_ID)
726 m_break_ids.push_back(id);
730 void Clear() { m_break_ids.clear(); }
732 void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) {
733 for (lldb::break_id_t id : m_break_ids) {
734 bp_list.AddBreakpointID(BreakpointID(id));
738 TargetSP GetTarget() { return m_target_wp.lock(); }
741 std::vector<lldb::break_id_t> m_break_ids;
742 TargetWP m_target_wp;
745 SBBreakpointList::SBBreakpointList(SBTarget &target)
746 : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {}
748 SBBreakpointList::~SBBreakpointList() {}
750 size_t SBBreakpointList::GetSize() const {
754 return m_opaque_sp->GetSize();
757 SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) {
759 return SBBreakpoint();
761 BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx);
762 return SBBreakpoint(bkpt_sp);
765 SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) {
767 return SBBreakpoint();
768 BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id);
769 return SBBreakpoint(bkpt_sp);
772 void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) {
773 if (!sb_bkpt.IsValid())
777 m_opaque_sp->Append(sb_bkpt.m_opaque_wp.lock());
780 void SBBreakpointList::AppendByID(lldb::break_id_t id) {
783 m_opaque_sp->AppendByID(id);
786 bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) {
787 if (!sb_bkpt.IsValid())
791 return m_opaque_sp->AppendIfUnique(sb_bkpt.GetSP());
794 void SBBreakpointList::Clear() {
796 m_opaque_sp->Clear();
799 void SBBreakpointList::CopyToBreakpointIDList(
800 lldb_private::BreakpointIDList &bp_id_list) {
802 m_opaque_sp->CopyToBreakpointIDList(bp_id_list);