blob: 89742a6090142afce53478a38e4c8f1bc823d84b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- BreakpointLocationList.cpp ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11// C Includes
12// C++ Includes
13// Other libraries and framework includes
14// Project includes
15#include "lldb/Breakpoint/BreakpointLocationList.h"
16#include "lldb/Breakpoint/BreakpointLocation.h"
17#include "lldb/Core/ModuleList.h"
18#include "lldb/Target/Target.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23BreakpointLocationList::BreakpointLocationList() :
24 m_locations(),
25 m_address_to_location (),
Greg Claytonc0d34462011-02-05 00:38:04 +000026 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027{
28}
29
30BreakpointLocationList::~BreakpointLocationList()
31{
32}
33
Greg Claytonc0d34462011-02-05 00:38:04 +000034BreakpointLocationSP
35BreakpointLocationList::Create (Breakpoint &bp, const Address &addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036{
Greg Claytonc0d34462011-02-05 00:38:04 +000037 Mutex::Locker locker (m_mutex);
38 // The location ID is just the size of the location list + 1
39 lldb::break_id_t bp_loc_id = m_locations.size() + 1;
40 BreakpointLocationSP bp_loc_sp (new BreakpointLocation (bp_loc_id, bp, addr));
41 m_locations.push_back (bp_loc_sp);
42 m_address_to_location[addr] = bp_loc_sp;
43 return bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044}
45
46bool
Greg Claytonc982c762010-07-09 20:39:50 +000047BreakpointLocationList::ShouldStop (StoppointCallbackContext *context, lldb::break_id_t break_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048{
49 BreakpointLocationSP bp = FindByID (break_id);
50 if (bp)
51 {
52 // Let the BreakpointLocation decide if it should stop here (could not have
53 // reached it's target hit count yet, or it could have a callback
54 // that decided it shouldn't stop (shared library loads/unloads).
55 return bp->ShouldStop (context);
56 }
57 // We should stop here since this BreakpointLocation isn't valid anymore or it
58 // doesn't exist.
59 return true;
60}
61
Greg Claytonc982c762010-07-09 20:39:50 +000062lldb::break_id_t
Greg Claytonc0d34462011-02-05 00:38:04 +000063BreakpointLocationList::FindIDByAddress (const Address &addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064{
65 BreakpointLocationSP bp_loc_sp = FindByAddress (addr);
66 if (bp_loc_sp)
67 {
68 return bp_loc_sp->GetID();
69 }
70 return LLDB_INVALID_BREAK_ID;
71}
72
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073BreakpointLocationSP
Greg Claytonc982c762010-07-09 20:39:50 +000074BreakpointLocationList::FindByID (lldb::break_id_t break_id) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075{
Greg Claytonc0d34462011-02-05 00:38:04 +000076 BreakpointLocationSP bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077 Mutex::Locker locker (m_mutex);
Greg Claytonc0d34462011-02-05 00:38:04 +000078 // We never remove a breakpoint locations, so the ID can be translated into
79 // the location index by subtracting 1
80 uint32_t idx = break_id - 1;
81 if (idx <= m_locations.size())
82 {
83 bp_loc_sp = m_locations[idx];
84 }
85 return bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086}
87
88size_t
89BreakpointLocationList::FindInModule (Module *module,
90 BreakpointLocationCollection& bp_loc_list)
91{
92 Mutex::Locker locker (m_mutex);
93 const size_t orig_size = bp_loc_list.GetSize();
94 collection::iterator pos, end = m_locations.end();
95
96 for (pos = m_locations.begin(); pos != end; ++pos)
97 {
98 bool seen = false;
99 BreakpointLocationSP break_loc = (*pos);
100 const Section *section = break_loc->GetAddress().GetSection();
101 if (section)
102 {
103 if (section->GetModule() == module)
104 {
105 if (!seen)
106 {
107 seen = true;
108 bp_loc_list.Add (break_loc);
109 }
110
111 }
112 }
113 }
114 return bp_loc_list.GetSize() - orig_size;
115}
116
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117const BreakpointLocationSP
Greg Claytonc0d34462011-02-05 00:38:04 +0000118BreakpointLocationList::FindByAddress (const Address &addr) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119{
120 Mutex::Locker locker (m_mutex);
Greg Claytonc0d34462011-02-05 00:38:04 +0000121 BreakpointLocationSP bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000122 if (!m_locations.empty())
123 {
124 addr_map::const_iterator pos = m_address_to_location.find (addr);
125 if (pos != m_address_to_location.end())
Greg Claytonc0d34462011-02-05 00:38:04 +0000126 bp_loc_sp = pos->second;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127 }
128
Greg Claytonc0d34462011-02-05 00:38:04 +0000129 return bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130}
131
132void
133BreakpointLocationList::Dump (Stream *s) const
134{
135 s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Greg Claytonded470d2011-03-19 01:12:21 +0000136 //s->Indent();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 Mutex::Locker locker (m_mutex);
138 s->Printf("BreakpointLocationList with %zu BreakpointLocations:\n", m_locations.size());
139 s->IndentMore();
140 collection::const_iterator pos, end = m_locations.end();
141 for (pos = m_locations.begin(); pos != end; ++pos)
142 (*pos).get()->Dump(s);
143 s->IndentLess();
144}
145
146
147BreakpointLocationSP
148BreakpointLocationList::GetByIndex (uint32_t i)
149{
150 Mutex::Locker locker (m_mutex);
Greg Claytonc0d34462011-02-05 00:38:04 +0000151 BreakpointLocationSP bp_loc_sp;
Greg Claytonc982c762010-07-09 20:39:50 +0000152 if (i < m_locations.size())
Greg Claytonc0d34462011-02-05 00:38:04 +0000153 bp_loc_sp = m_locations[i];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154
Greg Claytonc0d34462011-02-05 00:38:04 +0000155 return bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156}
157
158const BreakpointLocationSP
159BreakpointLocationList::GetByIndex (uint32_t i) const
160{
161 Mutex::Locker locker (m_mutex);
Greg Claytonc0d34462011-02-05 00:38:04 +0000162 BreakpointLocationSP bp_loc_sp;
Greg Claytonc982c762010-07-09 20:39:50 +0000163 if (i < m_locations.size())
Greg Claytonc0d34462011-02-05 00:38:04 +0000164 bp_loc_sp = m_locations[i];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165
Greg Claytonc0d34462011-02-05 00:38:04 +0000166 return bp_loc_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169void
170BreakpointLocationList::ClearAllBreakpointSites ()
171{
172 Mutex::Locker locker (m_mutex);
173 collection::iterator pos, end = m_locations.end();
174 for (pos = m_locations.begin(); pos != end; ++pos)
175 (*pos)->ClearBreakpointSite();
176}
177
178void
179BreakpointLocationList::ResolveAllBreakpointSites ()
180{
181 Mutex::Locker locker (m_mutex);
182 collection::iterator pos, end = m_locations.end();
183
184 for (pos = m_locations.begin(); pos != end; ++pos)
Jim Inghamd4ce0a12010-10-20 03:36:33 +0000185 {
186 if ((*pos)->IsEnabled())
187 (*pos)->ResolveBreakpointSite();
188 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
Greg Clayton9fed0d82010-07-23 23:33:17 +0000191uint32_t
192BreakpointLocationList::GetHitCount () const
193{
194 uint32_t hit_count = 0;
195 Mutex::Locker locker (m_mutex);
196 collection::const_iterator pos, end = m_locations.end();
197 for (pos = m_locations.begin(); pos != end; ++pos)
198 hit_count += (*pos)->GetHitCount();
199 return hit_count;
200}
201
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202size_t
203BreakpointLocationList::GetNumResolvedLocations() const
204{
205 Mutex::Locker locker (m_mutex);
206 size_t resolve_count = 0;
207 collection::const_iterator pos, end = m_locations.end();
208 for (pos = m_locations.begin(); pos != end; ++pos)
209 {
210 if ((*pos)->IsResolved())
211 ++resolve_count;
212 }
213 return resolve_count;
214}
215
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216void
217BreakpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level)
218{
219 Mutex::Locker locker (m_mutex);
220 collection::iterator pos, end = m_locations.end();
221
222 for (pos = m_locations.begin(); pos != end; ++pos)
223 {
224 s->Printf(" ");
225 (*pos)->GetDescription(s, level);
226 }
227}
228