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_
17 #include "lldb/Core/Address.h"
18 #include "lldb/Utility/Iterable.h"
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class BreakpointLocationList BreakpointLocationList.h
25 /// "lldb/Breakpoint/BreakpointLocationList.h" This class is used by
26 /// Breakpoint to manage a list of breakpoint locations, each breakpoint
27 /// location in the list has a unique ID, and is unique by Address as well.
28 //----------------------------------------------------------------------
29 class BreakpointLocationList {
30 // Only Breakpoints can make the location list, or add elements to it. This
31 // is not just some random collection of locations. Rather, the act of
32 // adding the location to this list sets its ID, and implicitly all the
33 // locations have the same breakpoint ID as well. If you need a generic
34 // container for breakpoint locations, use BreakpointLocationCollection.
35 friend class Breakpoint;
38 virtual ~BreakpointLocationList();
40 //------------------------------------------------------------------
41 /// Standard "Dump" method. At present it does nothing.
42 //------------------------------------------------------------------
43 void Dump(Stream *s) const;
45 //------------------------------------------------------------------
46 /// Returns a shared pointer to the breakpoint location at address \a addr -
50 /// The address to look for.
53 /// A shared pointer to the breakpoint. May contain a nullptr
54 /// pointer if the breakpoint doesn't exist.
55 //------------------------------------------------------------------
56 const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;
58 //------------------------------------------------------------------
59 /// Returns a shared pointer to the breakpoint location with id \a breakID,
62 /// @param[in] breakID
63 /// The breakpoint location ID to seek for.
66 /// A shared pointer to the breakpoint. May contain a nullptr
67 /// pointer if the breakpoint doesn't exist.
68 //------------------------------------------------------------------
69 lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const;
71 //------------------------------------------------------------------
72 /// Returns the breakpoint location id to the breakpoint location at address
76 /// The address to match.
79 /// The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
80 //------------------------------------------------------------------
81 lldb::break_id_t FindIDByAddress(const Address &addr);
83 //------------------------------------------------------------------
84 /// Returns a breakpoint location list of the breakpoint locations in the
85 /// module \a module. This list is allocated, and owned by the caller.
88 /// The module to seek in.
91 /// A breakpoint collection that gets any breakpoint locations
92 /// that match \a module appended to.
95 /// The number of matches
96 //------------------------------------------------------------------
97 size_t FindInModule(Module *module,
98 BreakpointLocationCollection &bp_loc_list);
100 //------------------------------------------------------------------
101 /// Returns a shared pointer to the breakpoint location with index \a i.
104 /// The breakpoint location index to seek for.
107 /// A shared pointer to the breakpoint. May contain a nullptr
108 /// pointer if the breakpoint doesn't exist.
109 //------------------------------------------------------------------
110 lldb::BreakpointLocationSP GetByIndex(size_t i);
112 //------------------------------------------------------------------
113 /// Returns a shared pointer to the breakpoint location with index \a i,
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 const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
125 //------------------------------------------------------------------
126 /// Removes all the locations in this list from their breakpoint site owners
128 //------------------------------------------------------------------
129 void ClearAllBreakpointSites();
131 //------------------------------------------------------------------
132 /// Tells all the breakpoint locations in this list to attempt to resolve
133 /// any possible breakpoint sites.
134 //------------------------------------------------------------------
135 void ResolveAllBreakpointSites();
137 //------------------------------------------------------------------
138 /// Returns the number of breakpoint locations in this list with resolved
142 /// Number of qualifying breakpoint locations.
143 //------------------------------------------------------------------
144 size_t GetNumResolvedLocations() const;
146 //------------------------------------------------------------------
147 /// Returns the number hit count of all locations in this list.
150 /// Hit count of all locations in this list.
151 //------------------------------------------------------------------
152 uint32_t GetHitCount() const;
154 //------------------------------------------------------------------
155 /// Enquires of the breakpoint location in this list with ID \a breakID
156 /// whether we should stop.
158 /// @param[in] context
159 /// This contains the information about this stop.
161 /// @param[in] breakID
162 /// This break ID that we hit.
165 /// \b true if we should stop, \b false otherwise.
166 //------------------------------------------------------------------
167 bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
169 //------------------------------------------------------------------
170 /// Returns the number of elements in this breakpoint location list.
173 /// The number of elements.
174 //------------------------------------------------------------------
175 size_t GetSize() const { return m_locations.size(); }
177 //------------------------------------------------------------------
178 /// Print a description of the breakpoint locations in this list to the
182 /// The stream to which to print the description.
185 /// The description level that indicates the detail level to
188 /// @see lldb::DescriptionLevel
189 //------------------------------------------------------------------
190 void GetDescription(Stream *s, lldb::DescriptionLevel level);
193 //------------------------------------------------------------------
194 /// This is the standard constructor.
196 /// It creates an empty breakpoint location list. It is protected here
197 /// because only Breakpoints are allowed to create the breakpoint location
199 //------------------------------------------------------------------
200 BreakpointLocationList(Breakpoint &owner);
202 //------------------------------------------------------------------
203 /// Add the breakpoint \a bp_loc_sp to the list.
206 /// Shared pointer to the breakpoint location that will get
207 /// added to the list.
210 /// Returns breakpoint location id.
211 //------------------------------------------------------------------
212 lldb::BreakpointLocationSP Create(const Address &addr,
213 bool resolve_indirect_symbols);
215 void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
217 void StopRecordingNewLocations();
219 lldb::BreakpointLocationSP AddLocation(const Address &addr,
220 bool resolve_indirect_symbols,
221 bool *new_location = nullptr);
223 void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
224 lldb::BreakpointLocationSP from_location_sp);
226 bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
228 void RemoveLocationByIndex(size_t idx);
230 void RemoveInvalidLocations(const ArchSpec &arch);
234 typedef std::vector<lldb::BreakpointLocationSP> collection;
235 typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
236 Address::ModulePointerAndOffsetLessThanFunctionObject>
240 collection m_locations; // Vector of locations, sorted by ID
241 addr_map m_address_to_location;
242 mutable std::recursive_mutex m_mutex;
243 lldb::break_id_t m_next_id;
244 BreakpointLocationCollection *m_new_location_recorder;
247 typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
249 BreakpointLocationIterable;
251 BreakpointLocationIterable BreakpointLocations() {
252 return BreakpointLocationIterable(m_locations);
256 } // namespace lldb_private
258 #endif // liblldb_BreakpointLocationList_h_