1254721Semaste//===-- WatchpointList.h ----------------------------------------*- C++ -*-===// 2254721Semaste// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6254721Semaste// 7254721Semaste//===----------------------------------------------------------------------===// 8254721Semaste 9254721Semaste#ifndef liblldb_WatchpointList_h_ 10254721Semaste#define liblldb_WatchpointList_h_ 11254721Semaste 12254721Semaste#include <list> 13309124Sdim#include <mutex> 14254721Semaste#include <vector> 15309124Sdim 16314564Sdim#include "lldb/Core/Address.h" 17254721Semaste#include "lldb/lldb-private.h" 18254721Semaste 19254721Semastenamespace lldb_private { 20254721Semaste 21353358Sdim/// \class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h" 22341825Sdim/// This class is used by Watchpoint to manage a list of watchpoints, 23254721Semaste// each watchpoint in the list has a unique ID, and is unique by Address as 24254721Semaste// well. 25254721Semaste 26314564Sdimclass WatchpointList { 27341825Sdim // Only Target can make the watchpoint list, or add elements to it. This is 28341825Sdim // not just some random collection of watchpoints. Rather, the act of adding 29341825Sdim // the watchpoint to this list sets its ID. 30314564Sdim friend class Watchpoint; 31314564Sdim friend class Target; 32254721Semaste 33254721Semastepublic: 34314564Sdim /// Default constructor makes an empty list. 35314564Sdim WatchpointList(); 36254721Semaste 37314564Sdim /// Destructor, currently does nothing. 38314564Sdim ~WatchpointList(); 39254721Semaste 40314564Sdim /// Add a Watchpoint to the list. 41314564Sdim /// 42353358Sdim /// \param[in] wp_sp 43314564Sdim /// A shared pointer to a watchpoint being added to the list. 44314564Sdim /// 45353358Sdim /// \return 46314564Sdim /// The ID of the Watchpoint in the list. 47314564Sdim lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify); 48254721Semaste 49314564Sdim /// Standard "Dump" method. 50314564Sdim void Dump(Stream *s) const; 51254721Semaste 52314564Sdim /// Dump with lldb::DescriptionLevel. 53314564Sdim void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const; 54254721Semaste 55341825Sdim /// Returns a shared pointer to the watchpoint at address \a addr - const 56341825Sdim /// version. 57314564Sdim /// 58353358Sdim /// \param[in] addr 59314564Sdim /// The address to look for. 60314564Sdim /// 61353358Sdim /// \result 62314564Sdim /// A shared pointer to the watchpoint. May contain a NULL 63314564Sdim /// pointer if the watchpoint doesn't exist. 64314564Sdim const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const; 65254721Semaste 66341825Sdim /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec 67341825Sdim /// - const version. 68314564Sdim /// 69353358Sdim /// \param[in] spec 70314564Sdim /// The watchpoint spec to look for. 71314564Sdim /// 72353358Sdim /// \result 73314564Sdim /// A shared pointer to the watchpoint. May contain a NULL 74314564Sdim /// pointer if the watchpoint doesn't exist. 75314564Sdim const lldb::WatchpointSP FindBySpec(std::string spec) const; 76254721Semaste 77341825Sdim /// Returns a shared pointer to the watchpoint with id \a watchID, const 78314564Sdim /// version. 79314564Sdim /// 80353358Sdim /// \param[in] watchID 81314564Sdim /// The watchpoint location ID to seek for. 82314564Sdim /// 83353358Sdim /// \result 84314564Sdim /// A shared pointer to the watchpoint. May contain a NULL 85314564Sdim /// pointer if the watchpoint doesn't exist. 86314564Sdim lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const; 87254721Semaste 88341825Sdim /// Returns the watchpoint id to the watchpoint at address \a addr. 89314564Sdim /// 90353358Sdim /// \param[in] addr 91314564Sdim /// The address to match. 92314564Sdim /// 93353358Sdim /// \result 94314564Sdim /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID. 95314564Sdim lldb::watch_id_t FindIDByAddress(lldb::addr_t addr); 96254721Semaste 97341825Sdim /// Returns the watchpoint id to the watchpoint with watchpoint spec \a 98341825Sdim /// spec. 99314564Sdim /// 100353358Sdim /// \param[in] spec 101314564Sdim /// The watchpoint spec to match. 102314564Sdim /// 103353358Sdim /// \result 104314564Sdim /// The ID of the watchpoint, or LLDB_INVALID_WATCH_ID. 105314564Sdim lldb::watch_id_t FindIDBySpec(std::string spec); 106254721Semaste 107314564Sdim /// Returns a shared pointer to the watchpoint with index \a i. 108314564Sdim /// 109353358Sdim /// \param[in] i 110314564Sdim /// The watchpoint index to seek for. 111314564Sdim /// 112353358Sdim /// \result 113314564Sdim /// A shared pointer to the watchpoint. May contain a NULL pointer if 114314564Sdim /// the watchpoint doesn't exist. 115314564Sdim lldb::WatchpointSP GetByIndex(uint32_t i); 116254721Semaste 117314564Sdim /// Returns a shared pointer to the watchpoint with index \a i, const 118314564Sdim /// version. 119314564Sdim /// 120353358Sdim /// \param[in] i 121314564Sdim /// The watchpoint index to seek for. 122314564Sdim /// 123353358Sdim /// \result 124314564Sdim /// A shared pointer to the watchpoint. May contain a NULL pointer if 125314564Sdim /// the watchpoint location doesn't exist. 126314564Sdim const lldb::WatchpointSP GetByIndex(uint32_t i) const; 127254721Semaste 128314564Sdim /// Removes the watchpoint given by \b watchID from this list. 129314564Sdim /// 130353358Sdim /// \param[in] watchID 131314564Sdim /// The watchpoint ID to remove. 132314564Sdim /// 133353358Sdim /// \result 134314564Sdim /// \b true if the watchpoint \a watchID was in the list. 135314564Sdim bool Remove(lldb::watch_id_t watchID, bool notify); 136254721Semaste 137314564Sdim /// Returns the number hit count of all watchpoints in this list. 138314564Sdim /// 139353358Sdim /// \result 140314564Sdim /// Hit count of all watchpoints in this list. 141314564Sdim uint32_t GetHitCount() const; 142254721Semaste 143314564Sdim /// Enquires of the watchpoint in this list with ID \a watchID whether we 144314564Sdim /// should stop. 145314564Sdim /// 146353358Sdim /// \param[in] context 147314564Sdim /// This contains the information about this stop. 148314564Sdim /// 149353358Sdim /// \param[in] watchID 150314564Sdim /// This watch ID that we hit. 151314564Sdim /// 152353358Sdim /// \return 153314564Sdim /// \b true if we should stop, \b false otherwise. 154314564Sdim bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID); 155254721Semaste 156314564Sdim /// Returns the number of elements in this watchpoint list. 157314564Sdim /// 158353358Sdim /// \result 159314564Sdim /// The number of elements. 160314564Sdim size_t GetSize() const { 161314564Sdim std::lock_guard<std::recursive_mutex> guard(m_mutex); 162314564Sdim return m_watchpoints.size(); 163314564Sdim } 164254721Semaste 165314564Sdim /// Print a description of the watchpoints in this list to the stream \a s. 166314564Sdim /// 167353358Sdim /// \param[in] s 168314564Sdim /// The stream to which to print the description. 169314564Sdim /// 170353358Sdim /// \param[in] level 171314564Sdim /// The description level that indicates the detail level to 172314564Sdim /// provide. 173314564Sdim /// 174353358Sdim /// \see lldb::DescriptionLevel 175314564Sdim void GetDescription(Stream *s, lldb::DescriptionLevel level); 176254721Semaste 177314564Sdim void SetEnabledAll(bool enabled); 178254721Semaste 179314564Sdim void RemoveAll(bool notify); 180254721Semaste 181314564Sdim /// Sets the passed in Locker to hold the Watchpoint List mutex. 182314564Sdim /// 183360784Sdim /// \param[in] lock 184314564Sdim /// The locker object that is set. 185314564Sdim void GetListMutex(std::unique_lock<std::recursive_mutex> &lock); 186314564Sdim 187254721Semasteprotected: 188314564Sdim typedef std::list<lldb::WatchpointSP> wp_collection; 189314564Sdim typedef std::vector<lldb::watch_id_t> id_vector; 190254721Semaste 191314564Sdim id_vector GetWatchpointIDs() const; 192254721Semaste 193314564Sdim wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID); 194254721Semaste 195314564Sdim wp_collection::const_iterator 196314564Sdim GetIDConstIterator(lldb::watch_id_t watchID) const; 197254721Semaste 198314564Sdim wp_collection m_watchpoints; 199314564Sdim mutable std::recursive_mutex m_mutex; 200254721Semaste 201314564Sdim lldb::watch_id_t m_next_wp_id; 202254721Semaste}; 203254721Semaste 204254721Semaste} // namespace lldb_private 205254721Semaste 206314564Sdim#endif // liblldb_WatchpointList_h_ 207