1 //===-- AddressRange.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_AddressRange_h_
11 #define liblldb_AddressRange_h_
13 #include "lldb/Core/Address.h"
14 #include "lldb/lldb-forward.h"
15 #include "lldb/lldb-types.h"
19 namespace lldb_private {
22 namespace lldb_private {
25 namespace lldb_private {
29 namespace lldb_private {
31 //----------------------------------------------------------------------
32 /// @class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
33 /// A section + offset based address range class.
34 //----------------------------------------------------------------------
37 //------------------------------------------------------------------
38 /// Default constructor.
40 /// Initialize with a invalid section (NULL), an invalid offset
41 /// (LLDB_INVALID_ADDRESS), and zero byte size.
42 //------------------------------------------------------------------
45 //------------------------------------------------------------------
46 /// Construct with a section pointer, offset, and byte_size.
48 /// Initialize the address with the supplied \a section, \a offset and \a
51 /// @param[in] section
52 /// A section pointer to a valid lldb::Section, or NULL if the
53 /// address doesn't have a section or will get resolved later.
56 /// The offset in bytes into \a section.
58 /// @param[in] byte_size
59 /// The size in bytes of the address range.
60 //------------------------------------------------------------------
61 AddressRange(const lldb::SectionSP §ion, lldb::addr_t offset,
62 lldb::addr_t byte_size);
64 //------------------------------------------------------------------
65 /// Construct with a virtual address, section list and byte size.
67 /// Initialize and resolve the address with the supplied virtual address \a
68 /// file_addr, and byte size \a byte_size.
70 /// @param[in] file_addr
71 /// A virtual address.
73 /// @param[in] byte_size
74 /// The size in bytes of the address range.
76 /// @param[in] section_list
77 /// A list of sections, one of which may contain the \a vaddr.
78 //------------------------------------------------------------------
79 AddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size,
80 const SectionList *section_list = nullptr);
82 //------------------------------------------------------------------
83 /// Construct with a Address object address and byte size.
85 /// Initialize by copying the section offset address in \a so_addr, and
86 /// setting the byte size to \a byte_size.
88 /// @param[in] so_addr
89 /// A section offset address object.
91 /// @param[in] byte_size
92 /// The size in bytes of the address range.
93 //------------------------------------------------------------------
94 AddressRange(const Address &so_addr, lldb::addr_t byte_size);
96 //------------------------------------------------------------------
99 /// The destructor is virtual in case this class is subclassed.
100 //------------------------------------------------------------------
103 //------------------------------------------------------------------
104 /// Clear the object's state.
106 /// Sets the section to an invalid value (NULL), an invalid offset
107 /// (LLDB_INVALID_ADDRESS) and a zero byte size.
108 //------------------------------------------------------------------
111 //------------------------------------------------------------------
112 /// Check if a section offset address is contained in this range.
114 /// @param[in] so_addr
115 /// A section offset address object reference.
118 /// Returns \b true if \a so_addr is contained in this range,
119 /// \b false otherwise.
120 //------------------------------------------------------------------
122 // Contains (const Address &so_addr) const;
124 //------------------------------------------------------------------
125 /// Check if a section offset address is contained in this range.
127 /// @param[in] so_addr_ptr
128 /// A section offset address object pointer.
131 /// Returns \b true if \a so_addr is contained in this range,
132 /// \b false otherwise.
133 //------------------------------------------------------------------
135 // Contains (const Address *so_addr_ptr) const;
137 //------------------------------------------------------------------
138 /// Check if a section offset \a so_addr when represented as a file address
139 /// is contained within this object's file address range.
141 /// @param[in] so_addr
142 /// A section offset address object reference.
145 /// Returns \b true if both \a this and \a so_addr have
146 /// resolvable file address values and \a so_addr is contained
147 /// in the address range, \b false otherwise.
148 //------------------------------------------------------------------
149 bool ContainsFileAddress(const Address &so_addr) const;
151 //------------------------------------------------------------------
152 /// Check if the resolved file address \a file_addr is contained within this
153 /// object's file address range.
155 /// @param[in] so_addr
156 /// A section offset address object reference.
159 /// Returns \b true if both \a this has a resolvable file
160 /// address value and \a so_addr is contained in the address
161 /// range, \b false otherwise.
162 //------------------------------------------------------------------
163 bool ContainsFileAddress(lldb::addr_t file_addr) const;
165 //------------------------------------------------------------------
166 /// Check if a section offset \a so_addr when represented as a load address
167 /// is contained within this object's load address range.
169 /// @param[in] so_addr
170 /// A section offset address object reference.
173 /// Returns \b true if both \a this and \a so_addr have
174 /// resolvable load address values and \a so_addr is contained
175 /// in the address range, \b false otherwise.
176 //------------------------------------------------------------------
177 bool ContainsLoadAddress(const Address &so_addr, Target *target) const;
179 //------------------------------------------------------------------
180 /// Check if the resolved load address \a load_addr is contained within this
181 /// object's load address range.
183 /// @param[in] so_addr
184 /// A section offset address object reference.
187 /// Returns \b true if both \a this has a resolvable load
188 /// address value and \a so_addr is contained in the address
189 /// range, \b false otherwise.
190 //------------------------------------------------------------------
191 bool ContainsLoadAddress(lldb::addr_t load_addr, Target *target) const;
193 //------------------------------------------------------------------
194 /// Dump a description of this object to a Stream.
196 /// Dump a description of the contents of this object to the supplied stream
197 /// \a s. There are many ways to display a section offset based address
198 /// range, and \a style lets the user choose how the base address gets
202 /// The stream to which to dump the object description.
205 /// The display style for the address.
208 /// Returns \b true if the address was able to be displayed.
209 /// File and load addresses may be unresolved and it may not be
210 /// possible to display a valid value, \b false will be returned
213 /// @see Address::DumpStyle
214 //------------------------------------------------------------------
216 Dump(Stream *s, Target *target, Address::DumpStyle style,
217 Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
219 //------------------------------------------------------------------
220 /// Dump a debug description of this object to a Stream.
222 /// Dump a debug description of the contents of this object to the supplied
225 /// The debug description contains verbose internal state such and pointer
226 /// values, reference counts, etc.
229 /// The stream to which to dump the object description.
230 //------------------------------------------------------------------
231 void DumpDebug(Stream *s) const;
233 //------------------------------------------------------------------
234 /// Get accessor for the base address of the range.
237 /// A reference to the base address object.
238 //------------------------------------------------------------------
239 Address &GetBaseAddress() { return m_base_addr; }
241 //------------------------------------------------------------------
242 /// Get const accessor for the base address of the range.
245 /// A const reference to the base address object.
246 //------------------------------------------------------------------
247 const Address &GetBaseAddress() const { return m_base_addr; }
249 //------------------------------------------------------------------
250 /// Get accessor for the byte size of this range.
253 /// The size in bytes of this address range.
254 //------------------------------------------------------------------
255 lldb::addr_t GetByteSize() const { return m_byte_size; }
257 //------------------------------------------------------------------
258 /// Get the memory cost of this object.
261 /// The number of bytes that this object occupies in memory.
262 //------------------------------------------------------------------
263 size_t MemorySize() const {
264 // Noting special for the memory size of a single AddressRange object, it
265 // is just the size of itself.
266 return sizeof(AddressRange);
269 //------------------------------------------------------------------
270 /// Set accessor for the byte size of this range.
272 /// @param[in] byte_size
273 /// The new size in bytes of this address range.
274 //------------------------------------------------------------------
275 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
278 //------------------------------------------------------------------
280 //------------------------------------------------------------------
281 Address m_base_addr; ///< The section offset base address of this range.
282 lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
285 // bool operator== (const AddressRange& lhs, const AddressRange& rhs);
287 } // namespace lldb_private
289 #endif // liblldb_AddressRange_h_