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