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_
15 // Other libraries and framework includes
17 #include "lldb/Core/Address.h"
19 namespace lldb_private {
21 //----------------------------------------------------------------------
22 /// @class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
23 /// @brief A section + offset based address range class.
24 //----------------------------------------------------------------------
27 //------------------------------------------------------------------
28 /// Default constructor.
30 /// Initialize with a invalid section (NULL), an invalid
31 /// offset (LLDB_INVALID_ADDRESS), and zero byte size.
32 //------------------------------------------------------------------
35 //------------------------------------------------------------------
36 /// Construct with a section pointer, offset, and byte_size.
38 /// Initialize the address with the supplied \a section, \a
39 /// offset and \a byte_size.
41 /// @param[in] section
42 /// A section pointer to a valid lldb::Section, or NULL if the
43 /// address doesn't have a section or will get resolved later.
46 /// The offset in bytes into \a section.
48 /// @param[in] byte_size
49 /// The size in bytes of the address range.
50 //------------------------------------------------------------------
51 AddressRange(const lldb::SectionSP §ion, lldb::addr_t offset,
52 lldb::addr_t byte_size);
54 //------------------------------------------------------------------
55 /// Construct with a virtual address, section list and byte size.
57 /// Initialize and resolve the address with the supplied virtual
58 /// address \a file_addr, and byte size \a byte_size.
60 /// @param[in] file_addr
61 /// A virtual address.
63 /// @param[in] byte_size
64 /// The size in bytes of the address range.
66 /// @param[in] section_list
67 /// A list of sections, one of which may contain the \a vaddr.
68 //------------------------------------------------------------------
69 AddressRange(lldb::addr_t file_addr, lldb::addr_t byte_size,
70 const SectionList *section_list = nullptr);
72 //------------------------------------------------------------------
73 /// Construct with a Address object address and byte size.
75 /// Initialize by copying the section offset address in \a so_addr,
76 /// and setting the byte size to \a byte_size.
78 /// @param[in] so_addr
79 /// A section offset address object.
81 /// @param[in] byte_size
82 /// The size in bytes of the address range.
83 //------------------------------------------------------------------
84 AddressRange(const Address &so_addr, lldb::addr_t byte_size);
86 //------------------------------------------------------------------
89 /// The destructor is virtual in case this class is subclassed.
90 //------------------------------------------------------------------
93 //------------------------------------------------------------------
94 /// Clear the object's state.
96 /// Sets the section to an invalid value (NULL), an invalid offset
97 /// (LLDB_INVALID_ADDRESS) and a zero byte size.
98 //------------------------------------------------------------------
101 //------------------------------------------------------------------
102 /// Check if a section offset address is contained in this range.
104 /// @param[in] so_addr
105 /// A section offset address object reference.
108 /// Returns \b true if \a so_addr is contained in this range,
109 /// \b false otherwise.
110 //------------------------------------------------------------------
112 // Contains (const Address &so_addr) const;
114 //------------------------------------------------------------------
115 /// Check if a section offset address is contained in this range.
117 /// @param[in] so_addr_ptr
118 /// A section offset address object pointer.
121 /// Returns \b true if \a so_addr is contained in this range,
122 /// \b false otherwise.
123 //------------------------------------------------------------------
125 // Contains (const Address *so_addr_ptr) const;
127 //------------------------------------------------------------------
128 /// Check if a section offset \a so_addr when represented as a file
129 /// address is contained within this object's file address range.
131 /// @param[in] so_addr
132 /// A section offset address object reference.
135 /// Returns \b true if both \a this and \a so_addr have
136 /// resolvable file address values and \a so_addr is contained
137 /// in the address range, \b false otherwise.
138 //------------------------------------------------------------------
139 bool ContainsFileAddress(const Address &so_addr) const;
141 //------------------------------------------------------------------
142 /// Check if the resolved file address \a file_addr is contained
143 /// within this object's file address range.
145 /// @param[in] so_addr
146 /// A section offset address object reference.
149 /// Returns \b true if both \a this has a resolvable file
150 /// address value and \a so_addr is contained in the address
151 /// range, \b false otherwise.
152 //------------------------------------------------------------------
153 bool ContainsFileAddress(lldb::addr_t file_addr) const;
155 //------------------------------------------------------------------
156 /// Check if a section offset \a so_addr when represented as a load
157 /// address is contained within this object's load address range.
159 /// @param[in] so_addr
160 /// A section offset address object reference.
163 /// Returns \b true if both \a this and \a so_addr have
164 /// resolvable load address values and \a so_addr is contained
165 /// in the address range, \b false otherwise.
166 //------------------------------------------------------------------
167 bool ContainsLoadAddress(const Address &so_addr, Target *target) const;
169 //------------------------------------------------------------------
170 /// Check if the resolved load address \a load_addr is contained
171 /// within this object's load address range.
173 /// @param[in] so_addr
174 /// A section offset address object reference.
177 /// Returns \b true if both \a this has a resolvable load
178 /// address value and \a so_addr is contained in the address
179 /// range, \b false otherwise.
180 //------------------------------------------------------------------
181 bool ContainsLoadAddress(lldb::addr_t load_addr, Target *target) const;
183 //------------------------------------------------------------------
184 /// Dump a description of this object to a Stream.
186 /// Dump a description of the contents of this object to the
187 /// supplied stream \a s. There are many ways to display a section
188 /// offset based address range, and \a style lets the user choose
189 /// how the base address gets displayed.
192 /// The stream to which to dump the object description.
195 /// The display style for the address.
198 /// Returns \b true if the address was able to be displayed.
199 /// File and load addresses may be unresolved and it may not be
200 /// possible to display a valid value, \b false will be returned
203 /// @see Address::DumpStyle
204 //------------------------------------------------------------------
206 Dump(Stream *s, Target *target, Address::DumpStyle style,
207 Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
209 //------------------------------------------------------------------
210 /// Dump a debug description of this object to a Stream.
212 /// Dump a debug description of the contents of this object to the
213 /// supplied stream \a s.
215 /// The debug description contains verbose internal state such
216 /// and pointer values, reference counts, etc.
219 /// The stream to which to dump the object description.
220 //------------------------------------------------------------------
221 void DumpDebug(Stream *s) const;
223 //------------------------------------------------------------------
224 /// Get accessor for the base address of the range.
227 /// A reference to the base address object.
228 //------------------------------------------------------------------
229 Address &GetBaseAddress() { return m_base_addr; }
231 //------------------------------------------------------------------
232 /// Get const accessor for the base address of the range.
235 /// A const reference to the base address object.
236 //------------------------------------------------------------------
237 const Address &GetBaseAddress() const { return m_base_addr; }
239 //------------------------------------------------------------------
240 /// Get accessor for the byte size of this range.
243 /// The size in bytes of this address range.
244 //------------------------------------------------------------------
245 lldb::addr_t GetByteSize() const { return m_byte_size; }
247 //------------------------------------------------------------------
248 /// Get the memory cost of this object.
251 /// The number of bytes that this object occupies in memory.
252 //------------------------------------------------------------------
253 size_t MemorySize() const {
254 // Noting special for the memory size of a single AddressRange object,
255 // it is just the size of itself.
256 return sizeof(AddressRange);
259 //------------------------------------------------------------------
260 /// Set accessor for the byte size of this range.
262 /// @param[in] byte_size
263 /// The new size in bytes of this address range.
264 //------------------------------------------------------------------
265 void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
268 //------------------------------------------------------------------
270 //------------------------------------------------------------------
271 Address m_base_addr; ///< The section offset base address of this range.
272 lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
275 // bool operator== (const AddressRange& lhs, const AddressRange& rhs);
277 } // namespace lldb_private
279 #endif // liblldb_AddressRange_h_