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