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_
18 // Other libraries and framework includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Core/Address.h"
22 #include "lldb/Host/Mutex.h"
23 #include "lldb/Utility/Iterable.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class BreakpointLocationList BreakpointLocationList.h "lldb/Breakpoint/BreakpointLocationList.h"
29 /// @brief This class is used by Breakpoint to manage a list of breakpoint locations,
30 // each breakpoint location in the list
31 /// has a unique ID, and is unique by Address as well.
32 //----------------------------------------------------------------------
34 class BreakpointLocationList
36 // Only Breakpoints can make the location list, or add elements to it.
37 // This is not just some random collection of locations. Rather, the act of adding the location
38 // to this list sets its ID, and implicitly all the locations have the same breakpoint ID as
39 // well. If you need a generic container for breakpoint locations, use BreakpointLocationCollection.
40 friend class Breakpoint;
44 ~BreakpointLocationList();
46 //------------------------------------------------------------------
47 /// Standard "Dump" method. At present it does nothing.
48 //------------------------------------------------------------------
50 Dump (Stream *s) const;
52 //------------------------------------------------------------------
53 /// Returns a shared pointer to the breakpoint location at address
54 /// \a addr - const version.
57 /// The address to look for.
60 /// A shared pointer to the breakpoint. May contain a nullptr
61 /// pointer if the breakpoint doesn't exist.
62 //------------------------------------------------------------------
63 const lldb::BreakpointLocationSP
64 FindByAddress (const Address &addr) const;
66 //------------------------------------------------------------------
67 /// Returns a shared pointer to the breakpoint location with id
68 /// \a breakID, const version.
70 /// @param[in] breakID
71 /// The breakpoint location ID to seek for.
74 /// A shared pointer to the breakpoint. May contain a nullptr
75 /// pointer if the breakpoint doesn't exist.
76 //------------------------------------------------------------------
77 lldb::BreakpointLocationSP
78 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 //------------------------------------------------------------------
91 FindIDByAddress (const Address &addr);
93 //------------------------------------------------------------------
94 /// Returns a breakpoint location list of the breakpoint locations
95 /// in the module \a module. This list is allocated, and owned by
99 /// The module to seek in.
102 /// A breakpoint collection that gets any breakpoint locations
103 /// that match \a module appended to.
106 /// The number of matches
107 //------------------------------------------------------------------
109 FindInModule (Module *module,
110 BreakpointLocationCollection& bp_loc_list);
112 //------------------------------------------------------------------
113 /// Returns a shared pointer to the breakpoint location with
117 /// The breakpoint location index to seek for.
120 /// A shared pointer to the breakpoint. May contain a nullptr
121 /// pointer if the breakpoint doesn't exist.
122 //------------------------------------------------------------------
123 lldb::BreakpointLocationSP
124 GetByIndex (size_t i);
126 //------------------------------------------------------------------
127 /// Returns a shared pointer to the breakpoint location with index
128 /// \a i, const version.
131 /// The breakpoint location index to seek for.
134 /// A shared pointer to the breakpoint. May contain a nullptr
135 /// pointer if the breakpoint doesn't exist.
136 //------------------------------------------------------------------
137 const lldb::BreakpointLocationSP
138 GetByIndex (size_t i) const;
140 //------------------------------------------------------------------
141 /// Removes all the locations in this list from their breakpoint site
143 //------------------------------------------------------------------
145 ClearAllBreakpointSites ();
147 //------------------------------------------------------------------
148 /// Tells all the breakpoint locations in this list to attempt to
149 /// resolve any possible breakpoint sites.
150 //------------------------------------------------------------------
152 ResolveAllBreakpointSites ();
154 //------------------------------------------------------------------
155 /// Returns the number of breakpoint locations in this list with
156 /// resolved breakpoints.
159 /// Number of qualifying breakpoint locations.
160 //------------------------------------------------------------------
162 GetNumResolvedLocations() const;
164 //------------------------------------------------------------------
165 /// Returns the number hit count of all locations in this list.
168 /// Hit count of all locations in this list.
169 //------------------------------------------------------------------
171 GetHitCount () const;
173 //------------------------------------------------------------------
174 /// Enquires of the breakpoint location in this list with ID \a
175 /// breakID whether we should stop.
177 /// @param[in] context
178 /// This contains the information about this stop.
180 /// @param[in] breakID
181 /// This break ID that we hit.
184 /// \b true if we should stop, \b false otherwise.
185 //------------------------------------------------------------------
187 ShouldStop (StoppointCallbackContext *context,
188 lldb::break_id_t breakID);
190 //------------------------------------------------------------------
191 /// Returns the number of elements in this breakpoint location list.
194 /// The number of elements.
195 //------------------------------------------------------------------
199 return m_locations.size();
202 //------------------------------------------------------------------
203 /// Print a description of the breakpoint locations in this list to
207 /// The stream to which to print the description.
210 /// The description level that indicates the detail level to
213 /// @see lldb::DescriptionLevel
214 //------------------------------------------------------------------
216 GetDescription (Stream *s,
217 lldb::DescriptionLevel level);
220 //------------------------------------------------------------------
221 /// This is the standard constructor.
223 /// It creates an empty breakpoint location list. It is protected
224 /// here because only Breakpoints are allowed to create the
225 /// breakpoint location list.
226 //------------------------------------------------------------------
227 BreakpointLocationList(Breakpoint &owner);
229 //------------------------------------------------------------------
230 /// Add the breakpoint \a bp_loc_sp to the list.
233 /// Shared pointer to the breakpoint location that will get
234 /// added to the list.
237 /// Returns breakpoint location id.
238 //------------------------------------------------------------------
239 lldb::BreakpointLocationSP
240 Create (const Address &addr, bool resolve_indirect_symbols);
243 StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
246 StopRecordingNewLocations();
248 lldb::BreakpointLocationSP
249 AddLocation(const Address &addr,
250 bool resolve_indirect_symbols,
251 bool *new_location = nullptr);
254 SwapLocation (lldb::BreakpointLocationSP to_location_sp, lldb::BreakpointLocationSP from_location_sp);
257 RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp);
260 RemoveInvalidLocations (const ArchSpec &arch);
265 typedef std::vector<lldb::BreakpointLocationSP> collection;
266 typedef std::map<lldb_private::Address,
267 lldb::BreakpointLocationSP,
268 Address::ModulePointerAndOffsetLessThanFunctionObject> addr_map;
271 collection m_locations; // Vector of locations, sorted by ID
272 addr_map m_address_to_location;
273 mutable Mutex m_mutex;
274 lldb::break_id_t m_next_id;
275 BreakpointLocationCollection *m_new_location_recorder;
278 typedef AdaptedIterable<collection, lldb::BreakpointLocationSP, vector_adapter> BreakpointLocationIterable;
280 BreakpointLocationIterable
281 BreakpointLocations()
283 return BreakpointLocationIterable(m_locations);
287 } // namespace lldb_private
289 #endif // liblldb_BreakpointLocationList_h_