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_
18 // Other libraries and framework includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/Core/UserID.h"
23 #include "lldb/Breakpoint/StoppointLocation.h"
24 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
26 namespace lldb_private {
28 //----------------------------------------------------------------------
29 /// @class BreakpointSite BreakpointSite.h "lldb/Breakpoint/BreakpointSite.h"
30 /// @brief Class that manages the actual breakpoint that will be inserted
31 /// into the running program.
33 /// The BreakpointSite class handles the physical breakpoint that is
34 /// actually inserted in the target program. As such, it is also the
35 /// one that gets hit, when the program stops. It keeps a list of all
36 /// BreakpointLocations that share this phsyical site. When the
37 /// breakpoint is hit, all the locations are informed by the breakpoint
38 /// site. Breakpoint sites are owned by the process.
39 //----------------------------------------------------------------------
41 class BreakpointSite :
42 public std::enable_shared_from_this<BreakpointSite>,
43 public StoppointLocation
49 eSoftware, // Breakpoint opcode has been written to memory and m_saved_opcode
50 // and m_trap_opcode contain the saved and written opcode.
51 eHardware, // Breakpoint site is set as a hardware breakpoint
52 eExternal // Breakpoint site is managed by an external debug nub or
53 // debug interface where memory reads trasparently will not
54 // display any breakpoint opcodes.
57 virtual ~BreakpointSite ();
59 //----------------------------------------------------------------------
60 // This section manages the breakpoint traps
61 //----------------------------------------------------------------------
63 //------------------------------------------------------------------
64 /// Returns the Opcode Bytes for this breakpoint
65 //------------------------------------------------------------------
67 GetTrapOpcodeBytes ();
69 //------------------------------------------------------------------
70 /// Returns the Opcode Bytes for this breakpoint - const version
71 //------------------------------------------------------------------
73 GetTrapOpcodeBytes () const;
75 //------------------------------------------------------------------
76 /// Get the size of the trap opcode for this address
77 //------------------------------------------------------------------
79 GetTrapOpcodeMaxByteSize () const;
81 //------------------------------------------------------------------
82 /// Sets the trap opcode
83 //------------------------------------------------------------------
85 SetTrapOpcode (const uint8_t *trap_opcode,
86 uint32_t trap_opcode_size);
88 //------------------------------------------------------------------
89 /// Gets the original instruction bytes that were overwritten by the trap
90 //------------------------------------------------------------------
92 GetSavedOpcodeBytes ();
94 //------------------------------------------------------------------
95 /// Gets the original instruction bytes that were overwritten by the trap const version
96 //------------------------------------------------------------------
98 GetSavedOpcodeBytes () const;
100 //------------------------------------------------------------------
101 /// Says whether \a addr and size \a size intersects with the address \a intersect_addr
102 //------------------------------------------------------------------
104 IntersectsRange (lldb::addr_t addr,
106 lldb::addr_t *intersect_addr,
107 size_t *intersect_size,
108 size_t *opcode_offset) const;
110 //------------------------------------------------------------------
111 /// Tells whether the current breakpoint site is enabled or not
113 /// This is a low-level enable bit for the breakpoint sites. If a
114 /// breakpoint site has no enabled owners, it should just get
115 /// removed. This enable/disable is for the low-level target code
116 /// to enable and disable breakpoint sites when single stepping,
118 //------------------------------------------------------------------
122 //------------------------------------------------------------------
123 /// Sets whether the current breakpoint site is enabled or not
125 /// @param[in] enabled
126 /// \b true if the breakoint is enabled, \b false otherwise.
127 //------------------------------------------------------------------
129 SetEnabled (bool enabled);
131 //------------------------------------------------------------------
132 /// Enquires of the breakpoint locations that produced this breakpoint site whether
133 /// we should stop at this location.
135 /// @param[in] context
136 /// This contains the information about this stop.
139 /// \b true if we should stop, \b false otherwise.
140 //------------------------------------------------------------------
142 ShouldStop (StoppointCallbackContext *context);
144 //------------------------------------------------------------------
145 /// Standard Dump method
147 /// @param[in] context
148 /// The stream to dump this output.
149 //------------------------------------------------------------------
151 Dump (Stream *s) const;
153 //------------------------------------------------------------------
154 /// The "Owners" are the breakpoint locations that share this
155 /// breakpoint site. The method adds the \a owner to this breakpoint
156 /// site's owner list.
158 /// @param[in] context
159 /// \a owner is the Breakpoint Location to add.
160 //------------------------------------------------------------------
162 AddOwner (const lldb::BreakpointLocationSP &owner);
164 //------------------------------------------------------------------
165 /// This method returns the number of breakpoint locations currently
166 /// located at this breakpoint site.
169 /// The number of owners.
170 //------------------------------------------------------------------
172 GetNumberOfOwners ();
174 //------------------------------------------------------------------
175 /// This method returns the the breakpoint location at index \a index
176 /// located at this breakpoint site. The owners are listed ordinally
177 /// from 0 to GetNumberOfOwners() - 1 so you can use this method to iterate
181 /// The index in the list of owners for which you wish the owner location.
183 /// A shared pointer to the breakpoint location at that index.
184 //------------------------------------------------------------------
185 lldb::BreakpointLocationSP
186 GetOwnerAtIndex (size_t idx);
188 //------------------------------------------------------------------
189 /// Check whether the owners of this breakpoint site have any
190 /// thread specifiers, and if yes, is \a thread contained in any
191 /// of these specifiers.
193 /// @param[in] thread
194 /// The thread against which to test.
197 /// \b true if the collection contains at least one location that
198 /// would be valid for this thread, false otherwise.
199 //------------------------------------------------------------------
201 ValidForThisThread (Thread *thread);
204 //------------------------------------------------------------------
205 /// Print a description of this breakpoint site to the stream \a s.
206 /// GetDescription tells you about the breakpoint site's owners.
207 /// Use BreakpointSite::Dump(Stream *) to get information about the
208 /// breakpoint site itself.
211 /// The stream to which to print the description.
214 /// The description level that indicates the detail level to
217 /// @see lldb::DescriptionLevel
218 //------------------------------------------------------------------
220 GetDescription (Stream *s,
221 lldb::DescriptionLevel level);
223 //------------------------------------------------------------------
224 /// Tell whether a breakpoint has a location at this site.
227 /// The breakpoint id to query.
230 /// \b true if bp_id has a location that is at this site,
231 /// \b false otherwise.
232 //------------------------------------------------------------------
234 IsBreakpointAtThisSite (lldb::break_id_t bp_id);
236 //------------------------------------------------------------------
237 /// Tell whether ALL the breakpoints in the location collection are internal.
240 /// \b true if all breakpoint locations are owned by internal breakpoints,
241 /// \b false otherwise.
242 //------------------------------------------------------------------
253 SetType (BreakpointSite::Type type)
259 friend class Process;
261 //------------------------------------------------------------------
262 /// The method removes the owner at \a break_loc_id from this breakpoint list.
264 /// @param[in] context
265 /// \a break_loc_id is the Breakpoint Location to remove.
266 //------------------------------------------------------------------
268 RemoveOwner (lldb::break_id_t break_id,
269 lldb::break_id_t break_loc_id);
271 BreakpointSite::Type m_type;///< The type of this breakpoint site.
272 uint8_t m_saved_opcode[8]; ///< The saved opcode bytes if this breakpoint site uses trap opcodes.
273 uint8_t m_trap_opcode[8]; ///< The opcode that was used to create the breakpoint if it is a software breakpoint site.
274 bool m_enabled; ///< Boolean indicating if this breakpoint site enabled or not.
276 // Consider adding an optimization where if there is only one
277 // owner, we don't store a list. The usual case will be only one owner...
278 BreakpointLocationCollection m_owners; ///< This has the BreakpointLocations that share this breakpoint site.
280 static lldb::break_id_t
283 // Only the Process can create breakpoint sites in
284 // Process::CreateBreakpointSite (lldb::BreakpointLocationSP &, bool).
285 BreakpointSite (BreakpointSiteList *list,
286 const lldb::BreakpointLocationSP& owner,
290 DISALLOW_COPY_AND_ASSIGN(BreakpointSite);
293 } // namespace lldb_private
295 #endif // liblldb_BreakpointSite_h_