]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointList.h
Copy ^/vendor/NetBSD/tests/dist/lib/libc/hash/t_hmac.c to
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Breakpoint / BreakpointList.h
1 //===-- BreakpointList.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_BreakpointList_h_
11 #define liblldb_BreakpointList_h_
12
13 // C Includes
14 // C++ Includes
15 #include <list>
16 #include <mutex>
17
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/Breakpoint/Breakpoint.h"
21
22 namespace lldb_private {
23
24 //----------------------------------------------------------------------
25 /// @class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
26 /// @brief This class manages a list of breakpoints.
27 //----------------------------------------------------------------------
28
29 //----------------------------------------------------------------------
30 /// General Outline:
31 /// Allows adding and removing breakpoints and find by ID and index.
32 //----------------------------------------------------------------------
33
34 class BreakpointList
35 {
36 public:
37     BreakpointList (bool is_internal);
38
39     ~BreakpointList();
40
41     //------------------------------------------------------------------
42     /// Add the breakpoint \a bp_sp to the list.
43     ///
44     /// @param[in] bp_sp
45     ///   Shared pointer to the breakpoint that will get added to the list.
46     ///
47     /// @result
48     ///   Returns breakpoint id.
49     //------------------------------------------------------------------
50     lldb::break_id_t
51     Add (lldb::BreakpointSP& bp_sp, bool notify);
52
53     //------------------------------------------------------------------
54     /// Standard "Dump" method.  At present it does nothing.
55     //------------------------------------------------------------------
56     void
57     Dump (Stream *s) const;
58
59     //------------------------------------------------------------------
60     /// Returns a shared pointer to the breakpoint with id \a breakID.
61     ///
62     /// @param[in] breakID
63     ///   The breakpoint ID to seek for.
64     ///
65     /// @result
66     ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
67     ///   breakpoint doesn't exist.
68     //------------------------------------------------------------------
69     lldb::BreakpointSP
70     FindBreakpointByID (lldb::break_id_t breakID);
71
72     //------------------------------------------------------------------
73     /// Returns a shared pointer to the breakpoint with id \a breakID.  Const version.
74     ///
75     /// @param[in] breakID
76     ///   The breakpoint ID to seek for.
77     ///
78     /// @result
79     ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
80     ///   breakpoint doesn't exist.
81     //------------------------------------------------------------------
82     const lldb::BreakpointSP
83     FindBreakpointByID (lldb::break_id_t breakID) const;
84
85     //------------------------------------------------------------------
86     /// Returns a shared pointer to the breakpoint with index \a i.
87     ///
88     /// @param[in] i
89     ///   The breakpoint index to seek for.
90     ///
91     /// @result
92     ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
93     ///   breakpoint doesn't exist.
94     //------------------------------------------------------------------
95     lldb::BreakpointSP
96     GetBreakpointAtIndex (size_t i);
97
98     //------------------------------------------------------------------
99     /// Returns a shared pointer to the breakpoint with index \a i, const version
100     ///
101     /// @param[in] i
102     ///   The breakpoint index to seek for.
103     ///
104     /// @result
105     ///   A shared pointer to the breakpoint.  May contain a NULL pointer if the
106     ///   breakpoint doesn't exist.
107     //------------------------------------------------------------------
108     const lldb::BreakpointSP
109     GetBreakpointAtIndex (size_t i) const;
110
111     //------------------------------------------------------------------
112     /// Returns the number of elements in this breakpoint list.
113     ///
114     /// @result
115     ///   The number of elements.
116     //------------------------------------------------------------------
117     size_t
118     GetSize() const 
119     {
120         std::lock_guard<std::recursive_mutex> guard(m_mutex);
121         return m_breakpoints.size(); 
122     }
123
124     //------------------------------------------------------------------
125     /// Removes the breakpoint given by \b breakID from this list.
126     ///
127     /// @param[in] breakID
128     ///   The breakpoint index to remove.
129     ///
130     /// @result
131     ///   \b true if the breakpoint \a breakID was in the list.
132     //------------------------------------------------------------------
133     bool
134     Remove (lldb::break_id_t breakID, bool notify);
135
136     
137     //------------------------------------------------------------------
138     /// Removes all invalid breakpoint locations.
139     ///
140     /// Removes all breakpoint locations in the list with architectures
141     /// that aren't compatible with \a arch. Also remove any breakpoint
142     /// locations with whose locations have address where the section
143     /// has been deleted (module and object files no longer exist).
144     ///
145     /// This is typically used after the process calls exec, or anytime
146     /// the architecture of the target changes.
147     ///
148     /// @param[in] arch
149     ///     If valid, check the module in each breakpoint to make sure
150     ///     they are compatible, otherwise, ignore architecture.
151     //------------------------------------------------------------------
152     void
153     RemoveInvalidLocations (const ArchSpec &arch);
154
155     void
156     SetEnabledAll (bool enabled);
157
158     //------------------------------------------------------------------
159     /// Removes all the breakpoints from this list.
160     //------------------------------------------------------------------
161     void
162     RemoveAll (bool notify);
163
164     //------------------------------------------------------------------
165     /// Tell all the breakpoints to update themselves due to a change in the
166     /// modules in \a module_list.  \a added says whether the module was loaded
167     /// or unloaded.
168     ///
169     /// @param[in] module_list
170     ///   The module list that has changed.
171     ///
172     /// @param[in] load
173     ///   \b true if the modules are loaded, \b false if unloaded.
174     ///
175     /// @param[in] delete_locations
176     ///   If \a load is \b false, then delete breakpoint locations when
177     ///   when updating breakpoints.
178     //------------------------------------------------------------------
179     void
180     UpdateBreakpoints (ModuleList &module_list,
181                        bool load,
182                        bool delete_locations);
183     
184     void
185     UpdateBreakpointsWhenModuleIsReplaced (lldb::ModuleSP old_module_sp, lldb::ModuleSP new_module_sp);
186
187     void
188     ClearAllBreakpointSites ();
189     
190     //------------------------------------------------------------------
191     /// Sets the passed in Locker to hold the Breakpoint List mutex.
192     ///
193     /// @param[in] locker
194     ///   The locker object that is set.
195     //------------------------------------------------------------------
196     void
197     GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
198
199 protected:
200     typedef std::list<lldb::BreakpointSP> bp_collection;
201
202     bp_collection::iterator
203     GetBreakpointIDIterator(lldb::break_id_t breakID);
204
205     bp_collection::const_iterator
206     GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
207
208     std::recursive_mutex &
209     GetMutex() const
210     {
211         return m_mutex;
212     }
213
214     mutable std::recursive_mutex m_mutex;
215     bp_collection m_breakpoints;  // The breakpoint list, currently a list.
216     lldb::break_id_t m_next_break_id;
217     bool m_is_internal;
218
219 public:
220     typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP, list_adapter, std::recursive_mutex>
221         BreakpointIterable;
222     BreakpointIterable
223     Breakpoints()
224     {
225         return BreakpointIterable(m_breakpoints, GetMutex());
226     }
227
228 private:
229     DISALLOW_COPY_AND_ASSIGN (BreakpointList);
230 };
231
232 } // namespace lldb_private
233
234 #endif  // liblldb_BreakpointList_h_