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"
30 /// @brief This class is used by Breakpoint to manage a list of breakpoint
32 // each breakpoint location in the list
33 /// has a unique ID, and is unique by Address as well.
34 //----------------------------------------------------------------------
36 class BreakpointLocationList {
37 // Only Breakpoints can make the location list, or add elements to it.
38 // This is not just some random collection of locations. Rather, the act of
39 // adding the location
40 // to this list sets its ID, and implicitly all the locations have the same
42 // well. If you need a generic container for breakpoint locations, use
43 // BreakpointLocationCollection.
44 friend class Breakpoint;
47 virtual ~BreakpointLocationList();
49 //------------------------------------------------------------------
50 /// Standard "Dump" method. At present it does nothing.
51 //------------------------------------------------------------------
52 void Dump(Stream *s) const;
54 //------------------------------------------------------------------
55 /// Returns a shared pointer to the breakpoint location at address
56 /// \a addr - const version.
59 /// The address to look for.
62 /// A shared pointer to the breakpoint. May contain a nullptr
63 /// pointer if the breakpoint doesn't exist.
64 //------------------------------------------------------------------
65 const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;
67 //------------------------------------------------------------------
68 /// Returns a shared pointer to the breakpoint location with id
69 /// \a breakID, const version.
71 /// @param[in] breakID
72 /// The breakpoint location ID to seek for.
75 /// A shared pointer to the breakpoint. May contain a nullptr
76 /// pointer if the breakpoint doesn't exist.
77 //------------------------------------------------------------------
78 lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const;
80 //------------------------------------------------------------------
81 /// Returns the breakpoint location id to the breakpoint location
82 /// at address \a addr.
85 /// The address to match.
88 /// The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
89 //------------------------------------------------------------------
90 lldb::break_id_t FindIDByAddress(const Address &addr);
92 //------------------------------------------------------------------
93 /// Returns a breakpoint location list of the breakpoint locations
94 /// in the module \a module. This list is allocated, and owned by
98 /// The module to seek in.
101 /// A breakpoint collection that gets any breakpoint locations
102 /// that match \a module appended to.
105 /// The number of matches
106 //------------------------------------------------------------------
107 size_t FindInModule(Module *module,
108 BreakpointLocationCollection &bp_loc_list);
110 //------------------------------------------------------------------
111 /// Returns a shared pointer to the breakpoint location with
115 /// The breakpoint location index to seek for.
118 /// A shared pointer to the breakpoint. May contain a nullptr
119 /// pointer if the breakpoint doesn't exist.
120 //------------------------------------------------------------------
121 lldb::BreakpointLocationSP GetByIndex(size_t i);
123 //------------------------------------------------------------------
124 /// Returns a shared pointer to the breakpoint location with index
125 /// \a i, const version.
128 /// The breakpoint location index to seek for.
131 /// A shared pointer to the breakpoint. May contain a nullptr
132 /// pointer if the breakpoint doesn't exist.
133 //------------------------------------------------------------------
134 const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
136 //------------------------------------------------------------------
137 /// Removes all the locations in this list from their breakpoint site
139 //------------------------------------------------------------------
140 void ClearAllBreakpointSites();
142 //------------------------------------------------------------------
143 /// Tells all the breakpoint locations in this list to attempt to
144 /// resolve any possible breakpoint sites.
145 //------------------------------------------------------------------
146 void ResolveAllBreakpointSites();
148 //------------------------------------------------------------------
149 /// Returns the number of breakpoint locations in this list with
150 /// resolved breakpoints.
153 /// Number of qualifying breakpoint locations.
154 //------------------------------------------------------------------
155 size_t GetNumResolvedLocations() const;
157 //------------------------------------------------------------------
158 /// Returns the number hit count of all locations in this list.
161 /// Hit count of all locations in this list.
162 //------------------------------------------------------------------
163 uint32_t GetHitCount() const;
165 //------------------------------------------------------------------
166 /// Enquires of the breakpoint location in this list with ID \a
167 /// breakID whether we should stop.
169 /// @param[in] context
170 /// This contains the information about this stop.
172 /// @param[in] breakID
173 /// This break ID that we hit.
176 /// \b true if we should stop, \b false otherwise.
177 //------------------------------------------------------------------
178 bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
180 //------------------------------------------------------------------
181 /// Returns the number of elements in this breakpoint location list.
184 /// The number of elements.
185 //------------------------------------------------------------------
186 size_t GetSize() const { return m_locations.size(); }
188 //------------------------------------------------------------------
189 /// Print a description of the breakpoint locations in this list to
193 /// The stream to which to print the description.
196 /// The description level that indicates the detail level to
199 /// @see lldb::DescriptionLevel
200 //------------------------------------------------------------------
201 void GetDescription(Stream *s, lldb::DescriptionLevel level);
204 //------------------------------------------------------------------
205 /// This is the standard constructor.
207 /// It creates an empty breakpoint location list. It is protected
208 /// here because only Breakpoints are allowed to create the
209 /// breakpoint location list.
210 //------------------------------------------------------------------
211 BreakpointLocationList(Breakpoint &owner);
213 //------------------------------------------------------------------
214 /// Add the breakpoint \a bp_loc_sp to the list.
217 /// Shared pointer to the breakpoint location that will get
218 /// added to the list.
221 /// Returns breakpoint location id.
222 //------------------------------------------------------------------
223 lldb::BreakpointLocationSP Create(const Address &addr,
224 bool resolve_indirect_symbols);
226 void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
228 void StopRecordingNewLocations();
230 lldb::BreakpointLocationSP AddLocation(const Address &addr,
231 bool resolve_indirect_symbols,
232 bool *new_location = nullptr);
234 void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
235 lldb::BreakpointLocationSP from_location_sp);
237 bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
239 void RemoveInvalidLocations(const ArchSpec &arch);
243 typedef std::vector<lldb::BreakpointLocationSP> collection;
244 typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
245 Address::ModulePointerAndOffsetLessThanFunctionObject>
249 collection m_locations; // Vector of locations, sorted by ID
250 addr_map m_address_to_location;
251 mutable std::recursive_mutex m_mutex;
252 lldb::break_id_t m_next_id;
253 BreakpointLocationCollection *m_new_location_recorder;
256 typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
258 BreakpointLocationIterable;
260 BreakpointLocationIterable BreakpointLocations() {
261 return BreakpointLocationIterable(m_locations);
265 } // namespace lldb_private
267 #endif // liblldb_BreakpointLocationList_h_