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