BreakpointLocationList.h 7.1 KB

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