Home | History | Annotate | Download | only in Breakpoint
      1 //===-- BreakpointSiteList.h ------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef liblldb_BreakpointSiteList_h_
     11 #define liblldb_BreakpointSiteList_h_
     12 
     13 // C Includes
     14 // C++ Includes
     15 #include <map>
     16 // Other libraries and framework includes
     17 // Project includes
     18 #include "lldb/Breakpoint/BreakpointSite.h"
     19 #include "lldb/Host/Mutex.h"
     20 
     21 namespace lldb_private {
     22 
     23 //----------------------------------------------------------------------
     24 /// @class BreakpointSiteList BreakpointSiteList.h "lldb/Breakpoint/BreakpointSiteList.h"
     25 /// @brief Class that manages lists of BreakpointSite shared pointers.
     26 //----------------------------------------------------------------------
     27 class BreakpointSiteList
     28 {
     29 // At present Process directly accesses the map of BreakpointSites so it can
     30 // do quick lookups into the map (using GetMap).
     31 // FIXME: Find a better interface for this.
     32 friend class Process;
     33 
     34 public:
     35     //------------------------------------------------------------------
     36     /// Default constructor makes an empty list.
     37     //------------------------------------------------------------------
     38     BreakpointSiteList();
     39 
     40     //------------------------------------------------------------------
     41     /// Destructor, currently does nothing.
     42     //------------------------------------------------------------------
     43     ~BreakpointSiteList();
     44 
     45     //------------------------------------------------------------------
     46     /// Add a BreakpointSite to the list.
     47     ///
     48     /// @param[in] bp_site_sp
     49     ///    A shared pointer to a breakpoint site being added to the list.
     50     ///
     51     /// @return
     52     ///    The ID of the BreakpointSite in the list.
     53     //------------------------------------------------------------------
     54     lldb::break_id_t
     55     Add (const lldb::BreakpointSiteSP& bp_site_sp);
     56 
     57     //------------------------------------------------------------------
     58     /// Standard Dump routine, doesn't do anything at present.
     59     /// @param[in] s
     60     ///     Stream into which to dump the description.
     61     //------------------------------------------------------------------
     62     void
     63     Dump (Stream *s) const;
     64 
     65     //------------------------------------------------------------------
     66     /// Returns a shared pointer to the breakpoint site at address
     67     /// \a addr.
     68     ///
     69     /// @param[in] addr
     70     ///     The address to look for.
     71     ///
     72     /// @result
     73     ///     A shared pointer to the breakpoint site. May contain a NULL
     74     ///     pointer if no breakpoint site exists with a matching address.
     75     //------------------------------------------------------------------
     76     lldb::BreakpointSiteSP
     77     FindByAddress (lldb::addr_t addr);
     78 
     79     //------------------------------------------------------------------
     80     /// Returns a shared pointer to the breakpoint site with id \a breakID.
     81     ///
     82     /// @param[in] breakID
     83     ///   The breakpoint site ID to seek for.
     84     ///
     85     /// @result
     86     ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if the
     87     ///   breakpoint doesn't exist.
     88     //------------------------------------------------------------------
     89     lldb::BreakpointSiteSP
     90     FindByID (lldb::break_id_t breakID);
     91 
     92     //------------------------------------------------------------------
     93     /// Returns a shared pointer to the breakpoint site with id \a breakID - const version.
     94     ///
     95     /// @param[in] breakID
     96     ///   The breakpoint site ID to seek for.
     97     ///
     98     /// @result
     99     ///   A shared pointer to the breakpoint site.  May contain a NULL pointer if the
    100     ///   breakpoint doesn't exist.
    101     //------------------------------------------------------------------
    102     const lldb::BreakpointSiteSP
    103     FindByID (lldb::break_id_t breakID) const;
    104 
    105     //------------------------------------------------------------------
    106     /// Returns the breakpoint site id to the breakpoint site at address \a addr.
    107     ///
    108     /// @param[in] addr
    109     ///   The address to match.
    110     ///
    111     /// @result
    112     ///   The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID.
    113     //------------------------------------------------------------------
    114     lldb::break_id_t
    115     FindIDByAddress (lldb::addr_t addr);
    116 
    117     //------------------------------------------------------------------
    118     /// Returns whether the breakpoint site \a bp_site_id has \a bp_id
    119     //  as one of its owners.
    120     ///
    121     /// @param[in] bp_site_id
    122     ///   The breakpoint site id to query.
    123     ///
    124     /// @param[in] bp_id
    125     ///   The breakpoint id to look for in \a bp_site_id.
    126     ///
    127     /// @result
    128     ///   True if \a bp_site_id exists in the site list AND \a bp_id is one of the
    129     ///   owners of that site.
    130     //------------------------------------------------------------------
    131     bool
    132     BreakpointSiteContainsBreakpoint (lldb::break_id_t bp_site_id, lldb::break_id_t bp_id);
    133 
    134     void
    135     ForEach (std::function <void(BreakpointSite *)> const &callback);
    136 
    137     //------------------------------------------------------------------
    138     /// Removes the breakpoint site given by \b breakID from this list.
    139     ///
    140     /// @param[in] breakID
    141     ///   The breakpoint site index to remove.
    142     ///
    143     /// @result
    144     ///   \b true if the breakpoint site \a breakID was in the list.
    145     //------------------------------------------------------------------
    146     bool
    147     Remove (lldb::break_id_t breakID);
    148 
    149     //------------------------------------------------------------------
    150     /// Removes the breakpoint site at address \a addr from this list.
    151     ///
    152     /// @param[in] addr
    153     ///   The address from which to remove a breakpoint site.
    154     ///
    155     /// @result
    156     ///   \b true if \a addr had a breakpoint site to remove from the list.
    157     //------------------------------------------------------------------
    158     bool
    159     RemoveByAddress (lldb::addr_t addr);
    160 
    161     bool
    162     FindInRange (lldb::addr_t lower_bound, lldb::addr_t upper_bound, BreakpointSiteList &bp_site_list) const;
    163 
    164     typedef void (*BreakpointSiteSPMapFunc) (lldb::BreakpointSiteSP &bp, void *baton);
    165 
    166     //------------------------------------------------------------------
    167     /// Enquires of the breakpoint site on in this list with ID \a breakID whether
    168     /// we should stop for the breakpoint or not.
    169     ///
    170     /// @param[in] context
    171     ///    This contains the information about this stop.
    172     ///
    173     /// @param[in] breakID
    174     ///    This break ID that we hit.
    175     ///
    176     /// @return
    177     ///    \b true if we should stop, \b false otherwise.
    178     //------------------------------------------------------------------
    179     bool
    180     ShouldStop (StoppointCallbackContext *context, lldb::break_id_t breakID);
    181 
    182     //------------------------------------------------------------------
    183     /// Returns the number of elements in the list.
    184     ///
    185     /// @result
    186     ///   The number of elements.
    187     //------------------------------------------------------------------
    188     size_t
    189     GetSize() const
    190     {
    191         Mutex::Locker locker(m_mutex);
    192         return m_bp_site_list.size();
    193     }
    194 
    195     bool
    196     IsEmpty() const
    197     {
    198         Mutex::Locker locker(m_mutex);
    199         return m_bp_site_list.empty();
    200     }
    201 protected:
    202     typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection;
    203 
    204     collection::iterator
    205     GetIDIterator(lldb::break_id_t breakID);
    206 
    207     collection::const_iterator
    208     GetIDConstIterator(lldb::break_id_t breakID) const;
    209 
    210     mutable Mutex m_mutex;
    211     collection m_bp_site_list;  // The breakpoint site list.
    212 };
    213 
    214 } // namespace lldb_private
    215 
    216 #endif  // liblldb_BreakpointSiteList_h_
    217