1 //===-- BreakpointLocationList.h --------------------------------*- 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 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_BreakpointLocationList_h_
11 #define liblldb_BreakpointLocationList_h_
19 // Other libraries and framework includes
21 #include "lldb/Core/Address.h"
22 #include "lldb/Utility/Iterable.h"
23 #include "lldb/lldb-private.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class BreakpointLocationList BreakpointLocationList.h
29 /// "lldb/Breakpoint/BreakpointLocationList.h" This class is used by
30 /// Breakpoint to manage a list of breakpoint locations, each breakpoint
31 /// location in the list has a unique ID, and is unique by Address as well.
32 //----------------------------------------------------------------------
33 class BreakpointLocationList {
34 // Only Breakpoints can make the location list, or add elements to it. This
35 // is not just some random collection of locations. Rather, the act of
36 // adding the location to this list sets its ID, and implicitly all the
37 // locations have the same breakpoint ID as well. If you need a generic
38 // container for breakpoint locations, use BreakpointLocationCollection.
39 friend class Breakpoint;
42 virtual ~BreakpointLocationList();
44 //------------------------------------------------------------------
45 /// Standard "Dump" method. At present it does nothing.
46 //------------------------------------------------------------------
47 void Dump(Stream *s) const;
49 //------------------------------------------------------------------
50 /// Returns a shared pointer to the breakpoint location at address \a addr -
54 /// The address to look for.
57 /// A shared pointer to the breakpoint. May contain a nullptr
58 /// pointer if the breakpoint doesn't exist.
59 //------------------------------------------------------------------
60 const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;
62 //------------------------------------------------------------------
63 /// Returns a shared pointer to the breakpoint location with id \a breakID,
66 /// @param[in] breakID
67 /// The breakpoint location ID to seek for.
70 /// A shared pointer to the breakpoint. May contain a nullptr
71 /// pointer if the breakpoint doesn't exist.
72 //------------------------------------------------------------------
73 lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const;
75 //------------------------------------------------------------------
76 /// Returns the breakpoint location id to the breakpoint location at address
80 /// The address to match.
83 /// The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
84 //------------------------------------------------------------------
85 lldb::break_id_t FindIDByAddress(const Address &addr);
87 //------------------------------------------------------------------
88 /// Returns a breakpoint location list of the breakpoint locations in the
89 /// module \a module. This list is allocated, and owned by the caller.
92 /// The module to seek in.
95 /// A breakpoint collection that gets any breakpoint locations
96 /// that match \a module appended to.
99 /// The number of matches
100 //------------------------------------------------------------------
101 size_t FindInModule(Module *module,
102 BreakpointLocationCollection &bp_loc_list);
104 //------------------------------------------------------------------
105 /// Returns a shared pointer to the breakpoint location with index \a i.
108 /// The breakpoint location index to seek for.
111 /// A shared pointer to the breakpoint. May contain a nullptr
112 /// pointer if the breakpoint doesn't exist.
113 //------------------------------------------------------------------
114 lldb::BreakpointLocationSP GetByIndex(size_t i);
116 //------------------------------------------------------------------
117 /// Returns a shared pointer to the breakpoint location with index \a i,
121 /// The breakpoint location index to seek for.
124 /// A shared pointer to the breakpoint. May contain a nullptr
125 /// pointer if the breakpoint doesn't exist.
126 //------------------------------------------------------------------
127 const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
129 //------------------------------------------------------------------
130 /// Removes all the locations in this list from their breakpoint site owners
132 //------------------------------------------------------------------
133 void ClearAllBreakpointSites();
135 //------------------------------------------------------------------
136 /// Tells all the breakpoint locations in this list to attempt to resolve
137 /// any possible breakpoint sites.
138 //------------------------------------------------------------------
139 void ResolveAllBreakpointSites();
141 //------------------------------------------------------------------
142 /// Returns the number of breakpoint locations in this list with resolved
146 /// Number of qualifying breakpoint locations.
147 //------------------------------------------------------------------
148 size_t GetNumResolvedLocations() const;
150 //------------------------------------------------------------------
151 /// Returns the number hit count of all locations in this list.
154 /// Hit count of all locations in this list.
155 //------------------------------------------------------------------
156 uint32_t GetHitCount() const;
158 //------------------------------------------------------------------
159 /// Enquires of the breakpoint location in this list with ID \a breakID
160 /// whether we should stop.
162 /// @param[in] context
163 /// This contains the information about this stop.
165 /// @param[in] breakID
166 /// This break ID that we hit.
169 /// \b true if we should stop, \b false otherwise.
170 //------------------------------------------------------------------
171 bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
173 //------------------------------------------------------------------
174 /// Returns the number of elements in this breakpoint location list.
177 /// The number of elements.
178 //------------------------------------------------------------------
179 size_t GetSize() const { return m_locations.size(); }
181 //------------------------------------------------------------------
182 /// Print a description of the breakpoint locations in this list to the
186 /// The stream to which to print the description.
189 /// The description level that indicates the detail level to
192 /// @see lldb::DescriptionLevel
193 //------------------------------------------------------------------
194 void GetDescription(Stream *s, lldb::DescriptionLevel level);
197 //------------------------------------------------------------------
198 /// This is the standard constructor.
200 /// It creates an empty breakpoint location list. It is protected here
201 /// because only Breakpoints are allowed to create the breakpoint location
203 //------------------------------------------------------------------
204 BreakpointLocationList(Breakpoint &owner);
206 //------------------------------------------------------------------
207 /// Add the breakpoint \a bp_loc_sp to the list.
210 /// Shared pointer to the breakpoint location that will get
211 /// added to the list.
214 /// Returns breakpoint location id.
215 //------------------------------------------------------------------
216 lldb::BreakpointLocationSP Create(const Address &addr,
217 bool resolve_indirect_symbols);
219 void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
221 void StopRecordingNewLocations();
223 lldb::BreakpointLocationSP AddLocation(const Address &addr,
224 bool resolve_indirect_symbols,
225 bool *new_location = nullptr);
227 void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
228 lldb::BreakpointLocationSP from_location_sp);
230 bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
232 void RemoveLocationByIndex(size_t idx);
234 void RemoveInvalidLocations(const ArchSpec &arch);
238 typedef std::vector<lldb::BreakpointLocationSP> collection;
239 typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
240 Address::ModulePointerAndOffsetLessThanFunctionObject>
244 collection m_locations; // Vector of locations, sorted by ID
245 addr_map m_address_to_location;
246 mutable std::recursive_mutex m_mutex;
247 lldb::break_id_t m_next_id;
248 BreakpointLocationCollection *m_new_location_recorder;
251 typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
253 BreakpointLocationIterable;
255 BreakpointLocationIterable BreakpointLocations() {
256 return BreakpointLocationIterable(m_locations);
260 } // namespace lldb_private
262 #endif // liblldb_BreakpointLocationList_h_