BreakpointSiteList.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //===-- BreakpointSiteList.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_BREAKPOINTSITELIST_H
  9. #define LLDB_BREAKPOINT_BREAKPOINTSITELIST_H
  10. #include <functional>
  11. #include <map>
  12. #include <mutex>
  13. #include "lldb/Breakpoint/BreakpointSite.h"
  14. namespace lldb_private {
  15. /// \class BreakpointSiteList BreakpointSiteList.h
  16. /// "lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of
  17. /// BreakpointSite shared pointers.
  18. class BreakpointSiteList {
  19. // At present Process directly accesses the map of BreakpointSites so it can
  20. // do quick lookups into the map (using GetMap).
  21. // FIXME: Find a better interface for this.
  22. friend class Process;
  23. public:
  24. /// Default constructor makes an empty list.
  25. BreakpointSiteList();
  26. /// Destructor, currently does nothing.
  27. ~BreakpointSiteList();
  28. /// Add a BreakpointSite to the list.
  29. ///
  30. /// \param[in] bp_site_sp
  31. /// A shared pointer to a breakpoint site being added to the list.
  32. ///
  33. /// \return
  34. /// The ID of the BreakpointSite in the list.
  35. lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp);
  36. /// Standard Dump routine, doesn't do anything at present. \param[in] s
  37. /// Stream into which to dump the description.
  38. void Dump(Stream *s) const;
  39. /// Returns a shared pointer to the breakpoint site at address \a addr.
  40. ///
  41. /// \param[in] addr
  42. /// The address to look for.
  43. ///
  44. /// \result
  45. /// A shared pointer to the breakpoint site. May contain a NULL
  46. /// pointer if no breakpoint site exists with a matching address.
  47. lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr);
  48. /// Returns a shared pointer to the breakpoint site with id \a breakID.
  49. ///
  50. /// \param[in] breakID
  51. /// The breakpoint site ID to seek for.
  52. ///
  53. /// \result
  54. /// A shared pointer to the breakpoint site. May contain a NULL pointer if
  55. /// the
  56. /// breakpoint doesn't exist.
  57. lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID);
  58. /// Returns a shared pointer to the breakpoint site with id \a breakID -
  59. /// const version.
  60. ///
  61. /// \param[in] breakID
  62. /// The breakpoint site ID to seek for.
  63. ///
  64. /// \result
  65. /// A shared pointer to the breakpoint site. May contain a NULL pointer if
  66. /// the
  67. /// breakpoint doesn't exist.
  68. const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const;
  69. /// Returns the breakpoint site id to the breakpoint site at address \a
  70. /// addr.
  71. ///
  72. /// \param[in] addr
  73. /// The address to match.
  74. ///
  75. /// \result
  76. /// The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
  77. lldb::break_id_t FindIDByAddress(lldb::addr_t addr);
  78. /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
  79. // as one of its owners.
  80. ///
  81. /// \param[in] bp_site_id
  82. /// The breakpoint site id to query.
  83. ///
  84. /// \param[in] bp_id
  85. /// The breakpoint id to look for in \a bp_site_id.
  86. ///
  87. /// \result
  88. /// True if \a bp_site_id exists in the site list AND \a bp_id is one of the
  89. /// owners of that site.
  90. bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id,
  91. lldb::break_id_t bp_id);
  92. void ForEach(std::function<void(BreakpointSite *)> const &callback);
  93. /// Removes the breakpoint site given by \b breakID from this list.
  94. ///
  95. /// \param[in] breakID
  96. /// The breakpoint site index to remove.
  97. ///
  98. /// \result
  99. /// \b true if the breakpoint site \a breakID was in the list.
  100. bool Remove(lldb::break_id_t breakID);
  101. /// Removes the breakpoint site at address \a addr from this list.
  102. ///
  103. /// \param[in] addr
  104. /// The address from which to remove a breakpoint site.
  105. ///
  106. /// \result
  107. /// \b true if \a addr had a breakpoint site to remove from the list.
  108. bool RemoveByAddress(lldb::addr_t addr);
  109. bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound,
  110. BreakpointSiteList &bp_site_list) const;
  111. typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp,
  112. void *baton);
  113. /// Enquires of the breakpoint site on in this list with ID \a breakID
  114. /// whether we should stop for the breakpoint or not.
  115. ///
  116. /// \param[in] context
  117. /// This contains the information about this stop.
  118. ///
  119. /// \param[in] breakID
  120. /// This break ID that we hit.
  121. ///
  122. /// \return
  123. /// \b true if we should stop, \b false otherwise.
  124. bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
  125. /// Returns the number of elements in the list.
  126. ///
  127. /// \result
  128. /// The number of elements.
  129. size_t GetSize() const {
  130. std::lock_guard<std::recursive_mutex> guard(m_mutex);
  131. return m_bp_site_list.size();
  132. }
  133. bool IsEmpty() const {
  134. std::lock_guard<std::recursive_mutex> guard(m_mutex);
  135. return m_bp_site_list.empty();
  136. }
  137. protected:
  138. typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
  139. collection::iterator GetIDIterator(lldb::break_id_t breakID);
  140. collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const;
  141. mutable std::recursive_mutex m_mutex;
  142. collection m_bp_site_list; // The breakpoint site list.
  143. };
  144. } // namespace lldb_private
  145. #endif // LLDB_BREAKPOINT_BREAKPOINTSITELIST_H