1254721Semaste//===-- BreakpointSiteList.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_BreakpointSiteList_h_ 10254721Semaste#define liblldb_BreakpointSiteList_h_ 11254721Semaste 12309124Sdim#include <functional> 13254721Semaste#include <map> 14309124Sdim#include <mutex> 15309124Sdim 16254721Semaste#include "lldb/Breakpoint/BreakpointSite.h" 17254721Semaste 18254721Semastenamespace lldb_private { 19254721Semaste 20353358Sdim/// \class BreakpointSiteList BreakpointSiteList.h 21341825Sdim/// "lldb/Breakpoint/BreakpointSiteList.h" Class that manages lists of 22341825Sdim/// BreakpointSite shared pointers. 23314564Sdimclass BreakpointSiteList { 24314564Sdim // At present Process directly accesses the map of BreakpointSites so it can 25314564Sdim // do quick lookups into the map (using GetMap). 26314564Sdim // FIXME: Find a better interface for this. 27314564Sdim friend class Process; 28254721Semaste 29254721Semastepublic: 30314564Sdim /// Default constructor makes an empty list. 31314564Sdim BreakpointSiteList(); 32254721Semaste 33314564Sdim /// Destructor, currently does nothing. 34314564Sdim ~BreakpointSiteList(); 35254721Semaste 36314564Sdim /// Add a BreakpointSite to the list. 37314564Sdim /// 38353358Sdim /// \param[in] bp_site_sp 39314564Sdim /// A shared pointer to a breakpoint site being added to the list. 40314564Sdim /// 41353358Sdim /// \return 42314564Sdim /// The ID of the BreakpointSite in the list. 43314564Sdim lldb::break_id_t Add(const lldb::BreakpointSiteSP &bp_site_sp); 44254721Semaste 45353358Sdim /// Standard Dump routine, doesn't do anything at present. \param[in] s 46314564Sdim /// Stream into which to dump the description. 47314564Sdim void Dump(Stream *s) const; 48254721Semaste 49341825Sdim /// Returns a shared pointer to the breakpoint site at address \a addr. 50314564Sdim /// 51353358Sdim /// \param[in] addr 52314564Sdim /// The address to look for. 53314564Sdim /// 54353358Sdim /// \result 55314564Sdim /// A shared pointer to the breakpoint site. May contain a NULL 56314564Sdim /// pointer if no breakpoint site exists with a matching address. 57314564Sdim lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr); 58254721Semaste 59314564Sdim /// Returns a shared pointer to the breakpoint site with id \a breakID. 60314564Sdim /// 61353358Sdim /// \param[in] breakID 62314564Sdim /// The breakpoint site ID to seek for. 63314564Sdim /// 64353358Sdim /// \result 65314564Sdim /// A shared pointer to the breakpoint site. May contain a NULL pointer if 66314564Sdim /// the 67314564Sdim /// breakpoint doesn't exist. 68314564Sdim lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID); 69254721Semaste 70341825Sdim /// Returns a shared pointer to the breakpoint site with id \a breakID - 71341825Sdim /// const version. 72314564Sdim /// 73353358Sdim /// \param[in] breakID 74314564Sdim /// The breakpoint site ID to seek for. 75314564Sdim /// 76353358Sdim /// \result 77314564Sdim /// A shared pointer to the breakpoint site. May contain a NULL pointer if 78314564Sdim /// the 79314564Sdim /// breakpoint doesn't exist. 80314564Sdim const lldb::BreakpointSiteSP FindByID(lldb::break_id_t breakID) const; 81254721Semaste 82341825Sdim /// Returns the breakpoint site id to the breakpoint site at address \a 83341825Sdim /// addr. 84314564Sdim /// 85353358Sdim /// \param[in] addr 86314564Sdim /// The address to match. 87314564Sdim /// 88353358Sdim /// \result 89314564Sdim /// The ID of the breakpoint site, or LLDB_INVALID_BREAK_ID. 90314564Sdim lldb::break_id_t FindIDByAddress(lldb::addr_t addr); 91254721Semaste 92314564Sdim /// Returns whether the breakpoint site \a bp_site_id has \a bp_id 93314564Sdim // as one of its owners. 94314564Sdim /// 95353358Sdim /// \param[in] bp_site_id 96314564Sdim /// The breakpoint site id to query. 97314564Sdim /// 98353358Sdim /// \param[in] bp_id 99314564Sdim /// The breakpoint id to look for in \a bp_site_id. 100314564Sdim /// 101353358Sdim /// \result 102314564Sdim /// True if \a bp_site_id exists in the site list AND \a bp_id is one of the 103314564Sdim /// owners of that site. 104314564Sdim bool BreakpointSiteContainsBreakpoint(lldb::break_id_t bp_site_id, 105314564Sdim lldb::break_id_t bp_id); 106254721Semaste 107314564Sdim void ForEach(std::function<void(BreakpointSite *)> const &callback); 108254721Semaste 109314564Sdim /// Removes the breakpoint site given by \b breakID from this list. 110314564Sdim /// 111353358Sdim /// \param[in] breakID 112314564Sdim /// The breakpoint site index to remove. 113314564Sdim /// 114353358Sdim /// \result 115314564Sdim /// \b true if the breakpoint site \a breakID was in the list. 116314564Sdim bool Remove(lldb::break_id_t breakID); 117254721Semaste 118314564Sdim /// Removes the breakpoint site at address \a addr from this list. 119314564Sdim /// 120353358Sdim /// \param[in] addr 121314564Sdim /// The address from which to remove a breakpoint site. 122314564Sdim /// 123353358Sdim /// \result 124314564Sdim /// \b true if \a addr had a breakpoint site to remove from the list. 125314564Sdim bool RemoveByAddress(lldb::addr_t addr); 126254721Semaste 127314564Sdim bool FindInRange(lldb::addr_t lower_bound, lldb::addr_t upper_bound, 128314564Sdim BreakpointSiteList &bp_site_list) const; 129254721Semaste 130314564Sdim typedef void (*BreakpointSiteSPMapFunc)(lldb::BreakpointSiteSP &bp, 131314564Sdim void *baton); 132254721Semaste 133341825Sdim /// Enquires of the breakpoint site on in this list with ID \a breakID 134341825Sdim /// whether we should stop for the breakpoint or not. 135314564Sdim /// 136353358Sdim /// \param[in] context 137314564Sdim /// This contains the information about this stop. 138314564Sdim /// 139353358Sdim /// \param[in] breakID 140314564Sdim /// This break ID that we hit. 141314564Sdim /// 142353358Sdim /// \return 143314564Sdim /// \b true if we should stop, \b false otherwise. 144314564Sdim bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID); 145309124Sdim 146314564Sdim /// Returns the number of elements in the list. 147314564Sdim /// 148353358Sdim /// \result 149314564Sdim /// The number of elements. 150314564Sdim size_t GetSize() const { 151314564Sdim std::lock_guard<std::recursive_mutex> guard(m_mutex); 152314564Sdim return m_bp_site_list.size(); 153314564Sdim } 154314564Sdim 155314564Sdim bool IsEmpty() const { 156314564Sdim std::lock_guard<std::recursive_mutex> guard(m_mutex); 157314564Sdim return m_bp_site_list.empty(); 158314564Sdim } 159314564Sdim 160254721Semasteprotected: 161314564Sdim typedef std::map<lldb::addr_t, lldb::BreakpointSiteSP> collection; 162254721Semaste 163314564Sdim collection::iterator GetIDIterator(lldb::break_id_t breakID); 164254721Semaste 165314564Sdim collection::const_iterator GetIDConstIterator(lldb::break_id_t breakID) const; 166254721Semaste 167314564Sdim mutable std::recursive_mutex m_mutex; 168314564Sdim collection m_bp_site_list; // The breakpoint site list. 169254721Semaste}; 170254721Semaste 171254721Semaste} // namespace lldb_private 172254721Semaste 173314564Sdim#endif // liblldb_BreakpointSiteList_h_ 174