WatchpointList.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //===-- WatchpointList.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_WATCHPOINTLIST_H
  9. #define LLDB_BREAKPOINT_WATCHPOINTLIST_H
  10. #include <list>
  11. #include <mutex>
  12. #include <vector>
  13. #include "lldb/Core/Address.h"
  14. #include "lldb/lldb-private.h"
  15. namespace lldb_private {
  16. /// \class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h"
  17. /// This class is used by Watchpoint to manage a list of watchpoints,
  18. // each watchpoint in the list has a unique ID, and is unique by Address as
  19. // well.
  20. class WatchpointList {
  21. // Only Target can make the watchpoint list, or add elements to it. This is
  22. // not just some random collection of watchpoints. Rather, the act of adding
  23. // the watchpoint to this list sets its ID.
  24. friend class Watchpoint;
  25. friend class Target;
  26. public:
  27. /// Default constructor makes an empty list.
  28. WatchpointList();
  29. /// Destructor, currently does nothing.
  30. ~WatchpointList();
  31. /// Add a Watchpoint to the list.
  32. ///
  33. /// \param[in] wp_sp
  34. /// A shared pointer to a watchpoint being added to the list.
  35. ///
  36. /// \return
  37. /// The ID of the Watchpoint in the list.
  38. lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify);
  39. /// Standard "Dump" method.
  40. void Dump(Stream *s) const;
  41. /// Dump with lldb::DescriptionLevel.
  42. void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
  43. /// Returns a shared pointer to the watchpoint at address \a addr - const
  44. /// version.
  45. ///
  46. /// \param[in] addr
  47. /// The address to look for.
  48. ///
  49. /// \result
  50. /// A shared pointer to the watchpoint. May contain a NULL
  51. /// pointer if the watchpoint doesn't exist.
  52. const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const;
  53. /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec
  54. /// - const version.
  55. ///
  56. /// \param[in] spec
  57. /// The watchpoint spec to look for.
  58. ///
  59. /// \result
  60. /// A shared pointer to the watchpoint. May contain a NULL
  61. /// pointer if the watchpoint doesn't exist.
  62. const lldb::WatchpointSP FindBySpec(std::string spec) const;
  63. /// Returns a shared pointer to the watchpoint with id \a watchID, const
  64. /// version.
  65. ///
  66. /// \param[in] watchID
  67. /// The watchpoint location ID to seek for.
  68. ///
  69. /// \result
  70. /// A shared pointer to the watchpoint. May contain a NULL
  71. /// pointer if the watchpoint doesn't exist.
  72. lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const;
  73. /// Returns the watchpoint id to the watchpoint at address \a addr.
  74. ///
  75. /// \param[in] addr
  76. /// The address to match.
  77. ///
  78. /// \result
  79. /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
  80. lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
  81. /// Returns the watchpoint id to the watchpoint with watchpoint spec \a
  82. /// spec.
  83. ///
  84. /// \param[in] spec
  85. /// The watchpoint spec to match.
  86. ///
  87. /// \result
  88. /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
  89. lldb::watch_id_t FindIDBySpec(std::string spec);
  90. /// Returns a shared pointer to the watchpoint with index \a i.
  91. ///
  92. /// \param[in] i
  93. /// The watchpoint index to seek for.
  94. ///
  95. /// \result
  96. /// A shared pointer to the watchpoint. May contain a NULL pointer if
  97. /// the watchpoint doesn't exist.
  98. lldb::WatchpointSP GetByIndex(uint32_t i);
  99. /// Returns a shared pointer to the watchpoint with index \a i, const
  100. /// version.
  101. ///
  102. /// \param[in] i
  103. /// The watchpoint index to seek for.
  104. ///
  105. /// \result
  106. /// A shared pointer to the watchpoint. May contain a NULL pointer if
  107. /// the watchpoint location doesn't exist.
  108. const lldb::WatchpointSP GetByIndex(uint32_t i) const;
  109. /// Removes the watchpoint given by \b watchID from this list.
  110. ///
  111. /// \param[in] watchID
  112. /// The watchpoint ID to remove.
  113. ///
  114. /// \result
  115. /// \b true if the watchpoint \a watchID was in the list.
  116. bool Remove(lldb::watch_id_t watchID, bool notify);
  117. /// Returns the number hit count of all watchpoints in this list.
  118. ///
  119. /// \result
  120. /// Hit count of all watchpoints in this list.
  121. uint32_t GetHitCount() const;
  122. /// Enquires of the watchpoint in this list with ID \a watchID whether we
  123. /// should stop.
  124. ///
  125. /// \param[in] context
  126. /// This contains the information about this stop.
  127. ///
  128. /// \param[in] watchID
  129. /// This watch ID that we hit.
  130. ///
  131. /// \return
  132. /// \b true if we should stop, \b false otherwise.
  133. bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
  134. /// Returns the number of elements in this watchpoint list.
  135. ///
  136. /// \result
  137. /// The number of elements.
  138. size_t GetSize() const {
  139. std::lock_guard<std::recursive_mutex> guard(m_mutex);
  140. return m_watchpoints.size();
  141. }
  142. /// Print a description of the watchpoints in this list to the stream \a s.
  143. ///
  144. /// \param[in] s
  145. /// The stream to which to print the description.
  146. ///
  147. /// \param[in] level
  148. /// The description level that indicates the detail level to
  149. /// provide.
  150. ///
  151. /// \see lldb::DescriptionLevel
  152. void GetDescription(Stream *s, lldb::DescriptionLevel level);
  153. void SetEnabledAll(bool enabled);
  154. void RemoveAll(bool notify);
  155. /// Sets the passed in Locker to hold the Watchpoint List mutex.
  156. ///
  157. /// \param[in] lock
  158. /// The locker object that is set.
  159. void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
  160. protected:
  161. typedef std::list<lldb::WatchpointSP> wp_collection;
  162. typedef std::vector<lldb::watch_id_t> id_vector;
  163. id_vector GetWatchpointIDs() const;
  164. wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
  165. wp_collection::const_iterator
  166. GetIDConstIterator(lldb::watch_id_t watchID) const;
  167. wp_collection m_watchpoints;
  168. mutable std::recursive_mutex m_mutex;
  169. lldb::watch_id_t m_next_wp_id;
  170. };
  171. } // namespace lldb_private
  172. #endif // LLDB_BREAKPOINT_WATCHPOINTLIST_H