1 //===-- BreakpointSite.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_BreakpointSite_h_
11 #define liblldb_BreakpointSite_h_
19 // Other libraries and framework includes
22 #include "lldb/lldb-forward.h"
23 #include "lldb/Core/UserID.h"
24 #include "lldb/Breakpoint/StoppointLocation.h"
25 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
27 namespace lldb_private {
29 //----------------------------------------------------------------------
30 /// @class BreakpointSite BreakpointSite.h "lldb/Breakpoint/BreakpointSite.h"
31 /// @brief Class that manages the actual breakpoint that will be inserted
32 /// into the running program.
34 /// The BreakpointSite class handles the physical breakpoint that is
35 /// actually inserted in the target program. As such, it is also the
36 /// one that gets hit, when the program stops. It keeps a list of all
37 /// BreakpointLocations that share this physical site. When the
38 /// breakpoint is hit, all the locations are informed by the breakpoint
39 /// site. Breakpoint sites are owned by the process.
40 //----------------------------------------------------------------------
42 class BreakpointSite :
43 public std::enable_shared_from_this<BreakpointSite>,
44 public StoppointLocation
50 eSoftware, // Breakpoint opcode has been written to memory and m_saved_opcode
51 // and m_trap_opcode contain the saved and written opcode.
52 eHardware, // Breakpoint site is set as a hardware breakpoint
53 eExternal // Breakpoint site is managed by an external debug nub or
54 // debug interface where memory reads transparently will not
55 // display any breakpoint opcodes.
58 ~BreakpointSite() override;
60 //----------------------------------------------------------------------
61 // This section manages the breakpoint traps
62 //----------------------------------------------------------------------
64 //------------------------------------------------------------------
65 /// Returns the Opcode Bytes for this breakpoint
66 //------------------------------------------------------------------
68 GetTrapOpcodeBytes ();
70 //------------------------------------------------------------------
71 /// Returns the Opcode Bytes for this breakpoint - const version
72 //------------------------------------------------------------------
74 GetTrapOpcodeBytes () const;
76 //------------------------------------------------------------------
77 /// Get the size of the trap opcode for this address
78 //------------------------------------------------------------------
80 GetTrapOpcodeMaxByteSize () const;
82 //------------------------------------------------------------------
83 /// Sets the trap opcode
84 //------------------------------------------------------------------
86 SetTrapOpcode (const uint8_t *trap_opcode,
87 uint32_t trap_opcode_size);
89 //------------------------------------------------------------------
90 /// Gets the original instruction bytes that were overwritten by the trap
91 //------------------------------------------------------------------
93 GetSavedOpcodeBytes ();
95 //------------------------------------------------------------------
96 /// Gets the original instruction bytes that were overwritten by the trap const version
97 //------------------------------------------------------------------
99 GetSavedOpcodeBytes () const;
101 //------------------------------------------------------------------
102 /// Says whether \a addr and size \a size intersects with the address \a intersect_addr
103 //------------------------------------------------------------------
105 IntersectsRange (lldb::addr_t addr,
107 lldb::addr_t *intersect_addr,
108 size_t *intersect_size,
109 size_t *opcode_offset) const;
111 //------------------------------------------------------------------
112 /// Tells whether the current breakpoint site is enabled or not
114 /// This is a low-level enable bit for the breakpoint sites. If a
115 /// breakpoint site has no enabled owners, it should just get
116 /// removed. This enable/disable is for the low-level target code
117 /// to enable and disable breakpoint sites when single stepping,
119 //------------------------------------------------------------------
123 //------------------------------------------------------------------
124 /// Sets whether the current breakpoint site is enabled or not
126 /// @param[in] enabled
127 /// \b true if the breakpoint is enabled, \b false otherwise.
128 //------------------------------------------------------------------
130 SetEnabled (bool enabled);
132 //------------------------------------------------------------------
133 /// Enquires of the breakpoint locations that produced this breakpoint site whether
134 /// we should stop at this location.
136 /// @param[in] context
137 /// This contains the information about this stop.
140 /// \b true if we should stop, \b false otherwise.
141 //------------------------------------------------------------------
143 ShouldStop(StoppointCallbackContext *context) override;
145 //------------------------------------------------------------------
146 /// Standard Dump method
148 /// @param[in] context
149 /// The stream to dump this output.
150 //------------------------------------------------------------------
152 Dump(Stream *s) const override;
154 //------------------------------------------------------------------
155 /// The "Owners" are the breakpoint locations that share this
156 /// breakpoint site. The method adds the \a owner to this breakpoint
157 /// site's owner list.
159 /// @param[in] context
160 /// \a owner is the Breakpoint Location to add.
161 //------------------------------------------------------------------
163 AddOwner (const lldb::BreakpointLocationSP &owner);
165 //------------------------------------------------------------------
166 /// This method returns the number of breakpoint locations currently
167 /// located at this breakpoint site.
170 /// The number of owners.
171 //------------------------------------------------------------------
173 GetNumberOfOwners ();
175 //------------------------------------------------------------------
176 /// This method returns the breakpoint location at index \a index
177 /// located at this breakpoint site. The owners are listed ordinally
178 /// from 0 to GetNumberOfOwners() - 1 so you can use this method to iterate
182 /// The index in the list of owners for which you wish the owner location.
184 /// A shared pointer to the breakpoint location at that index.
185 //------------------------------------------------------------------
186 lldb::BreakpointLocationSP
187 GetOwnerAtIndex (size_t idx);
189 //------------------------------------------------------------------
190 /// This method copies the breakpoint site's owners into a new collection.
191 /// It does this while the owners mutex is locked.
193 /// @param[out] out_collection
194 /// The BreakpointLocationCollection into which to put the owners
195 /// of this breakpoint site.
198 /// The number of elements copied into out_collection.
199 //------------------------------------------------------------------
201 CopyOwnersList (BreakpointLocationCollection &out_collection);
203 //------------------------------------------------------------------
204 /// Check whether the owners of this breakpoint site have any
205 /// thread specifiers, and if yes, is \a thread contained in any
206 /// of these specifiers.
208 /// @param[in] thread
209 /// The thread against which to test.
212 /// \b true if the collection contains at least one location that
213 /// would be valid for this thread, false otherwise.
214 //------------------------------------------------------------------
216 ValidForThisThread (Thread *thread);
218 //------------------------------------------------------------------
219 /// Print a description of this breakpoint site to the stream \a s.
220 /// GetDescription tells you about the breakpoint site's owners.
221 /// Use BreakpointSite::Dump(Stream *) to get information about the
222 /// breakpoint site itself.
225 /// The stream to which to print the description.
228 /// The description level that indicates the detail level to
231 /// @see lldb::DescriptionLevel
232 //------------------------------------------------------------------
234 GetDescription (Stream *s,
235 lldb::DescriptionLevel level);
237 //------------------------------------------------------------------
238 /// Tell whether a breakpoint has a location at this site.
241 /// The breakpoint id to query.
244 /// \b true if bp_id has a location that is at this site,
245 /// \b false otherwise.
246 //------------------------------------------------------------------
248 IsBreakpointAtThisSite (lldb::break_id_t bp_id);
250 //------------------------------------------------------------------
251 /// Tell whether ALL the breakpoints in the location collection are internal.
254 /// \b true if all breakpoint locations are owned by internal breakpoints,
255 /// \b false otherwise.
256 //------------------------------------------------------------------
267 SetType (BreakpointSite::Type type)
273 friend class Process;
274 friend class BreakpointLocation;
275 // The StopInfoBreakpoint knows when it is processing a hit for a thread for a site, so let it be the
276 // one to manage setting the location hit count once and only once.
277 friend class StopInfoBreakpoint;
282 //------------------------------------------------------------------
283 /// The method removes the owner at \a break_loc_id from this breakpoint list.
285 /// @param[in] context
286 /// \a break_loc_id is the Breakpoint Location to remove.
287 //------------------------------------------------------------------
289 RemoveOwner (lldb::break_id_t break_id,
290 lldb::break_id_t break_loc_id);
292 BreakpointSite::Type m_type;///< The type of this breakpoint site.
293 uint8_t m_saved_opcode[8]; ///< The saved opcode bytes if this breakpoint site uses trap opcodes.
294 uint8_t m_trap_opcode[8]; ///< The opcode that was used to create the breakpoint if it is a software breakpoint site.
295 bool m_enabled; ///< Boolean indicating if this breakpoint site enabled or not.
297 // Consider adding an optimization where if there is only one
298 // owner, we don't store a list. The usual case will be only one owner...
299 BreakpointLocationCollection m_owners; ///< This has the BreakpointLocations that share this breakpoint site.
300 std::recursive_mutex m_owners_mutex; ///< This mutex protects the owners collection.
302 static lldb::break_id_t
305 // Only the Process can create breakpoint sites in
306 // Process::CreateBreakpointSite (lldb::BreakpointLocationSP &, bool).
307 BreakpointSite (BreakpointSiteList *list,
308 const lldb::BreakpointLocationSP& owner,
312 DISALLOW_COPY_AND_ASSIGN(BreakpointSite);
315 } // namespace lldb_private
317 #endif // liblldb_BreakpointSite_h_