BreakpointLocationList.h revision 3508c387c3f0c9ecc439d98048fd7694d41bab1b
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 <vector>
16#include <map>
17// Other libraries and framework includes
18// Project includes
19#include "lldb/lldb-private.h"
20#include "lldb/Core/Address.h"
21#include "lldb/Host/Mutex.h"
22
23namespace lldb_private {
24
25//----------------------------------------------------------------------
26/// @class BreakpointLocationList BreakpointLocationList.h "lldb/Breakpoint/BreakpointLocationList.h"
27/// @brief This class is used by Breakpoint to manage a list of breakpoint locations,
28//  each breakpoint location in the list
29/// has a unique ID, and is unique by Address as well.
30//----------------------------------------------------------------------
31
32class BreakpointLocationList
33{
34// Only Breakpoints can make the location list, or add elements to it.
35// This is not just some random collection of locations.  Rather, the act of adding the location
36// to this list sets its ID, and implicitly all the locations have the same breakpoint ID as
37// well.  If you need a generic container for breakpoint locations, use BreakpointLocationCollection.
38friend class Breakpoint;
39
40public:
41    virtual
42    ~BreakpointLocationList();
43
44    //------------------------------------------------------------------
45    /// Standard "Dump" method.  At present it does nothing.
46    //------------------------------------------------------------------
47    void
48    Dump (Stream *s) const;
49
50    //------------------------------------------------------------------
51    /// Returns a shared pointer to the breakpoint location at address
52    /// \a addr - const version.
53    ///
54    /// @param[in] addr
55    ///     The address to look for.
56    ///
57    /// @result
58    ///     A shared pointer to the breakpoint.  May contain a NULL
59    ///     pointer if the breakpoint doesn't exist.
60    //------------------------------------------------------------------
61    const lldb::BreakpointLocationSP
62    FindByAddress (const Address &addr) const;
63
64    //------------------------------------------------------------------
65    /// Returns a shared pointer to the breakpoint location with id
66    /// \a breakID, const version.
67    ///
68    /// @param[in] breakID
69    ///     The breakpoint location ID to seek for.
70    ///
71    /// @result
72    ///     A shared pointer to the breakpoint.  May contain a NULL
73    ///     pointer if the breakpoint doesn't exist.
74    //------------------------------------------------------------------
75    lldb::BreakpointLocationSP
76    FindByID (lldb::break_id_t breakID) const;
77
78    //------------------------------------------------------------------
79    /// Returns the breakpoint location id to the breakpoint location
80    /// at address \a addr.
81    ///
82    /// @param[in] addr
83    ///     The address to match.
84    ///
85    /// @result
86    ///     The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
87    //------------------------------------------------------------------
88    lldb::break_id_t
89    FindIDByAddress (const Address &addr);
90
91    //------------------------------------------------------------------
92    /// Returns a breakpoint location list of the breakpoint locations
93    /// in the module \a module.  This list is allocated, and owned by
94    /// the caller.
95    ///
96    /// @param[in] module
97    ///     The module to seek in.
98    ///
99    /// @param[in]
100    ///     A breakpoint collection that gets any breakpoint locations
101    ///     that match \a module appended to.
102    ///
103    /// @result
104    ///     The number of matches
105    //------------------------------------------------------------------
106    size_t
107    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 NULL
119    ///     pointer if the breakpoint doesn't exist.
120    //------------------------------------------------------------------
121    lldb::BreakpointLocationSP
122    GetByIndex (uint32_t i);
123
124    //------------------------------------------------------------------
125    /// Returns a shared pointer to the breakpoint location with index
126    /// \a i, const version.
127    ///
128    /// @param[in] i
129    ///     The breakpoint location index to seek for.
130    ///
131    /// @result
132    ///     A shared pointer to the breakpoint.  May contain a NULL
133    ///     pointer if the breakpoint doesn't exist.
134    //------------------------------------------------------------------
135    const lldb::BreakpointLocationSP
136    GetByIndex (uint32_t i) const;
137
138    //------------------------------------------------------------------
139    /// Removes all the locations in this list from their breakpoint site
140    /// owners list.
141    //------------------------------------------------------------------
142    void
143    ClearAllBreakpointSites ();
144
145    //------------------------------------------------------------------
146    /// Tells all the breakopint locations in this list to attempt to
147    /// resolve any possible breakpoint sites.
148    //------------------------------------------------------------------
149    void
150    ResolveAllBreakpointSites ();
151
152    //------------------------------------------------------------------
153    /// Returns the number of breakpoint locations in this list with
154    /// resolved breakpoints.
155    ///
156    /// @result
157    ///     Number of qualifying breakpoint locations.
158    //------------------------------------------------------------------
159    size_t
160    GetNumResolvedLocations() const;
161
162    //------------------------------------------------------------------
163    /// Returns the number hit count of all locations in this list.
164    ///
165    /// @result
166    ///     Hit count of all locations in this list.
167    //------------------------------------------------------------------
168    uint32_t
169    GetHitCount () const;
170
171    //------------------------------------------------------------------
172    /// Enquires of the breakpoint location in this list with ID \a
173    /// breakID whether we should stop.
174    ///
175    /// @param[in] context
176    ///     This contains the information about this stop.
177    ///
178    /// @param[in] breakID
179    ///     This break ID that we hit.
180    ///
181    /// @return
182    ///     \b true if we should stop, \b false otherwise.
183    //------------------------------------------------------------------
184    bool
185    ShouldStop (StoppointCallbackContext *context,
186                lldb::break_id_t breakID);
187
188    //------------------------------------------------------------------
189    /// Returns the number of elements in this breakpoint location list.
190    ///
191    /// @result
192    ///     The number of elements.
193    //------------------------------------------------------------------
194    size_t
195    GetSize() const
196    {
197        return m_locations.size();
198    }
199
200    //------------------------------------------------------------------
201    /// Print a description of the breakpoint locations in this list to
202    /// the stream \a s.
203    ///
204    /// @param[in] s
205    ///     The stream to which to print the description.
206    ///
207    /// @param[in] level
208    ///     The description level that indicates the detail level to
209    ///     provide.
210    ///
211    /// @see lldb::DescriptionLevel
212    //------------------------------------------------------------------
213    void
214    GetDescription (Stream *s,
215                    lldb::DescriptionLevel level);
216
217protected:
218
219    //------------------------------------------------------------------
220    /// This is the standard constructor.
221    ///
222    /// It creates an empty breakpoint location list. It is protected
223    /// here because only Breakpoints are allowed to create the
224    /// breakpoint location list.
225    //------------------------------------------------------------------
226    BreakpointLocationList(Breakpoint &owner);
227
228    //------------------------------------------------------------------
229    /// Add the breakpoint \a bp_loc_sp to the list.
230    ///
231    /// @param[in] bp_sp
232    ///     Shared pointer to the breakpoint location that will get
233    ///     added to the list.
234    ///
235    /// @result
236    ///     Returns breakpoint location id.
237    //------------------------------------------------------------------
238    lldb::BreakpointLocationSP
239    Create (const Address &addr);
240
241    void
242    StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
243
244    void
245    StopRecordingNewLocations();
246
247    lldb::BreakpointLocationSP
248    AddLocation (const Address &addr,
249                 bool *new_location = NULL);
250
251    bool
252    RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp);
253
254    typedef std::vector<lldb::BreakpointLocationSP> collection;
255    typedef std::map<lldb_private::Address,
256                     lldb::BreakpointLocationSP,
257                     Address::ModulePointerAndOffsetLessThanFunctionObject> addr_map;
258
259    Breakpoint &m_owner;
260    collection m_locations;
261    addr_map m_address_to_location;
262    mutable Mutex m_mutex;
263    lldb::break_id_t m_next_id;
264    BreakpointLocationCollection *m_new_location_recorder;
265};
266
267} // namespace lldb_private
268
269#endif  // liblldb_BreakpointLocationList_h_
270