LLDB  mainline
BreakpointSiteList.h
Go to the documentation of this file.
1 //===-- BreakpointSiteList.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_BREAKPOINTSITELIST_H
10 #define LLDB_BREAKPOINT_BREAKPOINTSITELIST_H
11 
12 #include <functional>
13 #include <map>
14 #include <mutex>
15 
17 
18 namespace lldb_private {
19 
20 /// \class BreakpointSiteList BreakpointSiteList.h
21 /// "lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of
22 /// BreakpointSite shared pointers.
24  // At present Process directly accesses the map of BreakpointSites so it can
25  // do quick lookups into the map (using GetMap).
26  // FIXME: Find a better interface for this.
27  friend class Process;
28 
29 public:
30  /// Default constructor makes an empty list.
32 
33  /// Destructor, currently does nothing.
35 
36  /// Add a BreakpointSite to the list.
37  ///
38  /// \param[in] bp_site_sp
39  /// A shared pointer to a breakpoint site being added to the list.
40  ///
41  /// \return
42  /// The ID of the BreakpointSite in the list.
43  lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp);
44 
45  /// Standard Dump routine, doesn't do anything at present. \param[in] s
46  /// Stream into which to dump the description.
47  void Dump(Stream *s) const;
48 
49  /// Returns a shared pointer to the breakpoint site at address \a addr.
50  ///
51  /// \param[in] addr
52  /// The address to look for.
53  ///
54  /// \result
55  /// A shared pointer to the breakpoint site. May contain a NULL
56  /// pointer if no breakpoint site exists with a matching address.
57  lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr);
58 
59  /// Returns a shared pointer to the breakpoint site with id \a breakID.
60  ///
61  /// \param[in] breakID
62  /// The breakpoint site ID to seek for.
63  ///
64  /// \result
65  /// A shared pointer to the breakpoint site. May contain a NULL pointer if
66  /// the
67  /// breakpoint doesn't exist.
68  lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
69 
70  /// Returns a shared pointer to the breakpoint site with id \a breakID -
71  /// const version.
72  ///
73  /// \param[in] breakID
74  /// The breakpoint site ID to seek for.
75  ///
76  /// \result
77  /// A shared pointer to the breakpoint site. May contain a NULL pointer if
78  /// the
79  /// breakpoint doesn't exist.
80  const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
81 
82  /// Returns the breakpoint site id to the breakpoint site at address \a
83  /// addr.
84  ///
85  /// \param[in] addr
86  /// The address to match.
87  ///
88  /// \result
89  /// The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
91 
92  /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
93  // as one of its owners.
94  ///
95  /// \param[in] bp_site_id
96  /// The breakpoint site id to query.
97  ///
98  /// \param[in] bp_id
99  /// The breakpoint id to look for in \a bp_site_id.
100  ///
101  /// \result
102  /// True if \a bp_site_id exists in the site list AND \a bp_id is one of the
103  /// owners of that site.
105  lldb::break_id_t bp_id);
106 
107  void ForEach(std::function<void(BreakpointSite *)> const &callback);
108 
109  /// Removes the breakpoint site given by \b breakID from this list.
110  ///
111  /// \param[in] breakID
112  /// The breakpoint site index to remove.
113  ///
114  /// \result
115  /// \b true if the breakpoint site \a breakID was in the list.
116  bool Remove(lldb::break_id_t breakID);
117 
118  /// Removes the breakpoint site at address \a addr from this list.
119  ///
120  /// \param[in] addr
121  /// The address from which to remove a breakpoint site.
122  ///
123  /// \result
124  /// \b true if \a addr had a breakpoint site to remove from the list.
125  bool RemoveByAddress(lldb::addr_t addr);
126 
127  bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
128  BreakpointSiteList &bp_site_list) const;
129 
130  typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
131  void *baton);
132 
133  /// Enquires of the breakpoint site on in this list with ID \a breakID
134  /// whether we should stop for the breakpoint or not.
135  ///
136  /// \param[in] context
137  /// This contains the information about this stop.
138  ///
139  /// \param[in] breakID
140  /// This break ID that we hit.
141  ///
142  /// \return
143  /// \b true if we should stop, \b false otherwise.
144  bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
145 
146  /// Returns the number of elements in the list.
147  ///
148  /// \result
149  /// The number of elements.
150  size_t GetSize() const {
151  std::lock_guard<std::recursive_mutex> guard(m_mutex);
152  return m_bp_site_list.size();
153  }
154 
155  bool IsEmpty() const {
156  std::lock_guard<std::recursive_mutex> guard(m_mutex);
157  return m_bp_site_list.empty();
158  }
159 
160 protected:
161  typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
162 
163  collection::iterator GetIDIterator(lldb::break_id_t breakID);
164 
165  collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
166 
167  mutable std::recursive_mutex m_mutex;
168  collection m_bp_site_list; // The breakpoint site list.
169 };
170 
171 } // namespace lldb_private
172 
173 #endif // LLDB_BREAKPOINT_BREAKPOINTSITELIST_H
lldb_private::StoppointCallbackContext
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
Definition: StoppointCallbackContext.h:26
lldb_private::BreakpointSiteList::FindIDByAddress
lldb::break_id_t FindIDByAddress(lldb::addr_t addr)
Returns the breakpoint site id to the breakpoint site at address addr.
Definition: BreakpointSiteList.cpp:50
lldb_private::Process
Definition: Process.h:342
lldb_private::BreakpointSiteList::BreakpointSiteContainsBreakpoint
bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id, lldb::break_id_t bp_id)
Returns whether the breakpoint site bp_site_id has bp_id.
Definition: BreakpointSiteList.cpp:141
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::BreakpointSiteList::FindInRange
bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound, BreakpointSiteList &bp_site_list) const
Definition: BreakpointSiteList.cpp:171
lldb_private::BreakpointSiteList::IsEmpty
bool IsEmpty() const
Definition: BreakpointSiteList.h:155
lldb_private::BreakpointSiteList::m_bp_site_list
collection m_bp_site_list
Definition: BreakpointSiteList.h:168
lldb_private::BreakpointSiteList::~BreakpointSiteList
~BreakpointSiteList()
Destructor, currently does nothing.
lldb_private::BreakpointSiteList::Remove
bool Remove(lldb::break_id_t breakID)
Removes the breakpoint site given by breakID from this list.
Definition: BreakpointSiteList.cpp:63
lldb_private::BreakpointSiteList::FindByAddress
lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr)
Returns a shared pointer to the breakpoint site at address addr.
Definition: BreakpointSiteList.cpp:132
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb_private::BreakpointSiteList::FindByID
lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID)
Returns a shared pointer to the breakpoint site with id breakID.
Definition: BreakpointSiteList.cpp:111
lldb_private::BreakpointSiteList::RemoveByAddress
bool RemoveByAddress(lldb::addr_t addr)
Removes the breakpoint site at address addr from this list.
Definition: BreakpointSiteList.cpp:73
lldb_private::BreakpointSiteList::ShouldStop
bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID)
Enquires of the breakpoint site on in this list with ID breakID whether we should stop for the breakp...
Definition: BreakpointSiteList.cpp:37
lldb_private::BreakpointSiteList::BreakpointSiteList
BreakpointSiteList()
Default constructor makes an empty list.
Definition: BreakpointSiteList.cpp:17
lldb_private::BreakpointSiteList::m_mutex
std::recursive_mutex m_mutex
Definition: BreakpointSiteList.h:167
lldb_private::BreakpointSiteList::Dump
void Dump(Stream *s) const
Standard Dump routine, doesn't do anything at present.
Definition: BreakpointSiteList.cpp:151
lldb_private::BreakpointSiteList::GetIDIterator
collection::iterator GetIDIterator(lldb::break_id_t breakID)
Definition: BreakpointSiteList.cpp:96
lldb_private::BreakpointSiteList::Add
lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp)
Add a BreakpointSite to the list.
Definition: BreakpointSiteList.cpp:24
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::BreakpointSiteList::ForEach
void ForEach(std::function< void(BreakpointSite *)> const &callback)
Definition: BreakpointSiteList.cpp:164
BreakpointSite.h
lldb_private::BreakpointSiteList::GetIDConstIterator
collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const
Definition: BreakpointSiteList.cpp:104
lldb_private::BreakpointSiteList
Definition: BreakpointSiteList.h:23
lldb_private::BreakpointSiteList::GetSize
size_t GetSize() const
Returns the number of elements in the list.
Definition: BreakpointSiteList.h:150
lldb_private::BreakpointSiteList::BreakpointSiteSPMapFunc
void(* BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp, void *baton)
Definition: BreakpointSiteList.h:130
lldb_private::BreakpointSiteList::collection
std::map< lldb::addr_t, lldb::BreakpointSiteSP > collection
Definition: BreakpointSiteList.h:161