BreakpointList.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //===-- BreakpointList.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_BREAKPOINTLIST_H
  9. #define LLDB_BREAKPOINT_BREAKPOINTLIST_H
  10. #include <list>
  11. #include <mutex>
  12. #include "lldb/Breakpoint/Breakpoint.h"
  13. namespace lldb_private {
  14. /// \class BreakpointList BreakpointList.h "lldb/Breakpoint/BreakpointList.h"
  15. /// This class manages a list of breakpoints.
  16. /// General Outline:
  17. /// Allows adding and removing breakpoints and find by ID and index.
  18. class BreakpointList {
  19. public:
  20. BreakpointList(bool is_internal);
  21. ~BreakpointList();
  22. /// Add the breakpoint \a bp_sp to the list.
  23. ///
  24. /// \param[in] bp_sp
  25. /// Shared pointer to the breakpoint that will get added to the list.
  26. ///
  27. /// \result
  28. /// Returns breakpoint id.
  29. lldb::break_id_t Add(lldb::BreakpointSP &bp_sp, bool notify);
  30. /// Standard "Dump" method. At present it does nothing.
  31. void Dump(Stream *s) const;
  32. /// Returns a shared pointer to the breakpoint with id \a breakID. Const
  33. /// version.
  34. ///
  35. /// \param[in] breakID
  36. /// The breakpoint ID to seek for.
  37. ///
  38. /// \result
  39. /// A shared pointer to the breakpoint. May contain a NULL pointer if the
  40. /// breakpoint doesn't exist.
  41. lldb::BreakpointSP FindBreakpointByID(lldb::break_id_t breakID) const;
  42. /// Returns a shared pointer to the breakpoint with index \a i.
  43. ///
  44. /// \param[in] i
  45. /// The breakpoint index to seek for.
  46. ///
  47. /// \result
  48. /// A shared pointer to the breakpoint. May contain a NULL pointer if the
  49. /// breakpoint doesn't exist.
  50. lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const;
  51. /// Find all the breakpoints with a given name
  52. ///
  53. /// \param[in] name
  54. /// The breakpoint name for which to search.
  55. ///
  56. /// \result
  57. /// error if the input name was not a legal breakpoint name, vector
  58. /// of breakpoints otherwise.
  59. llvm::Expected<std::vector<lldb::BreakpointSP>>
  60. FindBreakpointsByName(const char *name);
  61. /// Returns the number of elements in this breakpoint list.
  62. ///
  63. /// \result
  64. /// The number of elements.
  65. size_t GetSize() const {
  66. std::lock_guard<std::recursive_mutex> guard(m_mutex);
  67. return m_breakpoints.size();
  68. }
  69. /// Removes the breakpoint given by \b breakID from this list.
  70. ///
  71. /// \param[in] breakID
  72. /// The breakpoint index to remove.
  73. ///
  74. /// \result
  75. /// \b true if the breakpoint \a breakID was in the list.
  76. bool Remove(lldb::break_id_t breakID, bool notify);
  77. /// Removes all invalid breakpoint locations.
  78. ///
  79. /// Removes all breakpoint locations in the list with architectures that
  80. /// aren't compatible with \a arch. Also remove any breakpoint locations
  81. /// with whose locations have address where the section has been deleted
  82. /// (module and object files no longer exist).
  83. ///
  84. /// This is typically used after the process calls exec, or anytime the
  85. /// architecture of the target changes.
  86. ///
  87. /// \param[in] arch
  88. /// If valid, check the module in each breakpoint to make sure
  89. /// they are compatible, otherwise, ignore architecture.
  90. void RemoveInvalidLocations(const ArchSpec &arch);
  91. void SetEnabledAll(bool enabled);
  92. void SetEnabledAllowed(bool enabled);
  93. /// Removes all the breakpoints from this list.
  94. void RemoveAll(bool notify);
  95. /// Removes all the breakpoints from this list - first checking the
  96. /// ePermDelete on the breakpoints. This call should be used unless you are
  97. /// shutting down and need to actually clear them all.
  98. void RemoveAllowed(bool notify);
  99. /// Tell all the breakpoints to update themselves due to a change in the
  100. /// modules in \a module_list. \a added says whether the module was loaded
  101. /// or unloaded.
  102. ///
  103. /// \param[in] module_list
  104. /// The module list that has changed.
  105. ///
  106. /// \param[in] load
  107. /// \b true if the modules are loaded, \b false if unloaded.
  108. ///
  109. /// \param[in] delete_locations
  110. /// If \a load is \b false, then delete breakpoint locations when
  111. /// when updating breakpoints.
  112. void UpdateBreakpoints(ModuleList &module_list, bool load,
  113. bool delete_locations);
  114. void UpdateBreakpointsWhenModuleIsReplaced(lldb::ModuleSP old_module_sp,
  115. lldb::ModuleSP new_module_sp);
  116. void ClearAllBreakpointSites();
  117. /// Sets the passed in Locker to hold the Breakpoint List mutex.
  118. ///
  119. /// \param[in] lock
  120. /// The locker object that is set.
  121. void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
  122. protected:
  123. typedef std::vector<lldb::BreakpointSP> bp_collection;
  124. bp_collection::iterator GetBreakpointIDIterator(lldb::break_id_t breakID);
  125. bp_collection::const_iterator
  126. GetBreakpointIDConstIterator(lldb::break_id_t breakID) const;
  127. std::recursive_mutex &GetMutex() const { return m_mutex; }
  128. mutable std::recursive_mutex m_mutex;
  129. bp_collection m_breakpoints;
  130. lldb::break_id_t m_next_break_id;
  131. bool m_is_internal;
  132. public:
  133. typedef LockingAdaptedIterable<bp_collection, lldb::BreakpointSP,
  134. list_adapter, std::recursive_mutex>
  135. BreakpointIterable;
  136. BreakpointIterable Breakpoints() {
  137. return BreakpointIterable(m_breakpoints, GetMutex());
  138. }
  139. private:
  140. BreakpointList(const BreakpointList &) = delete;
  141. const BreakpointList &operator=(const BreakpointList &) = delete;
  142. };
  143. } // namespace lldb_private
  144. #endif // LLDB_BREAKPOINT_BREAKPOINTLIST_H