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