1 //===-- BreakpointLocationCollection.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/Breakpoint/BreakpointLocationCollection.h"
15 #include "lldb/Breakpoint/Breakpoint.h"
16 #include "lldb/Breakpoint/BreakpointLocation.h"
17 #include "lldb/Core/ModuleList.h"
18 #include "lldb/Target/Thread.h"
19 #include "lldb/Target/ThreadSpec.h"
22 using namespace lldb_private;
24 //----------------------------------------------------------------------
25 // BreakpointLocationCollection constructor
26 //----------------------------------------------------------------------
27 BreakpointLocationCollection::BreakpointLocationCollection()
28 : m_break_loc_collection(), m_collection_mutex() {}
30 //----------------------------------------------------------------------
32 //----------------------------------------------------------------------
33 BreakpointLocationCollection::~BreakpointLocationCollection() {}
35 void BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) {
36 std::lock_guard<std::mutex> guard(m_collection_mutex);
37 BreakpointLocationSP old_bp_loc =
38 FindByIDPair(bp_loc->GetBreakpoint().GetID(), bp_loc->GetID());
39 if (!old_bp_loc.get())
40 m_break_loc_collection.push_back(bp_loc);
43 bool BreakpointLocationCollection::Remove(lldb::break_id_t bp_id,
44 lldb::break_id_t bp_loc_id) {
45 std::lock_guard<std::mutex> guard(m_collection_mutex);
46 collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate
47 if (pos != m_break_loc_collection.end()) {
48 m_break_loc_collection.erase(pos);
54 class BreakpointIDPairMatches {
56 BreakpointIDPairMatches(lldb::break_id_t break_id,
57 lldb::break_id_t break_loc_id)
58 : m_break_id(break_id), m_break_loc_id(break_loc_id) {}
60 bool operator()(const BreakpointLocationSP &bp_loc) const {
61 return m_break_id == bp_loc->GetBreakpoint().GetID() &&
62 m_break_loc_id == bp_loc->GetID();
66 const lldb::break_id_t m_break_id;
67 const lldb::break_id_t m_break_loc_id;
70 BreakpointLocationCollection::collection::iterator
71 BreakpointLocationCollection::GetIDPairIterator(lldb::break_id_t break_id,
72 lldb::break_id_t break_loc_id) {
74 m_break_loc_collection.begin(),
75 m_break_loc_collection.end(), // Search full range
76 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
79 BreakpointLocationCollection::collection::const_iterator
80 BreakpointLocationCollection::GetIDPairConstIterator(
81 lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const {
83 m_break_loc_collection.begin(),
84 m_break_loc_collection.end(), // Search full range
85 BreakpointIDPairMatches(break_id, break_loc_id)); // Predicate
89 BreakpointLocationCollection::FindByIDPair(lldb::break_id_t break_id,
90 lldb::break_id_t break_loc_id) {
91 BreakpointLocationSP stop_sp;
92 collection::iterator pos = GetIDPairIterator(break_id, break_loc_id);
93 if (pos != m_break_loc_collection.end())
99 const BreakpointLocationSP BreakpointLocationCollection::FindByIDPair(
100 lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const {
101 BreakpointLocationSP stop_sp;
102 collection::const_iterator pos =
103 GetIDPairConstIterator(break_id, break_loc_id);
104 if (pos != m_break_loc_collection.end())
110 BreakpointLocationSP BreakpointLocationCollection::GetByIndex(size_t i) {
111 std::lock_guard<std::mutex> guard(m_collection_mutex);
112 BreakpointLocationSP stop_sp;
113 if (i < m_break_loc_collection.size())
114 stop_sp = m_break_loc_collection[i];
119 const BreakpointLocationSP
120 BreakpointLocationCollection::GetByIndex(size_t i) const {
121 std::lock_guard<std::mutex> guard(m_collection_mutex);
122 BreakpointLocationSP stop_sp;
123 if (i < m_break_loc_collection.size())
124 stop_sp = m_break_loc_collection[i];
129 bool BreakpointLocationCollection::ShouldStop(
130 StoppointCallbackContext *context) {
131 bool shouldStop = false;
133 size_t prev_size = GetSize();
134 while (i < prev_size) {
135 // ShouldStop can remove the breakpoint from the list
136 if (GetByIndex(i)->ShouldStop(context))
139 if (prev_size == GetSize())
141 prev_size = GetSize();
146 bool BreakpointLocationCollection::ValidForThisThread(Thread *thread) {
147 std::lock_guard<std::mutex> guard(m_collection_mutex);
148 collection::iterator pos, begin = m_break_loc_collection.begin(),
149 end = m_break_loc_collection.end();
151 for (pos = begin; pos != end; ++pos) {
152 if ((*pos)->ValidForThisThread(thread))
158 bool BreakpointLocationCollection::IsInternal() const {
159 std::lock_guard<std::mutex> guard(m_collection_mutex);
160 collection::const_iterator pos, begin = m_break_loc_collection.begin(),
161 end = m_break_loc_collection.end();
163 bool is_internal = true;
165 for (pos = begin; pos != end; ++pos) {
166 if (!(*pos)->GetBreakpoint().IsInternal()) {
174 void BreakpointLocationCollection::GetDescription(
175 Stream *s, lldb::DescriptionLevel level) {
176 std::lock_guard<std::mutex> guard(m_collection_mutex);
177 collection::iterator pos, begin = m_break_loc_collection.begin(),
178 end = m_break_loc_collection.end();
180 for (pos = begin; pos != end; ++pos) {
183 (*pos)->GetDescription(s, level);