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