]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Breakpoint/BreakpointLocationList.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Breakpoint / BreakpointLocationList.h
1 //===-- BreakpointLocationList.h --------------------------------*- 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 #ifndef liblldb_BreakpointLocationList_h_
11 #define liblldb_BreakpointLocationList_h_
12
13 // C Includes
14 // C++ Includes
15 #include <map>
16 #include <mutex>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/Core/Address.h"
22 #include "lldb/Utility/Iterable.h"
23 #include "lldb/lldb-private.h"
24
25 namespace lldb_private {
26
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
31 /// locations,
32 //  each breakpoint location in the list
33 /// has a unique ID, and is unique by Address as well.
34 //----------------------------------------------------------------------
35
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
41   // breakpoint ID as
42   // well.  If you need a generic container for breakpoint locations, use
43   // BreakpointLocationCollection.
44   friend class Breakpoint;
45
46 public:
47   virtual ~BreakpointLocationList();
48
49   //------------------------------------------------------------------
50   /// Standard "Dump" method.  At present it does nothing.
51   //------------------------------------------------------------------
52   void Dump(Stream *s) const;
53
54   //------------------------------------------------------------------
55   /// Returns a shared pointer to the breakpoint location at address
56   /// \a addr - const version.
57   ///
58   /// @param[in] addr
59   ///     The address to look for.
60   ///
61   /// @result
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;
66
67   //------------------------------------------------------------------
68   /// Returns a shared pointer to the breakpoint location with id
69   /// \a breakID, const version.
70   ///
71   /// @param[in] breakID
72   ///     The breakpoint location ID to seek for.
73   ///
74   /// @result
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;
79
80   //------------------------------------------------------------------
81   /// Returns the breakpoint location id to the breakpoint location
82   /// at address \a addr.
83   ///
84   /// @param[in] addr
85   ///     The address to match.
86   ///
87   /// @result
88   ///     The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
89   //------------------------------------------------------------------
90   lldb::break_id_t FindIDByAddress(const Address &addr);
91
92   //------------------------------------------------------------------
93   /// Returns a breakpoint location list of the breakpoint locations
94   /// in the module \a module.  This list is allocated, and owned by
95   /// the caller.
96   ///
97   /// @param[in] module
98   ///     The module to seek in.
99   ///
100   /// @param[in]
101   ///     A breakpoint collection that gets any breakpoint locations
102   ///     that match \a module appended to.
103   ///
104   /// @result
105   ///     The number of matches
106   //------------------------------------------------------------------
107   size_t FindInModule(Module *module,
108                       BreakpointLocationCollection &bp_loc_list);
109
110   //------------------------------------------------------------------
111   /// Returns a shared pointer to the breakpoint location with
112   /// index \a i.
113   ///
114   /// @param[in] i
115   ///     The breakpoint location index to seek for.
116   ///
117   /// @result
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);
122
123   //------------------------------------------------------------------
124   /// Returns a shared pointer to the breakpoint location with index
125   /// \a i, const version.
126   ///
127   /// @param[in] i
128   ///     The breakpoint location index to seek for.
129   ///
130   /// @result
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;
135
136   //------------------------------------------------------------------
137   /// Removes all the locations in this list from their breakpoint site
138   /// owners list.
139   //------------------------------------------------------------------
140   void ClearAllBreakpointSites();
141
142   //------------------------------------------------------------------
143   /// Tells all the breakpoint locations in this list to attempt to
144   /// resolve any possible breakpoint sites.
145   //------------------------------------------------------------------
146   void ResolveAllBreakpointSites();
147
148   //------------------------------------------------------------------
149   /// Returns the number of breakpoint locations in this list with
150   /// resolved breakpoints.
151   ///
152   /// @result
153   ///     Number of qualifying breakpoint locations.
154   //------------------------------------------------------------------
155   size_t GetNumResolvedLocations() const;
156
157   //------------------------------------------------------------------
158   /// Returns the number hit count of all locations in this list.
159   ///
160   /// @result
161   ///     Hit count of all locations in this list.
162   //------------------------------------------------------------------
163   uint32_t GetHitCount() const;
164
165   //------------------------------------------------------------------
166   /// Enquires of the breakpoint location in this list with ID \a
167   /// breakID whether we should stop.
168   ///
169   /// @param[in] context
170   ///     This contains the information about this stop.
171   ///
172   /// @param[in] breakID
173   ///     This break ID that we hit.
174   ///
175   /// @return
176   ///     \b true if we should stop, \b false otherwise.
177   //------------------------------------------------------------------
178   bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
179
180   //------------------------------------------------------------------
181   /// Returns the number of elements in this breakpoint location list.
182   ///
183   /// @result
184   ///     The number of elements.
185   //------------------------------------------------------------------
186   size_t GetSize() const { return m_locations.size(); }
187
188   //------------------------------------------------------------------
189   /// Print a description of the breakpoint locations in this list to
190   /// the stream \a s.
191   ///
192   /// @param[in] s
193   ///     The stream to which to print the description.
194   ///
195   /// @param[in] level
196   ///     The description level that indicates the detail level to
197   ///     provide.
198   ///
199   /// @see lldb::DescriptionLevel
200   //------------------------------------------------------------------
201   void GetDescription(Stream *s, lldb::DescriptionLevel level);
202
203 protected:
204   //------------------------------------------------------------------
205   /// This is the standard constructor.
206   ///
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);
212
213   //------------------------------------------------------------------
214   /// Add the breakpoint \a bp_loc_sp to the list.
215   ///
216   /// @param[in] bp_sp
217   ///     Shared pointer to the breakpoint location that will get
218   ///     added to the list.
219   ///
220   /// @result
221   ///     Returns breakpoint location id.
222   //------------------------------------------------------------------
223   lldb::BreakpointLocationSP Create(const Address &addr,
224                                     bool resolve_indirect_symbols);
225
226   void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
227
228   void StopRecordingNewLocations();
229
230   lldb::BreakpointLocationSP AddLocation(const Address &addr,
231                                          bool resolve_indirect_symbols,
232                                          bool *new_location = nullptr);
233
234   void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
235                     lldb::BreakpointLocationSP from_location_sp);
236
237   bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
238
239   void RemoveInvalidLocations(const ArchSpec &arch);
240
241   void Compact();
242
243   typedef std::vector<lldb::BreakpointLocationSP> collection;
244   typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
245                    Address::ModulePointerAndOffsetLessThanFunctionObject>
246       addr_map;
247
248   Breakpoint &m_owner;
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;
254
255 public:
256   typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
257                           vector_adapter>
258       BreakpointLocationIterable;
259
260   BreakpointLocationIterable BreakpointLocations() {
261     return BreakpointLocationIterable(m_locations);
262   }
263 };
264
265 } // namespace lldb_private
266
267 #endif // liblldb_BreakpointLocationList_h_