Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- BreakpointLocationList.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_BREAKPOINTLOCATIONLIST_H
0010 #define LLDB_BREAKPOINT_BREAKPOINTLOCATIONLIST_H
0011 
0012 #include <map>
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 BreakpointLocationList BreakpointLocationList.h
0023 /// "lldb/Breakpoint/BreakpointLocationList.h" This class is used by
0024 /// Breakpoint to manage a list of breakpoint locations, each breakpoint
0025 /// location in the list has a unique ID, and is unique by Address as well.
0026 class BreakpointLocationList {
0027   // Only Breakpoints can make the location list, or add elements to it. This
0028   // is not just some random collection of locations.  Rather, the act of
0029   // adding the location to this list sets its ID, and implicitly all the
0030   // locations have the same breakpoint ID as well.  If you need a generic
0031   // container for breakpoint locations, use BreakpointLocationCollection.
0032   friend class Breakpoint;
0033 
0034 public:
0035   virtual ~BreakpointLocationList();
0036 
0037   /// Standard "Dump" method.  At present it does nothing.
0038   void Dump(Stream *s) const;
0039 
0040   /// Returns a shared pointer to the breakpoint location at address \a addr -
0041   /// const version.
0042   ///
0043   /// \param[in] addr
0044   ///     The address to look for.
0045   ///
0046   /// \result
0047   ///     A shared pointer to the breakpoint. May contain a nullptr
0048   ///     pointer if the breakpoint doesn't exist.
0049   const lldb::BreakpointLocationSP FindByAddress(const Address &addr) const;
0050 
0051   /// Returns a shared pointer to the breakpoint location with id \a breakID,
0052   /// const version.
0053   ///
0054   /// \param[in] breakID
0055   ///     The breakpoint location ID to seek for.
0056   ///
0057   /// \result
0058   ///     A shared pointer to the breakpoint. May contain a nullptr
0059   ///     pointer if the breakpoint doesn't exist.
0060   lldb::BreakpointLocationSP FindByID(lldb::break_id_t breakID) const;
0061 
0062   /// Returns the breakpoint location id to the breakpoint location at address
0063   /// \a addr.
0064   ///
0065   /// \param[in] addr
0066   ///     The address to match.
0067   ///
0068   /// \result
0069   ///     The ID of the breakpoint location, or LLDB_INVALID_BREAK_ID.
0070   lldb::break_id_t FindIDByAddress(const Address &addr);
0071 
0072   /// Returns a breakpoint location list of the breakpoint locations in the
0073   /// module \a module.  This list is allocated, and owned by the caller.
0074   ///
0075   /// \param[in] module
0076   ///     The module to seek in.
0077   ///
0078   /// \param[in] bp_loc_list
0079   ///     A breakpoint collection that gets any breakpoint locations
0080   ///     that match \a module appended to.
0081   ///
0082   /// \result
0083   ///     The number of matches
0084   size_t FindInModule(Module *module,
0085                       BreakpointLocationCollection &bp_loc_list);
0086 
0087   /// Returns a shared pointer to the breakpoint location with index \a i.
0088   ///
0089   /// \param[in] i
0090   ///     The breakpoint location index to seek for.
0091   ///
0092   /// \result
0093   ///     A shared pointer to the breakpoint. May contain a nullptr
0094   ///     pointer if the breakpoint doesn't exist.
0095   lldb::BreakpointLocationSP GetByIndex(size_t i);
0096 
0097   /// Returns a shared pointer to the breakpoint location with index \a i,
0098   /// const version.
0099   ///
0100   /// \param[in] i
0101   ///     The breakpoint location index to seek for.
0102   ///
0103   /// \result
0104   ///     A shared pointer to the breakpoint. May contain a nullptr
0105   ///     pointer if the breakpoint doesn't exist.
0106   const lldb::BreakpointLocationSP GetByIndex(size_t i) const;
0107 
0108   /// Removes all the locations in this list from their breakpoint site owners
0109   /// list.
0110   void ClearAllBreakpointSites();
0111 
0112   /// Tells all the breakpoint locations in this list to attempt to resolve
0113   /// any possible breakpoint sites.
0114   void ResolveAllBreakpointSites();
0115 
0116   /// Returns the number of breakpoint locations in this list with resolved
0117   /// breakpoints.
0118   ///
0119   /// \result
0120   ///     Number of qualifying breakpoint locations.
0121   size_t GetNumResolvedLocations() const;
0122 
0123   /// Returns the number hit count of all locations in this list.
0124   ///
0125   /// \result
0126   ///     Hit count of all locations in this list.
0127   uint32_t GetHitCount() const;
0128 
0129   /// Resets the hit count of all locations in this list.
0130   void ResetHitCount();
0131 
0132   /// Enquires of the breakpoint location in this list with ID \a breakID
0133   /// whether we should stop.
0134   ///
0135   /// \param[in] context
0136   ///     This contains the information about this stop.
0137   ///
0138   /// \param[in] breakID
0139   ///     This break ID that we hit.
0140   ///
0141   /// \return
0142   ///     \b true if we should stop, \b false otherwise.
0143   bool ShouldStop(StoppointCallbackContext *context, lldb::break_id_t breakID);
0144 
0145   /// Returns the number of elements in this breakpoint location list.
0146   ///
0147   /// \result
0148   ///     The number of elements.
0149   size_t GetSize() const { return m_locations.size(); }
0150 
0151   /// Print a description of the breakpoint locations in this list to the
0152   /// stream \a s.
0153   ///
0154   /// \param[in] s
0155   ///     The stream to which to print the description.
0156   ///
0157   /// \param[in] level
0158   ///     The description level that indicates the detail level to
0159   ///     provide.
0160   ///
0161   /// \see lldb::DescriptionLevel
0162   void GetDescription(Stream *s, lldb::DescriptionLevel level);
0163 
0164 protected:
0165   /// This is the standard constructor.
0166   ///
0167   /// It creates an empty breakpoint location list. It is protected here
0168   /// because only Breakpoints are allowed to create the breakpoint location
0169   /// list.
0170   BreakpointLocationList(Breakpoint &owner);
0171 
0172   lldb::BreakpointLocationSP Create(const Address &addr,
0173                                     bool resolve_indirect_symbols);
0174 
0175   void StartRecordingNewLocations(BreakpointLocationCollection &new_locations);
0176 
0177   void StopRecordingNewLocations();
0178 
0179   lldb::BreakpointLocationSP AddLocation(const Address &addr,
0180                                          bool resolve_indirect_symbols,
0181                                          bool *new_location = nullptr);
0182 
0183   void SwapLocation(lldb::BreakpointLocationSP to_location_sp,
0184                     lldb::BreakpointLocationSP from_location_sp);
0185 
0186   bool RemoveLocation(const lldb::BreakpointLocationSP &bp_loc_sp);
0187 
0188   void RemoveLocationByIndex(size_t idx);
0189 
0190   void RemoveInvalidLocations(const ArchSpec &arch);
0191 
0192   void Compact();
0193 
0194   typedef std::vector<lldb::BreakpointLocationSP> collection;
0195   typedef std::map<lldb_private::Address, lldb::BreakpointLocationSP,
0196                    Address::ModulePointerAndOffsetLessThanFunctionObject>
0197       addr_map;
0198 
0199   Breakpoint &m_owner;
0200   collection m_locations; // Vector of locations, sorted by ID
0201   addr_map m_address_to_location;
0202   mutable std::recursive_mutex m_mutex;
0203   lldb::break_id_t m_next_id;
0204   BreakpointLocationCollection *m_new_location_recorder;
0205 
0206 public:
0207   typedef AdaptedIterable<collection, lldb::BreakpointLocationSP,
0208                           vector_adapter>
0209       BreakpointLocationIterable;
0210 
0211   BreakpointLocationIterable BreakpointLocations() {
0212     return BreakpointLocationIterable(m_locations);
0213   }
0214 };
0215 
0216 } // namespace lldb_private
0217 
0218 #endif // LLDB_BREAKPOINT_BREAKPOINTLOCATIONLIST_H