LLDB mainline
BreakpointSite.h
Go to the documentation of this file.
1//===-- BreakpointSite.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_BREAKPOINTSITE_H
10#define LLDB_BREAKPOINT_BREAKPOINTSITE_H
11
12#include <list>
13#include <mutex>
14
15
19#include "lldb/Utility/UserID.h"
20#include "lldb/lldb-forward.h"
21
22namespace lldb_private {
23
24/// \class BreakpointSite BreakpointSite.h "lldb/Breakpoint/BreakpointSite.h"
25/// Class that manages the actual breakpoint that will be inserted into the
26/// running program.
27///
28/// The BreakpointSite class handles the physical breakpoint that is actually
29/// inserted in the target program. As such, it is also the one that gets
30/// hit, when the program stops. It keeps a list of all BreakpointLocations
31/// that share this physical site. When the breakpoint is hit, all the
32/// locations are informed by the breakpoint site. Breakpoint sites are owned
33/// by the process.
34
35class BreakpointSite : public std::enable_shared_from_this<BreakpointSite>,
36 public StoppointSite {
37public:
38 enum Type {
39 eSoftware, // Breakpoint opcode has been written to memory and
40 // m_saved_opcode
41 // and m_trap_opcode contain the saved and written opcode.
42 eHardware, // Breakpoint site is set as a hardware breakpoint
43 eExternal // Breakpoint site is managed by an external debug nub or
44 // debug interface where memory reads transparently will not
45 // display any breakpoint opcodes.
46 };
47
50
51 ~BreakpointSite() override;
52
53 // This section manages the breakpoint traps
54
55 /// Returns the Opcode Bytes for this breakpoint
56 uint8_t *GetTrapOpcodeBytes();
57
58 /// Returns the Opcode Bytes for this breakpoint - const version
59 const uint8_t *GetTrapOpcodeBytes() const;
60
61 /// Get the size of the trap opcode for this address
62 size_t GetTrapOpcodeMaxByteSize() const;
63
64 /// Sets the trap opcode
65 bool SetTrapOpcode(const uint8_t *trap_opcode, uint32_t trap_opcode_size);
66
67 /// Gets the original instruction bytes that were overwritten by the trap
68 uint8_t *GetSavedOpcodeBytes();
69
70 /// Gets the original instruction bytes that were overwritten by the trap
71 /// const version
72 const uint8_t *GetSavedOpcodeBytes() const;
73
74 /// Says whether \a addr and size \a size intersects with the address \a
75 /// intersect_addr
76 bool IntersectsRange(lldb::addr_t addr, size_t size,
77 lldb::addr_t *intersect_addr, size_t *intersect_size,
78 size_t *opcode_offset) const;
79
80 /// Enquires of the breakpoint locations that produced this breakpoint site
81 /// whether we should stop at this location.
82 ///
83 /// \param[in] context
84 /// This contains the information about this stop.
85 ///
86 /// \return
87 /// \b true if we should stop, \b false otherwise.
89 BreakpointLocationCollection &stopping_bp_loc) override;
90
91 /// Standard Dump method
92 void Dump(Stream *s) const override;
93
94 /// The "Constituents" are the breakpoint locations that share this breakpoint
95 /// site. The method adds the \a constituent to this breakpoint site's
96 /// constituent list.
97 ///
98 /// \param[in] constituent
99 /// \a constituent is the Breakpoint Location to add.
100 void AddConstituent(const lldb::BreakpointLocationSP &constituent);
101
102 /// This method returns the number of breakpoint locations currently located
103 /// at this breakpoint site.
104 ///
105 /// \return
106 /// The number of constituents.
108
109 /// This method returns the breakpoint location at index \a index located at
110 /// this breakpoint site. The constituents are listed ordinally from 0 to
111 /// GetNumberOfConstituents() - 1 so you can use this method to iterate over
112 /// the constituents
113 ///
114 /// \param[in] idx
115 /// The index in the list of constituents for which you wish the
116 /// constituent location.
117 ///
118 /// \return
119 /// A shared pointer to the breakpoint location at that index.
121
122 /// This method copies the breakpoint site's constituents into a new
123 /// collection. It does this while the constituents mutex is locked.
124 ///
125 /// \param[out] out_collection
126 /// The BreakpointLocationCollection into which to put the constituents
127 /// of this breakpoint site.
128 ///
129 /// \return
130 /// The number of elements copied into out_collection.
132
133 /// Check whether the constituents of this breakpoint site have any thread
134 /// specifiers, and if yes, is \a thread contained in any of these
135 /// specifiers.
136 ///
137 /// \param[in] thread
138 /// The thread against which to test.
139 ///
140 /// return
141 /// \b true if the collection contains at least one location that
142 /// would be valid for this thread, false otherwise.
143 bool ValidForThisThread(Thread &thread);
144
145 /// Returns true if at least one constituent is both public and valid for
146 /// `thread`.
148
149 /// Print a description of this breakpoint site to the stream \a s.
150 /// GetDescription tells you about the breakpoint site's constituents. Use
151 /// BreakpointSite::Dump(Stream *) to get information about the breakpoint
152 /// site itself.
153 ///
154 /// \param[in] s
155 /// The stream to which to print the description.
156 ///
157 /// \param[in] level
158 /// The description level that indicates the detail level to
159 /// provide.
160 ///
161 /// \see lldb::DescriptionLevel
163
164 // This runs through all the breakpoint locations owning this site and returns
165 // the greatest of their suggested stack frame indexes. This only handles
166 // inlined stack changes.
167 std::optional<uint32_t> GetSuggestedStackFrameIndex();
168
169 /// Tell whether a breakpoint has a location at this site.
170 ///
171 /// \param[in] bp_id
172 /// The breakpoint id to query.
173 ///
174 /// \result
175 /// \b true if bp_id has a location that is at this site,
176 /// \b false otherwise.
178
179 /// Tell whether ALL the breakpoints in the location collection are
180 /// internal.
181 ///
182 /// \result
183 /// \b true if all breakpoint locations are owned by internal breakpoints,
184 /// \b false otherwise.
185 bool IsInternal() const;
186
192
194
195 void SetType(BreakpointSite::Type type) { m_type = type; }
196
197private:
198 friend class Process;
199 friend class BreakpointLocation;
200 // The StopInfoBreakpoint knows when it is processing a hit for a thread for
201 // a site, so let it be the one to manage setting the location hit count once
202 // and only once.
203 friend class StopInfoBreakpoint;
204
205 void BumpHitCounts();
206
207 /// The method removes the constituent at \a break_loc_id from this breakpoint
208 /// list.
209 size_t RemoveConstituent(lldb::break_id_t break_id,
210 lldb::break_id_t break_loc_id);
211
212 /// Sets whether the current breakpoint site is enabled or not.
213 ///
214 /// \param[in] enabled
215 /// \b true if the breakpoint is enabled, \b false otherwise.
216 void SetEnabled(bool enabled);
217
218 BreakpointSite::Type m_type; ///< The type of this breakpoint site.
219 uint8_t m_saved_opcode[8]; ///< The saved opcode bytes if this breakpoint site
220 ///uses trap opcodes.
221 uint8_t m_trap_opcode[8]; ///< The opcode that was used to create the
222 ///breakpoint if it is a software breakpoint site.
223 bool
224 m_enabled; ///< Boolean indicating if this breakpoint site enabled or not.
225
226 // Consider adding an optimization where if there is only one constituent, we
227 // don't store a list. The usual case will be only one constituent...
229 m_constituents; ///< This has the BreakpointLocations
230 /// that share this breakpoint site.
231 std::recursive_mutex m_constituents_mutex; ///< This mutex protects the
232 ///< constituents collection.
233
235
236 // Only the Process can create breakpoint sites in
237 // Process::CreateBreakpointSite (lldb::BreakpointLocationSP &, bool).
239 lldb::addr_t m_addr, bool use_hardware);
240
242 const BreakpointSite &operator=(const BreakpointSite &) = delete;
243};
244
245} // namespace lldb_private
246
247#endif // LLDB_BREAKPOINT_BREAKPOINTSITE_H
#define lldbassert(x)
Definition LLDBAssert.h:16
BreakpointLocationCollection m_constituents
This has the BreakpointLocations that share this breakpoint site.
bool SetTrapOpcode(const uint8_t *trap_opcode, uint32_t trap_opcode_size)
Sets the trap opcode.
static lldb::break_id_t GetNextID()
void Dump(Stream *s) const override
Standard Dump method.
const BreakpointSite & operator=(const BreakpointSite &)=delete
size_t GetTrapOpcodeMaxByteSize() const
Get the size of the trap opcode for this address.
size_t GetNumberOfConstituents()
This method returns the number of breakpoint locations currently located at this breakpoint site.
BreakpointSite::Type m_type
The type of this breakpoint site.
BreakpointSite::Type GetType() const
void SetType(BreakpointSite::Type type)
std::recursive_mutex m_constituents_mutex
This mutex protects the constituents collection.
bool IntersectsRange(lldb::addr_t addr, size_t size, lldb::addr_t *intersect_addr, size_t *intersect_size, size_t *opcode_offset) const
Says whether addr and size size intersects with the address intersect_addr.
bool ShouldStop(StoppointCallbackContext *context, BreakpointLocationCollection &stopping_bp_loc) override
Enquires of the breakpoint locations that produced this breakpoint site whether we should stop at thi...
bool IsBreakpointAtThisSite(lldb::break_id_t bp_id)
Tell whether a breakpoint has a location at this site.
void AddConstituent(const lldb::BreakpointLocationSP &constituent)
The "Constituents" are the breakpoint locations that share this breakpoint site.
uint8_t * GetTrapOpcodeBytes()
Returns the Opcode Bytes for this breakpoint.
bool IsInternal() const
Tell whether ALL the breakpoints in the location collection are internal.
bool ValidForThisThread(Thread &thread)
Check whether the constituents of this breakpoint site have any thread specifiers,...
void GetDescription(Stream *s, lldb::DescriptionLevel level)
Print a description of this breakpoint site to the stream s.
BreakpointSite(const lldb::BreakpointLocationSP &constituent, lldb::addr_t m_addr, bool use_hardware)
uint8_t m_trap_opcode[8]
The opcode that was used to create the breakpoint if it is a software breakpoint site.
size_t RemoveConstituent(lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
The method removes the constituent at break_loc_id from this breakpoint list.
uint8_t * GetSavedOpcodeBytes()
Gets the original instruction bytes that were overwritten by the trap.
BreakpointSite(const BreakpointSite &)=delete
bool ContainsUserBreakpointForThread(Thread &thread)
Returns true if at least one constituent is both public and valid for thread.
lldb::BreakpointLocationSP GetConstituentAtIndex(size_t idx)
This method returns the breakpoint location at index index located at this breakpoint site.
bool IsHardware() const override
bool m_enabled
Boolean indicating if this breakpoint site enabled or not.
std::optional< uint32_t > GetSuggestedStackFrameIndex()
uint8_t m_saved_opcode[8]
The saved opcode bytes if this breakpoint site uses trap opcodes.
size_t CopyConstituentsList(BreakpointLocationCollection &out_collection)
This method copies the breakpoint site's constituents into a new collection.
void SetEnabled(bool enabled)
Sets whether the current breakpoint site is enabled or not.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
lldb::addr_t m_addr
The load address of this stop point.
StoppointSite(lldb::break_id_t bid, lldb::addr_t m_addr, bool hardware)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
int32_t break_id_t
Definition lldb-types.h:87
uint64_t addr_t
Definition lldb-types.h:80