]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointLocationList.h
Merge clang trunk r338150 (just before the 7.0.0 branch point), and
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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" 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;
40
41 public:
42   virtual ~BreakpointLocationList();
43
44   //------------------------------------------------------------------
45   /// Standard "Dump" method.  At present it does nothing.
46   //------------------------------------------------------------------
47   void Dump(Stream *s) const;
48
49   //------------------------------------------------------------------
50   /// Returns a shared pointer to the breakpoint location at address \a addr -
51   /// const version.
52   ///
53   /// @param[in] addr
54   ///     The address to look for.
55   ///
56   /// @result
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;
61
62   //------------------------------------------------------------------
63   /// Returns a shared pointer to the breakpoint location with id \a breakID,
64   /// const version.
65   ///
66   /// @param[in] breakID
67   ///     The breakpoint location ID to seek for.
68   ///
69   /// @result
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;
74
75   //------------------------------------------------------------------
76   /// Returns the breakpoint location id to the breakpoint location at address
77   /// \a addr.
78   ///
79   /// @param[in] addr
80   ///     The address to match.
81   ///
82   /// @result
83   ///     The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
84   //------------------------------------------------------------------
85   lldb::break_id_t FindIDByAddress(const Address &addr);
86
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.
90   ///
91   /// @param[in] module
92   ///     The module to seek in.
93   ///
94   /// @param[in]
95   ///     A breakpoint collection that gets any breakpoint locations
96   ///     that match \a module appended to.
97   ///
98   /// @result
99   ///     The number of matches
100   //------------------------------------------------------------------
101   size_t FindInModule(Module *module,
102                       BreakpointLocationCollection &bp_loc_list);
103
104   //------------------------------------------------------------------
105   /// Returns a shared pointer to the breakpoint location with index \a i.
106   ///
107   /// @param[in] i
108   ///     The breakpoint location index to seek for.
109   ///
110   /// @result
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);
115
116   //------------------------------------------------------------------
117   /// Returns a shared pointer to the breakpoint location with index \a i,
118   /// const version.
119   ///
120   /// @param[in] i
121   ///     The breakpoint location index to seek for.
122   ///
123   /// @result
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;
128
129   //------------------------------------------------------------------
130   /// Removes all the locations in this list from their breakpoint site owners
131   /// list.
132   //------------------------------------------------------------------
133   void ClearAllBreakpointSites();
134
135   //------------------------------------------------------------------
136   /// Tells all the breakpoint locations in this list to attempt to resolve
137   /// any possible breakpoint sites.
138   //------------------------------------------------------------------
139   void ResolveAllBreakpointSites();
140
141   //------------------------------------------------------------------
142   /// Returns the number of breakpoint locations in this list with resolved
143   /// breakpoints.
144   ///
145   /// @result
146   ///     Number of qualifying breakpoint locations.
147   //------------------------------------------------------------------
148   size_t GetNumResolvedLocations() const;
149
150   //------------------------------------------------------------------
151   /// Returns the number hit count of all locations in this list.
152   ///
153   /// @result
154   ///     Hit count of all locations in this list.
155   //------------------------------------------------------------------
156   uint32_t GetHitCount() const;
157
158   //------------------------------------------------------------------
159   /// Enquires of the breakpoint location in this list with ID \a breakID
160   /// whether we should stop.
161   ///
162   /// @param[in] context
163   ///     This contains the information about this stop.
164   ///
165   /// @param[in] breakID
166   ///     This break ID that we hit.
167   ///
168   /// @return
169   ///     \b true if we should stop, \b false otherwise.
170   //------------------------------------------------------------------
171   bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
172
173   //------------------------------------------------------------------
174   /// Returns the number of elements in this breakpoint location list.
175   ///
176   /// @result
177   ///     The number of elements.
178   //------------------------------------------------------------------
179   size_t GetSize() const { return m_locations.size(); }
180
181   //------------------------------------------------------------------
182   /// Print a description of the breakpoint locations in this list to the
183   /// stream \a s.
184   ///
185   /// @param[in] s
186   ///     The stream to which to print the description.
187   ///
188   /// @param[in] level
189   ///     The description level that indicates the detail level to
190   ///     provide.
191   ///
192   /// @see lldb::DescriptionLevel
193   //------------------------------------------------------------------
194   void GetDescription(Stream *s, lldb::DescriptionLevel level);
195
196 protected:
197   //------------------------------------------------------------------
198   /// This is the standard constructor.
199   ///
200   /// It creates an empty breakpoint location list. It is protected here
201   /// because only Breakpoints are allowed to create the breakpoint location
202   /// list.
203   //------------------------------------------------------------------
204   BreakpointLocationList(Breakpoint &owner);
205
206   //------------------------------------------------------------------
207   /// Add the breakpoint \a bp_loc_sp to the list.
208   ///
209   /// @param[in] bp_sp
210   ///     Shared pointer to the breakpoint location that will get
211   ///     added to the list.
212   ///
213   /// @result
214   ///     Returns breakpoint location id.
215   //------------------------------------------------------------------
216   lldb::BreakpointLocationSP Create(const Address &addr,
217                                     bool resolve_indirect_symbols);
218
219   void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
220
221   void StopRecordingNewLocations();
222
223   lldb::BreakpointLocationSP AddLocation(const Address &addr,
224                                          bool resolve_indirect_symbols,
225                                          bool *new_location = nullptr);
226
227   void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
228                     lldb::BreakpointLocationSP from_location_sp);
229
230   bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
231   
232   void RemoveLocationByIndex(size_t idx);
233
234   void RemoveInvalidLocations(const ArchSpec &arch);
235
236   void Compact();
237
238   typedef std::vector<lldb::BreakpointLocationSP> collection;
239   typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
240                    Address::ModulePointerAndOffsetLessThanFunctionObject>
241       addr_map;
242
243   Breakpoint &m_owner;
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;
249
250 public:
251   typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
252                           vector_adapter>
253       BreakpointLocationIterable;
254
255   BreakpointLocationIterable BreakpointLocations() {
256     return BreakpointLocationIterable(m_locations);
257   }
258 };
259
260 } // namespace lldb_private
261
262 #endif // liblldb_BreakpointLocationList_h_