LLDB  mainline
BreakpointList.h
Go to the documentation of this file.
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 LLDB_BREAKPOINT_BREAKPOINTLIST_H
10 #define LLDB_BREAKPOINT_BREAKPOINTLIST_H
11 
12 #include <list>
13 #include <mutex>
14 
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 
26 public:
27  BreakpointList(bool is_internal);
28 
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  /// error if the input name was not a legal breakpoint name, vector
71  /// of breakpoints otherwise.
72  llvm::Expected<std::vector<lldb::BreakpointSP>>
73  FindBreakpointsByName(const char *name);
74 
75  /// Returns the number of elements in this breakpoint list.
76  ///
77  /// \result
78  /// The number of elements.
79  size_t GetSize() const {
80  std::lock_guard<std::recursive_mutex> guard(m_mutex);
81  return m_breakpoints.size();
82  }
83 
84  /// Removes the breakpoint given by \b breakID from this list.
85  ///
86  /// \param[in] breakID
87  /// The breakpoint index to remove.
88  ///
89  /// \result
90  /// \b true if the breakpoint \a breakID was in the list.
91  bool Remove(lldb::break_id_t breakID, bool notify);
92 
93  /// Removes all invalid breakpoint locations.
94  ///
95  /// Removes all breakpoint locations in the list with architectures that
96  /// aren't compatible with \a arch. Also remove any breakpoint locations
97  /// with whose locations have address where the section has been deleted
98  /// (module and object files no longer exist).
99  ///
100  /// This is typically used after the process calls exec, or anytime the
101  /// architecture of the target changes.
102  ///
103  /// \param[in] arch
104  /// If valid, check the module in each breakpoint to make sure
105  /// they are compatible, otherwise, ignore architecture.
106  void RemoveInvalidLocations(const ArchSpec &arch);
107 
108  void SetEnabledAll(bool enabled);
109 
110  void SetEnabledAllowed(bool enabled);
111 
112  /// Removes all the breakpoints from this list.
113  void RemoveAll(bool notify);
114 
115  /// Removes all the breakpoints from this list - first checking the
116  /// ePermDelete on the breakpoints. This call should be used unless you are
117  /// shutting down and need to actually clear them all.
118  void RemoveAllowed(bool notify);
119 
120  /// Tell all the breakpoints to update themselves due to a change in the
121  /// modules in \a module_list. \a added says whether the module was loaded
122  /// or unloaded.
123  ///
124  /// \param[in] module_list
125  /// The module list that has changed.
126  ///
127  /// \param[in] load
128  /// \b true if the modules are loaded, \b false if unloaded.
129  ///
130  /// \param[in] delete_locations
131  /// If \a load is \b false, then delete breakpoint locations when
132  /// when updating breakpoints.
133  void UpdateBreakpoints(ModuleList &module_list, bool load,
134  bool delete_locations);
135 
136  void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp,
137  lldb::ModuleSP new_module_sp);
138 
140 
141  /// Sets the passed in Locker to hold the Breakpoint List mutex.
142  ///
143  /// \param[in] lock
144  /// The locker object that is set.
145  void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
146 
147 protected:
148  typedef std::vector<lldb::BreakpointSP> bp_collection;
149 
150  bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID);
151 
152  bp_collection::const_iterator
154 
155  std::recursive_mutex &GetMutex() const { return m_mutex; }
156 
157  mutable std::recursive_mutex m_mutex;
161 
162 public:
163  typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
164  list_adapter, std::recursive_mutex>
168  }
169 
170 private:
171  BreakpointList(const BreakpointList &) = delete;
172  const BreakpointList &operator=(const BreakpointList &) = delete;
173 };
174 
175 } // namespace lldb_private
176 
177 #endif // LLDB_BREAKPOINT_BREAKPOINTLIST_H
lldb_private::BreakpointList::RemoveAllowed
void RemoveAllowed(bool notify)
Removes all the breakpoints from this list - first checking the ePermDelete on the breakpoints.
Definition: BreakpointList.cpp:94
lldb_private::BreakpointList::Breakpoints
BreakpointIterable Breakpoints()
Definition: BreakpointList.h:166
lldb_private::BreakpointList
General Outline: Allows adding and removing breakpoints and find by ID and index.
Definition: BreakpointList.h:25
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::BreakpointList::operator=
const BreakpointList & operator=(const BreakpointList &)=delete
lldb_private::BreakpointList::m_mutex
std::recursive_mutex m_mutex
Definition: BreakpointList.h:157
lldb_private::Stream
Definition: Stream.h:28
lldb_private::BreakpointList::m_breakpoints
bp_collection m_breakpoints
Definition: BreakpointList.h:158
lldb_private::list_adapter
E list_adapter(I &iter)
Definition: Iterable.h:23
lldb_private::BreakpointList::UpdateBreakpoints
void UpdateBreakpoints(ModuleList &module_list, bool load, bool delete_locations)
Tell all the breakpoints to update themselves due to a change in the modules in module_list.
Definition: BreakpointList.cpp:172
lldb_private::BreakpointList::BreakpointList
BreakpointList(bool is_internal)
Definition: BreakpointList.cpp:25
lldb_private::LockingAdaptedIterable
Definition: Iterable.h:171
lldb_private::ModuleList
Definition: ModuleList.h:72
lldb_private::BreakpointList::BreakpointIterable
LockingAdaptedIterable< bp_collection, lldb::BreakpointSP, list_adapter, std::recursive_mutex > BreakpointIterable
Definition: BreakpointList.h:165
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb_private::BreakpointList::Add
lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify)
Add the breakpoint bp_sp to the list.
Definition: BreakpointList.cpp:31
lldb_private::BreakpointList::bp_collection
std::vector< lldb::BreakpointSP > bp_collection
Definition: BreakpointList.h:148
lldb_private::BreakpointList::SetEnabledAllowed
void SetEnabledAllowed(bool enabled)
Definition: BreakpointList.cpp:75
lldb_private::BreakpointList::GetListMutex
void GetListMutex(std::unique_lock< std::recursive_mutex > &lock)
Sets the passed in Locker to hold the Breakpoint List mutex.
Definition: BreakpointList.cpp:192
lldb_private::BreakpointList::GetBreakpointAtIndex
lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const
Returns a shared pointer to the breakpoint with index i.
Definition: BreakpointList.cpp:165
lldb_private::BreakpointList::Dump
void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
Definition: BreakpointList.cpp:153
lldb_private::BreakpointList::GetBreakpointIDIterator
bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID)
Definition: BreakpointList.cpp:111
lldb_private::BreakpointList::RemoveInvalidLocations
void RemoveInvalidLocations(const ArchSpec &arch)
Removes all invalid breakpoint locations.
Definition: BreakpointList.cpp:63
lldb_private::BreakpointList::SetEnabledAll
void SetEnabledAll(bool enabled)
Definition: BreakpointList.cpp:69
lldb_private::BreakpointList::GetBreakpointIDConstIterator
bp_collection::const_iterator GetBreakpointIDConstIterator(lldb::break_id_t breakID) const
Definition: BreakpointList.cpp:118
lldb_private::BreakpointList::ClearAllBreakpointSites
void ClearAllBreakpointSites()
Definition: BreakpointList.cpp:186
lldb_private::BreakpointList::GetMutex
std::recursive_mutex & GetMutex() const
Definition: BreakpointList.h:155
lldb_private::BreakpointList::GetSize
size_t GetSize() const
Returns the number of elements in this breakpoint list.
Definition: BreakpointList.h:79
lldb_private::BreakpointList::m_is_internal
bool m_is_internal
Definition: BreakpointList.h:160
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Breakpoint.h
lldb_private::BreakpointList::UpdateBreakpointsWhenModuleIsReplaced
void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp, lldb::ModuleSP new_module_sp)
Definition: BreakpointList.cpp:179
lldb_private::BreakpointList::RemoveAll
void RemoveAll(bool notify)
Removes all the breakpoints from this list.
Definition: BreakpointList.cpp:82
lldb_private::BreakpointList::FindBreakpointsByName
llvm::Expected< std::vector< lldb::BreakpointSP > > FindBreakpointsByName(const char *name)
Find all the breakpoints with a given name.
Definition: BreakpointList.cpp:134
lldb_private::BreakpointList::Remove
bool Remove(lldb::break_id_t breakID, bool notify)
Removes the breakpoint given by breakID from this list.
Definition: BreakpointList.cpp:45
lldb_private::BreakpointList::FindBreakpointByID
lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const
Returns a shared pointer to the breakpoint with id breakID.
Definition: BreakpointList.cpp:124
lldb_private::BreakpointList::m_next_break_id
lldb::break_id_t m_next_break_id
Definition: BreakpointList.h:159
lldb_private::BreakpointList::~BreakpointList
~BreakpointList()