1 //===-- AddressRange.h ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_AddressRange_h_
10 #define liblldb_AddressRange_h_
12 #include "lldb/Core/Address.h"
13 #include "lldb/lldb-forward.h"
14 #include "lldb/lldb-types.h"
18 namespace lldb_private {
23 /// \class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
24 /// A section + offset based address range class.
27 /// Default constructor.
29 /// Initialize with a invalid section (NULL), an invalid offset
30 /// (LLDB_INVALID_ADDRESS), and zero byte size.
33 /// Construct with a section pointer, offset, and byte_size.
35 /// Initialize the address with the supplied \a section, \a offset and \a
38 /// \param[in] section
39 /// A section pointer to a valid lldb::Section, or NULL if the
40 /// address doesn't have a section or will get resolved later.
43 /// The offset in bytes into \a section.
45 /// \param[in] byte_size
46 /// The size in bytes of the address range.
47 AddressRange(const lldb::SectionSP §ion, lldb::addr_t offset,
48 lldb::addr_t byte_size);
50 /// Construct with a virtual address, section list and byte size.
52 /// Initialize and resolve the address with the supplied virtual address \a
53 /// file_addr, and byte size \a byte_size.
55 /// \param[in] file_addr
56 /// A virtual address.
58 /// \param[in] byte_size
59 /// The size in bytes of the address range.
61 /// \param[in] section_list
62 /// A list of sections, one of which may contain the \a vaddr.
63 AddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size,
64 const SectionList *section_list = nullptr);
66 /// Construct with a Address object address and byte size.
68 /// Initialize by copying the section offset address in \a so_addr, and
69 /// setting the byte size to \a byte_size.
71 /// \param[in] so_addr
72 /// A section offset address object.
74 /// \param[in] byte_size
75 /// The size in bytes of the address range.
76 AddressRange(const Address &so_addr, lldb::addr_t byte_size);
80 /// The destructor is virtual in case this class is subclassed.
83 /// Clear the object's state.
85 /// Sets the section to an invalid value (NULL), an invalid offset
86 /// (LLDB_INVALID_ADDRESS) and a zero byte size.
89 /// Check if a section offset address is contained in this range.
91 /// \param[in] so_addr
92 /// A section offset address object reference.
95 /// Returns \b true if \a so_addr is contained in this range,
96 /// \b false otherwise.
98 // Contains (const Address &so_addr) const;
100 /// Check if a section offset address is contained in this range.
102 /// \param[in] so_addr_ptr
103 /// A section offset address object pointer.
106 /// Returns \b true if \a so_addr is contained in this range,
107 /// \b false otherwise.
109 // Contains (const Address *so_addr_ptr) const;
111 /// Check if a section offset \a so_addr when represented as a file address
112 /// is contained within this object's file address range.
114 /// \param[in] so_addr
115 /// A section offset address object reference.
118 /// Returns \b true if both \a this and \a so_addr have
119 /// resolvable file address values and \a so_addr is contained
120 /// in the address range, \b false otherwise.
121 bool ContainsFileAddress(const Address &so_addr) const;
123 /// Check if the resolved file address \a file_addr is contained within this
124 /// object's file address range.
126 /// \param[in] so_addr
127 /// A section offset address object reference.
130 /// Returns \b true if both \a this has a resolvable file
131 /// address value and \a so_addr is contained in the address
132 /// range, \b false otherwise.
133 bool ContainsFileAddress(lldb::addr_t file_addr) const;
135 /// Check if a section offset \a so_addr when represented as a load address
136 /// is contained within this object's load address range.
138 /// \param[in] so_addr
139 /// A section offset address object reference.
142 /// Returns \b true if both \a this and \a so_addr have
143 /// resolvable load address values and \a so_addr is contained
144 /// in the address range, \b false otherwise.
145 bool ContainsLoadAddress(const Address &so_addr, Target *target) const;
147 /// Check if the resolved load address \a load_addr is contained within this
148 /// object's load address range.
150 /// \param[in] so_addr
151 /// A section offset address object reference.
154 /// Returns \b true if both \a this has a resolvable load
155 /// address value and \a so_addr is contained in the address
156 /// range, \b false otherwise.
157 bool ContainsLoadAddress(lldb::addr_t load_addr, Target *target) const;
159 //------------------------------------------------------------------
160 /// Extends this range with \b rhs_range if it overlaps this range on the
161 /// right side. The range overlaps on the right side if the base address
162 /// of \b rhs_range lies within this range or if it's contiguous on its
165 /// @param[in] rhs_range
166 /// The range to extend at the right side.
169 /// Returns \b true if this range was extended, \b false otherwise.
170 //------------------------------------------------------------------
171 bool Extend(const AddressRange &rhs_range);
173 /// Dump a description of this object to a Stream.
175 /// Dump a description of the contents of this object to the supplied stream
176 /// \a s. There are many ways to display a section offset based address
177 /// range, and \a style lets the user choose how the base address gets
181 /// The stream to which to dump the object description.
184 /// The display style for the address.
187 /// Returns \b true if the address was able to be displayed.
188 /// File and load addresses may be unresolved and it may not be
189 /// possible to display a valid value, \b false will be returned
192 /// \see Address::DumpStyle
194 Dump(Stream *s, Target *target, Address::DumpStyle style,
195 Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
197 /// Dump a debug description of this object to a Stream.
199 /// Dump a debug description of the contents of this object to the supplied
202 /// The debug description contains verbose internal state such and pointer
203 /// values, reference counts, etc.
206 /// The stream to which to dump the object description.
207 void DumpDebug(Stream *s) const;
209 /// Get accessor for the base address of the range.
212 /// A reference to the base address object.
213 Address &GetBaseAddress() { return m_base_addr; }
215 /// Get const accessor for the base address of the range.
218 /// A const reference to the base address object.
219 const Address &GetBaseAddress() const { return m_base_addr; }
221 /// Get accessor for the byte size of this range.
224 /// The size in bytes of this address range.
225 lldb::addr_t GetByteSize() const { return m_byte_size; }
227 /// Get the memory cost of this object.
230 /// The number of bytes that this object occupies in memory.
231 size_t MemorySize() const {
232 // Noting special for the memory size of a single AddressRange object, it
233 // is just the size of itself.
234 return sizeof(AddressRange);
237 /// Set accessor for the byte size of this range.
239 /// \param[in] byte_size
240 /// The new size in bytes of this address range.
241 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
245 Address m_base_addr; ///< The section offset base address of this range.
246 lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
249 // bool operator== (const AddressRange& lhs, const AddressRange& rhs);
251 } // namespace lldb_private
253 #endif // liblldb_AddressRange_h_