Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:44

0001 //===-- WatchpointList.h ----------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_BREAKPOINT_WATCHPOINTLIST_H
0010 #define LLDB_BREAKPOINT_WATCHPOINTLIST_H
0011 
0012 #include <list>
0013 #include <mutex>
0014 #include <vector>
0015 
0016 #include "lldb/Core/Address.h"
0017 #include "lldb/Utility/Iterable.h"
0018 #include "lldb/lldb-private.h"
0019 
0020 namespace lldb_private {
0021 
0022 /// \class WatchpointList WatchpointList.h "lldb/Breakpoint/WatchpointList.h"
0023 /// This class is used by Watchpoint to manage a list of watchpoints,
0024 //  each watchpoint in the list has a unique ID, and is unique by Address as
0025 //  well.
0026 
0027 class WatchpointList {
0028   // Only Target can make the watchpoint list, or add elements to it. This is
0029   // not just some random collection of watchpoints.  Rather, the act of adding
0030   // the watchpoint to this list sets its ID.
0031   friend class Watchpoint;
0032   friend class Target;
0033 
0034 public:
0035   /// Default constructor makes an empty list.
0036   WatchpointList();
0037 
0038   /// Destructor, currently does nothing.
0039   ~WatchpointList();
0040 
0041   typedef std::list<lldb::WatchpointSP> wp_collection;
0042   typedef LockingAdaptedIterable<wp_collection, lldb::WatchpointSP,
0043                                  vector_adapter, std::recursive_mutex>
0044       WatchpointIterable;
0045 
0046   /// Add a Watchpoint to the list.
0047   ///
0048   /// \param[in] wp_sp
0049   ///    A shared pointer to a watchpoint being added to the list.
0050   ///
0051   /// \return
0052   ///    The ID of the Watchpoint in the list.
0053   lldb::watch_id_t Add(const lldb::WatchpointSP &wp_sp, bool notify);
0054 
0055   /// Standard "Dump" method.
0056   void Dump(Stream *s) const;
0057 
0058   /// Dump with lldb::DescriptionLevel.
0059   void DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const;
0060 
0061   /// Returns a shared pointer to the watchpoint at address \a addr - const
0062   /// version.
0063   ///
0064   /// \param[in] addr
0065   ///     The address to look for.
0066   ///
0067   /// \result
0068   ///     A shared pointer to the watchpoint.  May contain a NULL
0069   ///     pointer if the watchpoint doesn't exist.
0070   const lldb::WatchpointSP FindByAddress(lldb::addr_t addr) const;
0071 
0072   /// Returns a shared pointer to the watchpoint with watchpoint spec \a spec
0073   /// - const version.
0074   ///
0075   /// \param[in] spec
0076   ///     The watchpoint spec to look for.
0077   ///
0078   /// \result
0079   ///     A shared pointer to the watchpoint.  May contain a NULL
0080   ///     pointer if the watchpoint doesn't exist.
0081   const lldb::WatchpointSP FindBySpec(std::string spec) const;
0082 
0083   /// Returns a shared pointer to the watchpoint with id \a watchID, const
0084   /// version.
0085   ///
0086   /// \param[in] watchID
0087   ///     The watchpoint location ID to seek for.
0088   ///
0089   /// \result
0090   ///     A shared pointer to the watchpoint.  May contain a NULL
0091   ///     pointer if the watchpoint doesn't exist.
0092   lldb::WatchpointSP FindByID(lldb::watch_id_t watchID) const;
0093 
0094   /// Returns the watchpoint id to the watchpoint at address \a addr.
0095   ///
0096   /// \param[in] addr
0097   ///     The address to match.
0098   ///
0099   /// \result
0100   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
0101   lldb::watch_id_t FindIDByAddress(lldb::addr_t addr);
0102 
0103   /// Returns the watchpoint id to the watchpoint with watchpoint spec \a
0104   /// spec.
0105   ///
0106   /// \param[in] spec
0107   ///     The watchpoint spec to match.
0108   ///
0109   /// \result
0110   ///     The ID of the watchpoint, or LLDB_INVALID_WATCH_ID.
0111   lldb::watch_id_t FindIDBySpec(std::string spec);
0112 
0113   /// Returns a shared pointer to the watchpoint with index \a i.
0114   ///
0115   /// \param[in] i
0116   ///     The watchpoint index to seek for.
0117   ///
0118   /// \result
0119   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
0120   ///     the watchpoint doesn't exist.
0121   lldb::WatchpointSP GetByIndex(uint32_t i);
0122 
0123   /// Returns a shared pointer to the watchpoint with index \a i, const
0124   /// version.
0125   ///
0126   /// \param[in] i
0127   ///     The watchpoint index to seek for.
0128   ///
0129   /// \result
0130   ///     A shared pointer to the watchpoint.  May contain a NULL pointer if
0131   ///     the watchpoint location doesn't exist.
0132   const lldb::WatchpointSP GetByIndex(uint32_t i) const;
0133 
0134   /// Removes the watchpoint given by \b watchID from this list.
0135   ///
0136   /// \param[in] watchID
0137   ///   The watchpoint ID to remove.
0138   ///
0139   /// \result
0140   ///   \b true if the watchpoint \a watchID was in the list.
0141   bool Remove(lldb::watch_id_t watchID, bool notify);
0142 
0143   /// Returns the number hit count of all watchpoints in this list.
0144   ///
0145   /// \result
0146   ///     Hit count of all watchpoints in this list.
0147   uint32_t GetHitCount() const;
0148 
0149   /// Enquires of the watchpoint in this list with ID \a watchID whether we
0150   /// should stop.
0151   ///
0152   /// \param[in] context
0153   ///     This contains the information about this stop.
0154   ///
0155   /// \param[in] watchID
0156   ///     This watch ID that we hit.
0157   ///
0158   /// \return
0159   ///     \b true if we should stop, \b false otherwise.
0160   bool ShouldStop(StoppointCallbackContext *context, lldb::watch_id_t watchID);
0161 
0162   /// Returns the number of elements in this watchpoint list.
0163   ///
0164   /// \result
0165   ///     The number of elements.
0166   size_t GetSize() const {
0167     std::lock_guard<std::recursive_mutex> guard(m_mutex);
0168     return m_watchpoints.size();
0169   }
0170 
0171   /// Print a description of the watchpoints in this list to the stream \a s.
0172   ///
0173   /// \param[in] s
0174   ///     The stream to which to print the description.
0175   ///
0176   /// \param[in] level
0177   ///     The description level that indicates the detail level to
0178   ///     provide.
0179   ///
0180   /// \see lldb::DescriptionLevel
0181   void GetDescription(Stream *s, lldb::DescriptionLevel level);
0182 
0183   void SetEnabledAll(bool enabled);
0184 
0185   void RemoveAll(bool notify);
0186 
0187   /// Sets the passed in Locker to hold the Watchpoint List mutex.
0188   ///
0189   /// \param[in] lock
0190   ///   The locker object that is set.
0191   void GetListMutex(std::unique_lock<std::recursive_mutex> &lock);
0192 
0193   WatchpointIterable Watchpoints() const {
0194     return WatchpointIterable(m_watchpoints, m_mutex);
0195   }
0196 
0197 protected:
0198   typedef std::vector<lldb::watch_id_t> id_vector;
0199 
0200   id_vector GetWatchpointIDs() const;
0201 
0202   wp_collection::iterator GetIDIterator(lldb::watch_id_t watchID);
0203 
0204   wp_collection::const_iterator
0205   GetIDConstIterator(lldb::watch_id_t watchID) const;
0206 
0207   wp_collection m_watchpoints;
0208   mutable std::recursive_mutex m_mutex;
0209 
0210   lldb::watch_id_t m_next_wp_id = 0;
0211 };
0212 
0213 } // namespace lldb_private
0214 
0215 #endif // LLDB_BREAKPOINT_WATCHPOINTLIST_H