Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- AddressRange.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_CORE_ADDRESSRANGE_H
0010 #define LLDB_CORE_ADDRESSRANGE_H
0011 
0012 #include "lldb/Core/Address.h"
0013 #include "lldb/lldb-forward.h"
0014 #include "lldb/lldb-types.h"
0015 
0016 #include <cstddef>
0017 
0018 namespace lldb_private {
0019 class SectionList;
0020 class Stream;
0021 class Target;
0022 
0023 /// \class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
0024 /// A section + offset based address range class.
0025 class AddressRange {
0026 public:
0027   /// Default constructor.
0028   ///
0029   /// Initialize with a invalid section (NULL), an invalid offset
0030   /// (LLDB_INVALID_ADDRESS), and zero byte size.
0031   AddressRange();
0032 
0033   /// Construct with a section pointer, offset, and byte_size.
0034   ///
0035   /// Initialize the address with the supplied \a section, \a offset and \a
0036   /// byte_size.
0037   ///
0038   /// \param[in] section
0039   ///     A section pointer to a valid lldb::Section, or NULL if the
0040   ///     address doesn't have a section or will get resolved later.
0041   ///
0042   /// \param[in] offset
0043   ///     The offset in bytes into \a section.
0044   ///
0045   /// \param[in] byte_size
0046   ///     The size in bytes of the address range.
0047   AddressRange(const lldb::SectionSP &section, lldb::addr_t offset,
0048                lldb::addr_t byte_size);
0049 
0050   /// Construct with a virtual address, section list and byte size.
0051   ///
0052   /// Initialize and resolve the address with the supplied virtual address \a
0053   /// file_addr, and byte size \a byte_size.
0054   ///
0055   /// \param[in] file_addr
0056   ///     A virtual address.
0057   ///
0058   /// \param[in] byte_size
0059   ///     The size in bytes of the address range.
0060   ///
0061   /// \param[in] section_list
0062   ///     A list of sections, one of which may contain the \a vaddr.
0063   AddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size,
0064                const SectionList *section_list = nullptr);
0065 
0066   /// Construct with a Address object address and byte size.
0067   ///
0068   /// Initialize by copying the section offset address in \a so_addr, and
0069   /// setting the byte size to \a byte_size.
0070   ///
0071   /// \param[in] so_addr
0072   ///     A section offset address object.
0073   ///
0074   /// \param[in] byte_size
0075   ///     The size in bytes of the address range.
0076   AddressRange(const Address &so_addr, lldb::addr_t byte_size);
0077 
0078   /// Destructor.
0079   ///
0080   /// The destructor is virtual in case this class is subclassed.
0081   ~AddressRange();
0082 
0083   /// Clear the object's state.
0084   ///
0085   /// Sets the section to an invalid value (NULL), an invalid offset
0086   /// (LLDB_INVALID_ADDRESS) and a zero byte size.
0087   void Clear();
0088 
0089   bool IsValid() const;
0090 
0091   /// Check if a section offset address is contained in this range.
0092   ///
0093   /// \param[in] so_addr
0094   ///     A section offset address object reference.
0095   ///
0096   /// \return
0097   ///     Returns \b true if \a so_addr is contained in this range,
0098   ///     \b false otherwise.
0099   bool Contains(const Address &so_addr) const;
0100 
0101   /// Check if a section offset address is contained in this range.
0102   ///
0103   /// \param[in] so_addr_ptr
0104   ///     A section offset address object pointer.
0105   ///
0106   /// \return
0107   ///     Returns \b true if \a so_addr is contained in this range,
0108   ///     \b false otherwise.
0109   //    bool
0110   //    Contains (const Address *so_addr_ptr) const;
0111 
0112   /// Check if a section offset \a so_addr when represented as a file address
0113   /// is contained within this object's file address range.
0114   ///
0115   /// \param[in] so_addr
0116   ///     A section offset address object reference.
0117   ///
0118   /// \return
0119   ///     Returns \b true if both \a this and \a so_addr have
0120   ///     resolvable file address values and \a so_addr is contained
0121   ///     in the address range, \b false otherwise.
0122   bool ContainsFileAddress(const Address &so_addr) const;
0123 
0124   /// Check if the resolved file address \a file_addr is contained within this
0125   /// object's file address range.
0126   ///
0127   /// \param[in] file_addr
0128   ///     A section offset address object reference.
0129   ///
0130   /// \return
0131   ///     Returns \b true if both \a this has a resolvable file
0132   ///     address value and \a so_addr is contained in the address
0133   ///     range, \b false otherwise.
0134   bool ContainsFileAddress(lldb::addr_t file_addr) const;
0135 
0136   /// Check if a section offset \a so_addr when represented as a load address
0137   /// is contained within this object's load address range.
0138   ///
0139   /// \param[in] so_addr
0140   ///     A section offset address object reference.
0141   ///
0142   /// \return
0143   ///     Returns \b true if both \a this and \a so_addr have
0144   ///     resolvable load address values and \a so_addr is contained
0145   ///     in the address range, \b false otherwise.
0146   bool ContainsLoadAddress(const Address &so_addr, Target *target) const;
0147 
0148   /// Check if the resolved load address \a load_addr is contained within this
0149   /// object's load address range.
0150   ///
0151   /// \return
0152   ///     Returns \b true if both \a this has a resolvable load
0153   ///     address value and \a so_addr is contained in the address
0154   ///     range, \b false otherwise.
0155   bool ContainsLoadAddress(lldb::addr_t load_addr, Target *target) const;
0156 
0157   //------------------------------------------------------------------
0158   /// Extends this range with \b rhs_range if it overlaps this range on the
0159   /// right side. The range overlaps on the right side if the base address
0160   /// of \b rhs_range lies within this range or if it's contiguous on its
0161   /// right side.
0162   ///
0163   /// @param[in] rhs_range
0164   ///     The range to extend at the right side.
0165   ///
0166   /// @return
0167   ///     Returns \b true if this range was extended, \b false otherwise.
0168   //------------------------------------------------------------------
0169   bool Extend(const AddressRange &rhs_range);
0170 
0171   /// Dump a description of this object to a Stream.
0172   ///
0173   /// Dump a description of the contents of this object to the supplied stream
0174   /// \a s. There are many ways to display a section offset based address
0175   /// range, and \a style lets the user choose how the base address gets
0176   /// displayed.
0177   ///
0178   /// \param[in] s
0179   ///     The stream to which to dump the object description.
0180   ///
0181   /// \param[in] style
0182   ///     The display style for the address.
0183   ///
0184   /// \return
0185   ///     Returns \b true if the address was able to be displayed.
0186   ///     File and load addresses may be unresolved and it may not be
0187   ///     possible to display a valid value, \b false will be returned
0188   ///     in such cases.
0189   ///
0190   /// \see Address::DumpStyle
0191   bool
0192   Dump(Stream *s, Target *target, Address::DumpStyle style,
0193        Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
0194 
0195   /// Dump a debug description of this object to a Stream.
0196   ///
0197   /// Dump a debug description of the contents of this object to the supplied
0198   /// stream \a s.
0199   ///
0200   /// The debug description contains verbose internal state such and pointer
0201   /// values, reference counts, etc.
0202   ///
0203   /// \param[in] s
0204   ///     The stream to which to dump the object description.
0205   void DumpDebug(Stream *s) const;
0206 
0207   /// Get accessor for the base address of the range.
0208   ///
0209   /// \return
0210   ///     A reference to the base address object.
0211   Address &GetBaseAddress() { return m_base_addr; }
0212 
0213   /// Get const accessor for the base address of the range.
0214   ///
0215   /// \return
0216   ///     A const reference to the base address object.
0217   const Address &GetBaseAddress() const { return m_base_addr; }
0218 
0219   /// Get accessor for the byte size of this range.
0220   ///
0221   /// \return
0222   ///     The size in bytes of this address range.
0223   lldb::addr_t GetByteSize() const { return m_byte_size; }
0224 
0225   /// Get the memory cost of this object.
0226   ///
0227   /// \return
0228   ///     The number of bytes that this object occupies in memory.
0229   size_t MemorySize() const {
0230     // Noting special for the memory size of a single AddressRange object, it
0231     // is just the size of itself.
0232     return sizeof(AddressRange);
0233   }
0234 
0235   /// Set accessor for the byte size of this range.
0236   ///
0237   /// \param[in] byte_size
0238   ///     The new size in bytes of this address range.
0239   void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
0240 
0241   bool GetDescription(Stream *s, Target *target) const;
0242 
0243   bool operator==(const AddressRange &rhs);
0244 
0245   bool operator!=(const AddressRange &rhs);
0246 
0247 protected:
0248   // Member variables
0249   Address m_base_addr;      ///< The section offset base address of this range.
0250   lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
0251 };
0252 
0253 // Forward-declarable wrapper.
0254 class AddressRanges : public std::vector<lldb_private::AddressRange> {
0255 public:
0256   using std::vector<lldb_private::AddressRange>::vector;
0257 };
0258 
0259 } // namespace lldb_private
0260 
0261 #endif // LLDB_CORE_ADDRESSRANGE_H