PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/include/lldb/Breakpoint/BreakpointSite.h

https://gitlab.com/jorjpimm/lldb
C Header | 304 lines | 98 code | 42 blank | 164 comment | 0 complexity | 1956ed1f6df98166b01d35b3cd0346da MD5 | raw file
  1. //===-- BreakpointSite.h ----------------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef liblldb_BreakpointSite_h_
  10. #define liblldb_BreakpointSite_h_
  11. // C Includes
  12. // C++ Includes
  13. #include <list>
  14. // Other libraries and framework includes
  15. // Project includes
  16. #include "lldb/lldb-private.h"
  17. #include "lldb/Host/Mutex.h"
  18. #include "lldb/Core/UserID.h"
  19. #include "lldb/Breakpoint/StoppointLocation.h"
  20. #include "lldb/Breakpoint/BreakpointLocationCollection.h"
  21. namespace lldb_private {
  22. //----------------------------------------------------------------------
  23. /// @class BreakpointSite BreakpointSite.h "lldb/Breakpoint/BreakpointSite.h"
  24. /// @brief Class that manages the actual breakpoint that will be inserted
  25. /// into the running program.
  26. ///
  27. /// The BreakpointSite class handles the physical breakpoint that is
  28. /// actually inserted in the target program. As such, it is also the
  29. /// one that gets hit, when the program stops. It keeps a list of all
  30. /// BreakpointLocations that share this physical site. When the
  31. /// breakpoint is hit, all the locations are informed by the breakpoint
  32. /// site. Breakpoint sites are owned by the process.
  33. //----------------------------------------------------------------------
  34. class BreakpointSite :
  35. public std::enable_shared_from_this<BreakpointSite>,
  36. public StoppointLocation
  37. {
  38. public:
  39. enum Type
  40. {
  41. eSoftware, // Breakpoint opcode has been written to memory and m_saved_opcode
  42. // and m_trap_opcode contain the saved and written opcode.
  43. eHardware, // Breakpoint site is set as a hardware breakpoint
  44. eExternal // Breakpoint site is managed by an external debug nub or
  45. // debug interface where memory reads transparently will not
  46. // display any breakpoint opcodes.
  47. };
  48. virtual ~BreakpointSite ();
  49. //----------------------------------------------------------------------
  50. // This section manages the breakpoint traps
  51. //----------------------------------------------------------------------
  52. //------------------------------------------------------------------
  53. /// Returns the Opcode Bytes for this breakpoint
  54. //------------------------------------------------------------------
  55. uint8_t *
  56. GetTrapOpcodeBytes ();
  57. //------------------------------------------------------------------
  58. /// Returns the Opcode Bytes for this breakpoint - const version
  59. //------------------------------------------------------------------
  60. const uint8_t *
  61. GetTrapOpcodeBytes () const;
  62. //------------------------------------------------------------------
  63. /// Get the size of the trap opcode for this address
  64. //------------------------------------------------------------------
  65. size_t
  66. GetTrapOpcodeMaxByteSize () const;
  67. //------------------------------------------------------------------
  68. /// Sets the trap opcode
  69. //------------------------------------------------------------------
  70. bool
  71. SetTrapOpcode (const uint8_t *trap_opcode,
  72. uint32_t trap_opcode_size);
  73. //------------------------------------------------------------------
  74. /// Gets the original instruction bytes that were overwritten by the trap
  75. //------------------------------------------------------------------
  76. uint8_t *
  77. GetSavedOpcodeBytes ();
  78. //------------------------------------------------------------------
  79. /// Gets the original instruction bytes that were overwritten by the trap const version
  80. //------------------------------------------------------------------
  81. const uint8_t *
  82. GetSavedOpcodeBytes () const;
  83. //------------------------------------------------------------------
  84. /// Says whether \a addr and size \a size intersects with the address \a intersect_addr
  85. //------------------------------------------------------------------
  86. bool
  87. IntersectsRange (lldb::addr_t addr,
  88. size_t size,
  89. lldb::addr_t *intersect_addr,
  90. size_t *intersect_size,
  91. size_t *opcode_offset) const;
  92. //------------------------------------------------------------------
  93. /// Tells whether the current breakpoint site is enabled or not
  94. ///
  95. /// This is a low-level enable bit for the breakpoint sites. If a
  96. /// breakpoint site has no enabled owners, it should just get
  97. /// removed. This enable/disable is for the low-level target code
  98. /// to enable and disable breakpoint sites when single stepping,
  99. /// etc.
  100. //------------------------------------------------------------------
  101. bool
  102. IsEnabled () const;
  103. //------------------------------------------------------------------
  104. /// Sets whether the current breakpoint site is enabled or not
  105. ///
  106. /// @param[in] enabled
  107. /// \b true if the breakpoint is enabled, \b false otherwise.
  108. //------------------------------------------------------------------
  109. void
  110. SetEnabled (bool enabled);
  111. //------------------------------------------------------------------
  112. /// Enquires of the breakpoint locations that produced this breakpoint site whether
  113. /// we should stop at this location.
  114. ///
  115. /// @param[in] context
  116. /// This contains the information about this stop.
  117. ///
  118. /// @return
  119. /// \b true if we should stop, \b false otherwise.
  120. //------------------------------------------------------------------
  121. virtual bool
  122. ShouldStop (StoppointCallbackContext *context);
  123. //------------------------------------------------------------------
  124. /// Standard Dump method
  125. ///
  126. /// @param[in] context
  127. /// The stream to dump this output.
  128. //------------------------------------------------------------------
  129. void
  130. Dump (Stream *s) const;
  131. //------------------------------------------------------------------
  132. /// The "Owners" are the breakpoint locations that share this
  133. /// breakpoint site. The method adds the \a owner to this breakpoint
  134. /// site's owner list.
  135. ///
  136. /// @param[in] context
  137. /// \a owner is the Breakpoint Location to add.
  138. //------------------------------------------------------------------
  139. void
  140. AddOwner (const lldb::BreakpointLocationSP &owner);
  141. //------------------------------------------------------------------
  142. /// This method returns the number of breakpoint locations currently
  143. /// located at this breakpoint site.
  144. ///
  145. /// @return
  146. /// The number of owners.
  147. //------------------------------------------------------------------
  148. size_t
  149. GetNumberOfOwners ();
  150. //------------------------------------------------------------------
  151. /// This method returns the breakpoint location at index \a index
  152. /// located at this breakpoint site. The owners are listed ordinally
  153. /// from 0 to GetNumberOfOwners() - 1 so you can use this method to iterate
  154. /// over the owners
  155. ///
  156. /// @param[in] index
  157. /// The index in the list of owners for which you wish the owner location.
  158. /// @return
  159. /// A shared pointer to the breakpoint location at that index.
  160. //------------------------------------------------------------------
  161. lldb::BreakpointLocationSP
  162. GetOwnerAtIndex (size_t idx);
  163. //------------------------------------------------------------------
  164. /// Check whether the owners of this breakpoint site have any
  165. /// thread specifiers, and if yes, is \a thread contained in any
  166. /// of these specifiers.
  167. ///
  168. /// @param[in] thread
  169. /// The thread against which to test.
  170. ///
  171. /// return
  172. /// \b true if the collection contains at least one location that
  173. /// would be valid for this thread, false otherwise.
  174. //------------------------------------------------------------------
  175. bool
  176. ValidForThisThread (Thread *thread);
  177. //------------------------------------------------------------------
  178. /// Print a description of this breakpoint site to the stream \a s.
  179. /// GetDescription tells you about the breakpoint site's owners.
  180. /// Use BreakpointSite::Dump(Stream *) to get information about the
  181. /// breakpoint site itself.
  182. ///
  183. /// @param[in] s
  184. /// The stream to which to print the description.
  185. ///
  186. /// @param[in] level
  187. /// The description level that indicates the detail level to
  188. /// provide.
  189. ///
  190. /// @see lldb::DescriptionLevel
  191. //------------------------------------------------------------------
  192. void
  193. GetDescription (Stream *s,
  194. lldb::DescriptionLevel level);
  195. //------------------------------------------------------------------
  196. /// Tell whether a breakpoint has a location at this site.
  197. ///
  198. /// @param[in] bp_id
  199. /// The breakpoint id to query.
  200. ///
  201. /// @result
  202. /// \b true if bp_id has a location that is at this site,
  203. /// \b false otherwise.
  204. //------------------------------------------------------------------
  205. bool
  206. IsBreakpointAtThisSite (lldb::break_id_t bp_id);
  207. //------------------------------------------------------------------
  208. /// Tell whether ALL the breakpoints in the location collection are internal.
  209. ///
  210. /// @result
  211. /// \b true if all breakpoint locations are owned by internal breakpoints,
  212. /// \b false otherwise.
  213. //------------------------------------------------------------------
  214. bool
  215. IsInternal () const;
  216. BreakpointSite::Type
  217. GetType () const
  218. {
  219. return m_type;
  220. }
  221. void
  222. SetType (BreakpointSite::Type type)
  223. {
  224. m_type = type;
  225. }
  226. private:
  227. friend class Process;
  228. friend class BreakpointLocation;
  229. // The StopInfoBreakpoint knows when it is processing a hit for a thread for a site, so let it be the
  230. // one to manage setting the location hit count once and only once.
  231. friend class StopInfoBreakpoint;
  232. void
  233. BumpHitCounts();
  234. //------------------------------------------------------------------
  235. /// The method removes the owner at \a break_loc_id from this breakpoint list.
  236. ///
  237. /// @param[in] context
  238. /// \a break_loc_id is the Breakpoint Location to remove.
  239. //------------------------------------------------------------------
  240. size_t
  241. RemoveOwner (lldb::break_id_t break_id,
  242. lldb::break_id_t break_loc_id);
  243. BreakpointSite::Type m_type;///< The type of this breakpoint site.
  244. uint8_t m_saved_opcode[8]; ///< The saved opcode bytes if this breakpoint site uses trap opcodes.
  245. uint8_t m_trap_opcode[8]; ///< The opcode that was used to create the breakpoint if it is a software breakpoint site.
  246. bool m_enabled; ///< Boolean indicating if this breakpoint site enabled or not.
  247. // Consider adding an optimization where if there is only one
  248. // owner, we don't store a list. The usual case will be only one owner...
  249. BreakpointLocationCollection m_owners; ///< This has the BreakpointLocations that share this breakpoint site.
  250. Mutex m_owners_mutex; ///< This mutex protects the owners collection.
  251. static lldb::break_id_t
  252. GetNextID();
  253. // Only the Process can create breakpoint sites in
  254. // Process::CreateBreakpointSite (lldb::BreakpointLocationSP &, bool).
  255. BreakpointSite (BreakpointSiteList *list,
  256. const lldb::BreakpointLocationSP& owner,
  257. lldb::addr_t m_addr,
  258. bool use_hardware);
  259. DISALLOW_COPY_AND_ASSIGN(BreakpointSite);
  260. };
  261. } // namespace lldb_private
  262. #endif // liblldb_BreakpointSite_h_