1 //===-- WatchpointResourceList.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 9 #ifndef LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H 10 #define LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H 11 12 #include "lldb/Utility/Iterable.h" 13 #include "lldb/lldb-private.h" 14 #include "lldb/lldb-public.h" 15 16 #include <mutex> 17 #include <vector> 18 19 namespace lldb_private { 20 21 class WatchpointResourceList { 22 23 public: 24 WatchpointResourceList(); 25 26 ~WatchpointResourceList(); 27 28 /// Add a WatchpointResource to the list. 29 /// 30 /// \param[in] wp_res_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::wp_resource_id_t Add(const lldb::WatchpointResourceSP &wp_res_sp); 36 37 /// Removes the watchpoint resource given by \a id from this list. 38 /// 39 /// \param[in] id 40 /// The watchpoint resource to remove. 41 /// 42 /// \result 43 /// \b true if the watchpoint resource \a id was in the list. 44 bool Remove(lldb::wp_resource_id_t id); 45 46 /// Removes the watchpoint resource containing address \a addr from this list. 47 /// 48 /// \param[in] addr 49 /// The address from which to remove a watchpoint resource. 50 /// 51 /// \result 52 /// \b true if \a addr had a watchpoint resource to remove from the list. 53 bool RemoveByAddress(lldb::addr_t addr); 54 55 /// Returns a shared pointer to the watchpoint resource which contains 56 /// \a addr. 57 /// 58 /// \param[in] addr 59 /// The address to look for. 60 /// 61 /// \result 62 /// A shared pointer to the watchpoint resource. May contain a nullptr 63 /// pointer if no watchpoint site exists with a matching address. 64 lldb::WatchpointResourceSP FindByAddress(lldb::addr_t addr); 65 66 /// Returns a shared pointer to the watchpoint resource which is owned 67 /// by \a wp_sp. 68 /// 69 /// \param[in] wp_sp 70 /// The WatchpointSP to look for. 71 /// 72 /// \result 73 /// A shared pointer to the watchpoint resource. May contain a nullptr 74 /// pointer if no watchpoint site exists 75 lldb::WatchpointResourceSP FindByWatchpointSP(lldb::WatchpointSP &wp_sp); 76 77 /// Returns a shared pointer to the watchpoint resource which is owned 78 /// by \a wp. 79 /// 80 /// \param[in] wp 81 /// The Watchpoint to look for. 82 /// 83 /// \result 84 /// A shared pointer to the watchpoint resource. May contain a nullptr 85 /// pointer if no watchpoint site exists 86 lldb::WatchpointResourceSP 87 FindByWatchpoint(const lldb_private::Watchpoint *wp); 88 89 /// Returns a shared pointer to the watchpoint resource which has hardware 90 /// index \a id. Some Process plugins may not have access to the actual 91 /// hardware watchpoint register number used for a WatchpointResource, so 92 /// the wp_resource_id_t may not be correctly tracking the target's wp 93 /// register target. 94 /// 95 /// \param[in] id 96 /// The hardware resource index to search for. 97 /// 98 /// \result 99 /// A shared pointer to the watchpoint resource. May contain a nullptr 100 /// pointer if no watchpoint site exists with a matching id. 101 lldb::WatchpointResourceSP FindByID(lldb::wp_resource_id_t id); 102 103 /// 104 /// Get the number of WatchpointResources that are available. 105 /// 106 /// \return 107 /// The number of WatchpointResources that are stored in the 108 /// WatchpointResourceList. 109 uint32_t GetSize(); 110 111 /// Get the WatchpointResource at a given index. 112 /// 113 /// \param [in] idx 114 /// The index of the resource. 115 /// \return 116 /// The WatchpointResource at that index number. 117 lldb::WatchpointResourceSP GetResourceAtIndex(uint32_t idx); 118 119 typedef std::vector<lldb::WatchpointResourceSP> collection; 120 typedef LockingAdaptedIterable<collection, lldb::WatchpointResourceSP, 121 vector_adapter, std::mutex> 122 WatchpointResourceIterable; 123 124 /// Iterate over the list of WatchpointResources. 125 /// 126 /// \return 127 /// An Iterable object which can be used to loop over the resources 128 /// that exist. 129 WatchpointResourceIterable Resources() { 130 return WatchpointResourceIterable(m_resources, m_mutex); 131 } 132 133 /// Clear out the list of resources from the WatchpointResourceList 134 void Clear(); 135 136 std::mutex &GetMutex(); 137 138 private: 139 collection m_resources; 140 std::mutex m_mutex; 141 }; 142 143 } // namespace lldb_private 144 145 #endif // LLDB_BREAKPOINT_WATCHPOINTRESOURCELIST_H 146