]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointLocationList.h
Import NetBSD's blacklist source from vendor tree
[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 <vector>
17
18 // Other libraries and framework includes
19 // Project 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"
24
25 namespace lldb_private {
26
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 //----------------------------------------------------------------------
33
34 class BreakpointLocationList
35 {
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;
41
42 public:
43     virtual 
44     ~BreakpointLocationList();
45
46     //------------------------------------------------------------------
47     /// Standard "Dump" method.  At present it does nothing.
48     //------------------------------------------------------------------
49     void
50     Dump (Stream *s) const;
51
52     //------------------------------------------------------------------
53     /// Returns a shared pointer to the breakpoint location at address
54     /// \a addr - const version.
55     ///
56     /// @param[in] addr
57     ///     The address to look for.
58     ///
59     /// @result
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;
65
66     //------------------------------------------------------------------
67     /// Returns a shared pointer to the breakpoint location with id
68     /// \a breakID, const version.
69     ///
70     /// @param[in] breakID
71     ///     The breakpoint location ID to seek for.
72     ///
73     /// @result
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;
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
91     FindIDByAddress (const Address &addr);
92
93     //------------------------------------------------------------------
94     /// Returns a breakpoint location list of the breakpoint locations
95     /// in the module \a module.  This list is allocated, and owned by
96     /// the caller.
97     ///
98     /// @param[in] module
99     ///     The module to seek in.
100     ///
101     /// @param[in]
102     ///     A breakpoint collection that gets any breakpoint locations
103     ///     that match \a module appended to.
104     ///
105     /// @result
106     ///     The number of matches
107     //------------------------------------------------------------------
108     size_t
109     FindInModule (Module *module,
110                   BreakpointLocationCollection& bp_loc_list);
111
112     //------------------------------------------------------------------
113     /// Returns a shared pointer to the breakpoint location with
114     /// index \a i.
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     lldb::BreakpointLocationSP
124     GetByIndex (size_t i);
125
126     //------------------------------------------------------------------
127     /// Returns a shared pointer to the breakpoint location with index
128     /// \a i, const version.
129     ///
130     /// @param[in] i
131     ///     The breakpoint location index to seek for.
132     ///
133     /// @result
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;
139
140     //------------------------------------------------------------------
141     /// Removes all the locations in this list from their breakpoint site
142     /// owners list.
143     //------------------------------------------------------------------
144     void
145     ClearAllBreakpointSites ();
146
147     //------------------------------------------------------------------
148     /// Tells all the breakpoint locations in this list to attempt to
149     /// resolve any possible breakpoint sites.
150     //------------------------------------------------------------------
151     void
152     ResolveAllBreakpointSites ();
153
154     //------------------------------------------------------------------
155     /// Returns the number of breakpoint locations in this list with
156     /// resolved breakpoints.
157     ///
158     /// @result
159     ///     Number of qualifying breakpoint locations.
160     //------------------------------------------------------------------
161     size_t
162     GetNumResolvedLocations() const;
163
164     //------------------------------------------------------------------
165     /// Returns the number hit count of all locations in this list.
166     ///
167     /// @result
168     ///     Hit count of all locations in this list.
169     //------------------------------------------------------------------
170     uint32_t
171     GetHitCount () const;
172
173     //------------------------------------------------------------------
174     /// Enquires of the breakpoint location in this list with ID \a
175     /// breakID whether we should stop.
176     ///
177     /// @param[in] context
178     ///     This contains the information about this stop.
179     ///
180     /// @param[in] breakID
181     ///     This break ID that we hit.
182     ///
183     /// @return
184     ///     \b true if we should stop, \b false otherwise.
185     //------------------------------------------------------------------
186     bool
187     ShouldStop (StoppointCallbackContext *context,
188                 lldb::break_id_t breakID);
189
190     //------------------------------------------------------------------
191     /// Returns the number of elements in this breakpoint location list.
192     ///
193     /// @result
194     ///     The number of elements.
195     //------------------------------------------------------------------
196     size_t
197     GetSize() const
198     {
199         return m_locations.size();
200     }
201
202     //------------------------------------------------------------------
203     /// Print a description of the breakpoint locations in this list to
204     /// the stream \a s.
205     ///
206     /// @param[in] s
207     ///     The stream to which to print the description.
208     ///
209     /// @param[in] level
210     ///     The description level that indicates the detail level to
211     ///     provide.
212     ///
213     /// @see lldb::DescriptionLevel
214     //------------------------------------------------------------------
215     void
216     GetDescription (Stream *s,
217                     lldb::DescriptionLevel level);
218
219 protected:
220     //------------------------------------------------------------------
221     /// This is the standard constructor.
222     ///
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);
228
229     //------------------------------------------------------------------
230     /// Add the breakpoint \a bp_loc_sp to the list.
231     ///
232     /// @param[in] bp_sp
233     ///     Shared pointer to the breakpoint location that will get
234     ///     added to the list.
235     ///
236     /// @result
237     ///     Returns breakpoint location id.
238     //------------------------------------------------------------------
239     lldb::BreakpointLocationSP
240     Create (const Address &addr, bool resolve_indirect_symbols);
241     
242     void
243     StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
244     
245     void
246     StopRecordingNewLocations();
247     
248     lldb::BreakpointLocationSP
249     AddLocation(const Address &addr,
250                 bool resolve_indirect_symbols,
251                 bool *new_location = nullptr);
252     
253     void
254     SwapLocation (lldb::BreakpointLocationSP to_location_sp, lldb::BreakpointLocationSP from_location_sp);
255
256     bool
257     RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp);
258     
259     void
260     RemoveInvalidLocations (const ArchSpec &arch);
261     
262     void
263     Compact();
264
265     typedef std::vector<lldb::BreakpointLocationSP> collection;
266     typedef std::map<lldb_private::Address,
267                      lldb::BreakpointLocationSP,
268                      Address::ModulePointerAndOffsetLessThanFunctionObject> addr_map;
269
270     Breakpoint &m_owner;
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;
276
277 public:
278     typedef AdaptedIterable<collection, lldb::BreakpointLocationSP, vector_adapter> BreakpointLocationIterable;
279
280     BreakpointLocationIterable
281     BreakpointLocations()
282     {
283         return BreakpointLocationIterable(m_locations);
284     }
285 };
286
287 } // namespace lldb_private
288
289 #endif // liblldb_BreakpointLocationList_h_