LLDB  mainline
BreakpointLocationList.h
Go to the documentation of this file.
1 //===-- BreakpointLocationList.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_BREAKPOINTLOCATIONLIST_H
10 #define LLDB_BREAKPOINT_BREAKPOINTLOCATIONLIST_H
11 
12 #include <map>
13 #include <mutex>
14 #include <vector>
15 
16 #include "lldb/Core/Address.h"
17 #include "lldb/Utility/Iterable.h"
18 #include "lldb/lldb-private.h"
19 
20 namespace lldb_private {
21 
22 /// \class BreakpointLocationList BreakpointLocationList.h
23 /// "lldb/Breakpoint/BreakpointLocationList.h" This class is used by
24 /// Breakpoint to manage a list of breakpoint locations, each breakpoint
25 /// location in the list has a unique ID, and is unique by Address as well.
27  // Only Breakpoints can make the location list, or add elements to it. This
28  // is not just some random collection of locations. Rather, the act of
29  // adding the location to this list sets its ID, and implicitly all the
30  // locations have the same breakpoint ID as well. If you need a generic
31  // container for breakpoint locations, use BreakpointLocationCollection.
32  friend class Breakpoint;
33 
34 public:
35  virtual ~BreakpointLocationList();
36 
37  /// Standard "Dump" method. At present it does nothing.
38  void Dump(Stream *s) const;
39 
40  /// Returns a shared pointer to the breakpoint location at address \a addr -
41  /// const version.
42  ///
43  /// \param[in] addr
44  /// The address to look for.
45  ///
46  /// \result
47  /// A shared pointer to the breakpoint. May contain a nullptr
48  /// pointer if the breakpoint doesn't exist.
49  const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;
50 
51  /// Returns a shared pointer to the breakpoint location with id \a breakID,
52  /// const version.
53  ///
54  /// \param[in] breakID
55  /// The breakpoint location ID to seek for.
56  ///
57  /// \result
58  /// A shared pointer to the breakpoint. May contain a nullptr
59  /// pointer if the breakpoint doesn't exist.
60  lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const;
61 
62  /// Returns the breakpoint location id to the breakpoint location at address
63  /// \a addr.
64  ///
65  /// \param[in] addr
66  /// The address to match.
67  ///
68  /// \result
69  /// The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
71 
72  /// Returns a breakpoint location list of the breakpoint locations in the
73  /// module \a module. This list is allocated, and owned by the caller.
74  ///
75  /// \param[in] module
76  /// The module to seek in.
77  ///
78  /// \param[in] bp_loc_list
79  /// A breakpoint collection that gets any breakpoint locations
80  /// that match \a module appended to.
81  ///
82  /// \result
83  /// The number of matches
84  size_t FindInModule(Module *module,
85  BreakpointLocationCollection &bp_loc_list);
86 
87  /// Returns a shared pointer to the breakpoint location with index \a i.
88  ///
89  /// \param[in] i
90  /// The breakpoint location index to seek for.
91  ///
92  /// \result
93  /// A shared pointer to the breakpoint. May contain a nullptr
94  /// pointer if the breakpoint doesn't exist.
95  lldb::BreakpointLocationSP GetByIndex(size_t i);
96 
97  /// Returns a shared pointer to the breakpoint location with index \a i,
98  /// const version.
99  ///
100  /// \param[in] i
101  /// The breakpoint location index to seek for.
102  ///
103  /// \result
104  /// A shared pointer to the breakpoint. May contain a nullptr
105  /// pointer if the breakpoint doesn't exist.
106  const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
107 
108  /// Removes all the locations in this list from their breakpoint site owners
109  /// list.
111 
112  /// Tells all the breakpoint locations in this list to attempt to resolve
113  /// any possible breakpoint sites.
115 
116  /// Returns the number of breakpoint locations in this list with resolved
117  /// breakpoints.
118  ///
119  /// \result
120  /// Number of qualifying breakpoint locations.
121  size_t GetNumResolvedLocations() const;
122 
123  /// Returns the number hit count of all locations in this list.
124  ///
125  /// \result
126  /// Hit count of all locations in this list.
127  uint32_t GetHitCount() const;
128 
129  /// Enquires of the breakpoint location in this list with ID \a breakID
130  /// whether we should stop.
131  ///
132  /// \param[in] context
133  /// This contains the information about this stop.
134  ///
135  /// \param[in] breakID
136  /// This break ID that we hit.
137  ///
138  /// \return
139  /// \b true if we should stop, \b false otherwise.
140  bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
141 
142  /// Returns the number of elements in this breakpoint location list.
143  ///
144  /// \result
145  /// The number of elements.
146  size_t GetSize() const { return m_locations.size(); }
147 
148  /// Print a description of the breakpoint locations in this list to the
149  /// stream \a s.
150  ///
151  /// \param[in] s
152  /// The stream to which to print the description.
153  ///
154  /// \param[in] level
155  /// The description level that indicates the detail level to
156  /// provide.
157  ///
158  /// \see lldb::DescriptionLevel
160 
161 protected:
162  /// This is the standard constructor.
163  ///
164  /// It creates an empty breakpoint location list. It is protected here
165  /// because only Breakpoints are allowed to create the breakpoint location
166  /// list.
168 
169  lldb::BreakpointLocationSP Create(const Address &addr,
170  bool resolve_indirect_symbols);
171 
173 
175 
176  lldb::BreakpointLocationSP AddLocation(const Address &addr,
177  bool resolve_indirect_symbols,
178  bool *new_location = nullptr);
179 
180  void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
181  lldb::BreakpointLocationSP from_location_sp);
182 
183  bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
184 
185  void RemoveLocationByIndex(size_t idx);
186 
187  void RemoveInvalidLocations(const ArchSpec &arch);
188 
189  void Compact();
190 
191  typedef std::vector<lldb::BreakpointLocationSP> collection;
192  typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
195 
197  collection m_locations; // Vector of locations, sorted by ID
199  mutable std::recursive_mutex m_mutex;
202 
203 public:
204  typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
207 
210  }
211 };
212 
213 } // namespace lldb_private
214 
215 #endif // LLDB_BREAKPOINT_BREAKPOINTLOCATIONLIST_H
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::BreakpointLocationList::m_locations
collection m_locations
Definition: BreakpointLocationList.h:197
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::BreakpointLocationList::ResolveAllBreakpointSites
void ResolveAllBreakpointSites()
Tells all the breakpoint locations in this list to attempt to resolve any possible breakpoint sites.
Definition: BreakpointLocationList.cpp:161
lldb_private::BreakpointLocationList::Create
lldb::BreakpointLocationSP Create(const Address &addr, bool resolve_indirect_symbols)
Definition: BreakpointLocationList.cpp:29
lldb_private::BreakpointLocationList::ShouldStop
bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID)
Enquires of the breakpoint location in this list with ID breakID whether we should stop.
Definition: BreakpointLocationList.cpp:42
lldb_private::BreakpointLocationList::m_next_id
lldb::break_id_t m_next_id
Definition: BreakpointLocationList.h:200
lldb_private::BreakpointLocationList::StartRecordingNewLocations
void StartRecordingNewLocations(BreakpointLocationCollection &new_locations)
Definition: BreakpointLocationList.cpp:291
lldb_private::vector_adapter
E vector_adapter(I &iter)
Definition: Iterable.h:21
lldb_private::Module
Definition: Module.h:85
lldb_private::BreakpointLocationList::collection
std::vector< lldb::BreakpointLocationSP > collection
Definition: BreakpointLocationList.h:191
lldb_private::AdaptedIterable
Definition: Iterable.h:153
lldb_private::Stream
Definition: Stream.h:28
lldb_private::BreakpointLocationList::m_address_to_location
addr_map m_address_to_location
Definition: BreakpointLocationList.h:198
lldb_private::BreakpointLocationList::RemoveLocation
bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp)
Definition: BreakpointLocationList.cpp:237
lldb_private::BreakpointLocationList::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Print a description of the breakpoint locations in this list to the stream s.
Definition: BreakpointLocationList.cpp:191
lldb_private::BreakpointLocationList::AddLocation
lldb::BreakpointLocationSP AddLocation(const Address &addr, bool resolve_indirect_symbols, bool *new_location=nullptr)
Definition: BreakpointLocationList.cpp:202
lldb_private::BreakpointLocationList::BreakpointLocationIterable
AdaptedIterable< collection, lldb::BreakpointLocationSP, vector_adapter > BreakpointLocationIterable
Definition: BreakpointLocationList.h:206
lldb_private::BreakpointLocationList::SwapLocation
void SwapLocation(lldb::BreakpointLocationSP to_location_sp, lldb::BreakpointLocationSP from_location_sp)
Definition: BreakpointLocationList.cpp:224
lldb_private::BreakpointLocationList::RemoveLocationByIndex
void RemoveLocationByIndex(size_t idx)
Definition: BreakpointLocationList.cpp:255
lldb_private::BreakpointLocationList::addr_map
std::map< lldb_private::Address, lldb::BreakpointLocationSP, Address::ModulePointerAndOffsetLessThanFunctionObject > addr_map
Definition: BreakpointLocationList.h:194
lldb_private::BreakpointLocationList::GetSize
size_t GetSize() const
Returns the number of elements in this breakpoint location list.
Definition: BreakpointLocationList.h:146
lldb_private::BreakpointLocationList::m_new_location_recorder
BreakpointLocationCollection * m_new_location_recorder
Definition: BreakpointLocationList.h:201
lldb_private::BreakpointLocationList::StopRecordingNewLocations
void StopRecordingNewLocations()
Definition: BreakpointLocationList.cpp:298
lldb_private::BreakpointLocationList::FindByID
lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const
Returns a shared pointer to the breakpoint location with id breakID, const version.
Definition: BreakpointLocationList.cpp:69
lldb::break_id_t
int32_t break_id_t
Definition: lldb-types.h:88
lldb_private::Address::ModulePointerAndOffsetLessThanFunctionObject
Definition: Address.h:204
lldb_private::BreakpointLocationList::GetHitCount
uint32_t GetHitCount() const
Returns the number hit count of all locations in this list.
Definition: BreakpointLocationList.cpp:171
lldb_private::BreakpointLocationList::m_owner
Breakpoint & m_owner
Definition: BreakpointLocationList.h:196
lldb_private::BreakpointLocationList::Compact
void Compact()
Definition: BreakpointLocationList.cpp:303
lldb_private::BreakpointLocationList::FindIDByAddress
lldb::break_id_t FindIDByAddress(const Address &addr)
Returns the breakpoint location id to the breakpoint location at address addr.
Definition: BreakpointLocationList.cpp:56
Address.h
lldb_private::BreakpointLocationCollection
Definition: BreakpointLocationCollection.h:20
lldb-private.h
Iterable.h
uint32_t
lldb_private::BreakpointLocationList::BreakpointLocations
BreakpointLocationIterable BreakpointLocations()
Definition: BreakpointLocationList.h:208
lldb_private::Address
Definition: Address.h:59
lldb_private::BreakpointLocationList::RemoveInvalidLocations
void RemoveInvalidLocations(const ArchSpec &arch)
Definition: BreakpointLocationList.cpp:261
lldb_private::BreakpointLocationList::GetNumResolvedLocations
size_t GetNumResolvedLocations() const
Returns the number of breakpoint locations in this list with resolved breakpoints.
Definition: BreakpointLocationList.cpp:180
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::BreakpointLocationList::~BreakpointLocationList
virtual ~BreakpointLocationList()
lldb_private::BreakpointLocationList
Definition: BreakpointLocationList.h:26
lldb_private::BreakpointLocationList::ClearAllBreakpointSites
void ClearAllBreakpointSites()
Removes all the locations in this list from their breakpoint site owners list.
Definition: BreakpointLocationList.cpp:154
lldb_private::BreakpointLocationList::m_mutex
std::recursive_mutex m_mutex
Definition: BreakpointLocationList.h:199
lldb_private::BreakpointLocationList::BreakpointLocationList
BreakpointLocationList(Breakpoint &owner)
This is the standard constructor.
Definition: BreakpointLocationList.cpp:22
lldb_private::BreakpointLocationList::Dump
void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
Definition: BreakpointLocationList.cpp:123
lldb_private::BreakpointLocationList::FindInModule
size_t FindInModule(Module *module, BreakpointLocationCollection &bp_loc_list)
Returns a breakpoint location list of the breakpoint locations in the module module.
Definition: BreakpointLocationList.cpp:80
lldb_private::BreakpointLocationList::GetByIndex
lldb::BreakpointLocationSP GetByIndex(size_t i)
Returns a shared pointer to the breakpoint location with index i.
Definition: BreakpointLocationList.cpp:136
lldb_private::BreakpointLocationList::FindByAddress
const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const
Returns a shared pointer to the breakpoint location at address addr - const version.
Definition: BreakpointLocationList.cpp:97
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::Breakpoint
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:80