1 //===-- BreakpointLocationCollection.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_BreakpointLocationCollection_h_
11 #define liblldb_BreakpointLocationCollection_h_
12 
13 #include <mutex>
14 #include <vector>
15 
16 #include "lldb/Utility/Iterable.h"
17 #include "lldb/lldb-private.h"
18 
19 namespace lldb_private {
20 
21 class BreakpointLocationCollection {
22 public:
23   BreakpointLocationCollection();
24 
25   ~BreakpointLocationCollection();
26 
27   //------------------------------------------------------------------
28   /// Add the breakpoint \a bp_loc_sp to the list.
29   ///
30   /// @param[in] bp_sp
31   ///     Shared pointer to the breakpoint location that will get added
32   ///     to the list.
33   ///
34   /// @result
35   ///     Returns breakpoint location id.
36   //------------------------------------------------------------------
37   void Add(const lldb::BreakpointLocationSP &bp_loc_sp);
38 
39   //------------------------------------------------------------------
40   /// Removes the breakpoint location given by \b breakID from this
41   /// list.
42   ///
43   /// @param[in] break_id
44   ///     The breakpoint index to remove.
45   ///
46   /// @param[in] break_loc_id
47   ///     The breakpoint location index in break_id to remove.
48   ///
49   /// @result
50   ///     \b true if the breakpoint was in the list.
51   //------------------------------------------------------------------
52   bool Remove(lldb::break_id_t break_id, lldb::break_id_t break_loc_id);
53 
54   //------------------------------------------------------------------
55   /// Returns a shared pointer to the breakpoint location with id \a
56   /// breakID.
57   ///
58   /// @param[in] break_id
59   ///     The breakpoint  ID to seek for.
60   ///
61   /// @param[in] break_loc_id
62   ///     The breakpoint location ID in \a break_id to seek for.
63   ///
64   /// @result
65   ///     A shared pointer to the breakpoint.  May contain a NULL
66   ///     pointer if the breakpoint doesn't exist.
67   //------------------------------------------------------------------
68   lldb::BreakpointLocationSP FindByIDPair(lldb::break_id_t break_id,
69                                           lldb::break_id_t break_loc_id);
70 
71   //------------------------------------------------------------------
72   /// Returns a shared pointer to the breakpoint location with id \a
73   /// breakID, const version.
74   ///
75   /// @param[in] breakID
76   ///     The breakpoint location ID to seek for.
77   ///
78   /// @param[in] break_loc_id
79   ///     The breakpoint location ID in \a break_id to seek for.
80   ///
81   /// @result
82   ///     A shared pointer to the breakpoint.  May contain a NULL
83   ///     pointer if the breakpoint doesn't exist.
84   //------------------------------------------------------------------
85   const lldb::BreakpointLocationSP
86   FindByIDPair(lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const;
87 
88   //------------------------------------------------------------------
89   /// Returns a shared pointer to the breakpoint location with index
90   /// \a i.
91   ///
92   /// @param[in] i
93   ///     The breakpoint location index to seek for.
94   ///
95   /// @result
96   ///     A shared pointer to the breakpoint.  May contain a NULL
97   ///     pointer if the breakpoint doesn't exist.
98   //------------------------------------------------------------------
99   lldb::BreakpointLocationSP GetByIndex(size_t i);
100 
101   //------------------------------------------------------------------
102   /// Returns a shared pointer to the breakpoint location with index
103   /// \a i, const version.
104   ///
105   /// @param[in] i
106   ///     The breakpoint location index to seek for.
107   ///
108   /// @result
109   ///     A shared pointer to the breakpoint.  May contain a NULL
110   ///     pointer if the breakpoint doesn't exist.
111   //------------------------------------------------------------------
112   const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
113 
114   //------------------------------------------------------------------
115   /// Returns the number of elements in this breakpoint location list.
116   ///
117   /// @result
118   ///     The number of elements.
119   //------------------------------------------------------------------
GetSize()120   size_t GetSize() const { return m_break_loc_collection.size(); }
121 
122   //------------------------------------------------------------------
123   /// Enquires of all the breakpoint locations in this list whether
124   /// we should stop at a hit at \a breakID.
125   ///
126   /// @param[in] context
127   ///    This contains the information about this stop.
128   ///
129   /// @param[in] breakID
130   ///    This break ID that we hit.
131   ///
132   /// @return
133   ///    \b true if we should stop, \b false otherwise.
134   //------------------------------------------------------------------
135   bool ShouldStop(StoppointCallbackContext *context);
136 
137   //------------------------------------------------------------------
138   /// Print a description of the breakpoint locations in this list
139   /// to the stream \a s.
140   ///
141   /// @param[in] s
142   ///     The stream to which to print the description.
143   ///
144   /// @param[in] level
145   ///     The description level that indicates the detail level to
146   ///     provide.
147   ///
148   /// @see lldb::DescriptionLevel
149   //------------------------------------------------------------------
150   void GetDescription(Stream *s, lldb::DescriptionLevel level);
151 
152   //------------------------------------------------------------------
153   /// Check whether this collection of breakpoint locations have any
154   /// thread specifiers, and if yes, is \a thread_id contained in any
155   /// of these specifiers.
156   ///
157   /// @param[in] thread
158   ///     The thread against which to test.
159   ///
160   /// return
161   ///     \b true if the collection contains at least one location that
162   ///     would be valid for this thread, false otherwise.
163   //------------------------------------------------------------------
164   bool ValidForThisThread(Thread *thread);
165 
166   //------------------------------------------------------------------
167   /// Tell whether ALL the breakpoints in the location collection are internal.
168   ///
169   /// @result
170   ///     \b true if all breakpoint locations are owned by internal breakpoints,
171   ///     \b false otherwise.
172   //------------------------------------------------------------------
173   bool IsInternal() const;
174 
175 protected:
176   //------------------------------------------------------------------
177   // Classes that inherit from BreakpointLocationCollection can see and modify
178   // these
179   //------------------------------------------------------------------
180 
181 private:
182   //------------------------------------------------------------------
183   // For BreakpointLocationCollection only
184   //------------------------------------------------------------------
185 
186   typedef std::vector<lldb::BreakpointLocationSP> collection;
187 
188   collection::iterator GetIDPairIterator(lldb::break_id_t break_id,
189                                          lldb::break_id_t break_loc_id);
190 
191   collection::const_iterator
192   GetIDPairConstIterator(lldb::break_id_t break_id,
193                          lldb::break_id_t break_loc_id) const;
194 
195   collection m_break_loc_collection;
196   mutable std::mutex m_collection_mutex;
197 
198 public:
199   typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
200                           vector_adapter>
201       BreakpointLocationCollectionIterable;
BreakpointLocations()202   BreakpointLocationCollectionIterable BreakpointLocations() {
203     return BreakpointLocationCollectionIterable(m_break_loc_collection);
204   }
205 };
206 
207 } // namespace lldb_private
208 
209 #endif // liblldb_BreakpointLocationCollection_h_
210