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 //----------------------------------------------------------------------
28 //------------------------------------------------------------------
29 /// Default constructor.
31 /// Initialize with a invalid section (NULL), an invalid
32 /// offset (LLDB_INVALID_ADDRESS), and zero byte size.
33 //------------------------------------------------------------------
36 //------------------------------------------------------------------
37 /// Construct with a section pointer, offset, and byte_size.
39 /// Initialize the address with the supplied \a section, \a
40 /// offset and \a byte_size.
42 /// @param[in] section
43 /// A section pointer to a valid lldb::Section, or NULL if the
44 /// address doesn't have a section or will get resolved later.
47 /// The offset in bytes into \a section.
49 /// @param[in] byte_size
50 /// The size in bytes of the address range.
51 //------------------------------------------------------------------
52 AddressRange (const lldb::SectionSP §ion, lldb::addr_t offset, 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, const SectionList *section_list = nullptr);
71 //------------------------------------------------------------------
72 /// Construct with a Address object address and byte size.
74 /// Initialize by copying the section offset address in \a so_addr,
75 /// and setting the byte size to \a byte_size.
77 /// @param[in] so_addr
78 /// A section offset address object.
80 /// @param[in] byte_size
81 /// The size in bytes of the address range.
82 //------------------------------------------------------------------
83 AddressRange (const Address& so_addr, lldb::addr_t byte_size);
85 //------------------------------------------------------------------
88 /// The destructor is virtual in case this class is subclassed.
89 //------------------------------------------------------------------
92 //------------------------------------------------------------------
93 /// Clear the object's state.
95 /// Sets the section to an invalid value (NULL), an invalid offset
96 /// (LLDB_INVALID_ADDRESS) and a zero byte size.
97 //------------------------------------------------------------------
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 //------------------------------------------------------------------
140 ContainsFileAddress (const Address &so_addr) const;
142 //------------------------------------------------------------------
143 /// Check if the resolved file address \a file_addr is contained
144 /// within this object's file address range.
146 /// @param[in] so_addr
147 /// A section offset address object reference.
150 /// Returns \b true if both \a this has a resolvable file
151 /// address value and \a so_addr is contained in the address
152 /// range, \b false otherwise.
153 //------------------------------------------------------------------
155 ContainsFileAddress (lldb::addr_t file_addr) const;
157 //------------------------------------------------------------------
158 /// Check if a section offset \a so_addr when represented as a load
159 /// address is contained within this object's load address range.
161 /// @param[in] so_addr
162 /// A section offset address object reference.
165 /// Returns \b true if both \a this and \a so_addr have
166 /// resolvable load address values and \a so_addr is contained
167 /// in the address range, \b false otherwise.
168 //------------------------------------------------------------------
170 ContainsLoadAddress (const Address &so_addr, Target *target) const;
172 //------------------------------------------------------------------
173 /// Check if the resolved load address \a load_addr is contained
174 /// within this object's load address range.
176 /// @param[in] so_addr
177 /// A section offset address object reference.
180 /// Returns \b true if both \a this has a resolvable load
181 /// address value and \a so_addr is contained in the address
182 /// range, \b false otherwise.
183 //------------------------------------------------------------------
185 ContainsLoadAddress (lldb::addr_t load_addr, Target *target) const;
187 //------------------------------------------------------------------
188 /// Dump a description of this object to a Stream.
190 /// Dump a description of the contents of this object to the
191 /// supplied stream \a s. There are many ways to display a section
192 /// offset based address range, and \a style lets the user choose
193 /// how the base address gets displayed.
196 /// The stream to which to dump the object description.
199 /// The display style for the address.
202 /// Returns \b true if the address was able to be displayed.
203 /// File and load addresses may be unresolved and it may not be
204 /// possible to display a valid value, \b false will be returned
207 /// @see Address::DumpStyle
208 //------------------------------------------------------------------
210 Dump (Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
212 //------------------------------------------------------------------
213 /// Dump a debug description of this object to a Stream.
215 /// Dump a debug description of the contents of this object to the
216 /// supplied stream \a s.
218 /// The debug description contains verbose internal state such
219 /// and pointer values, reference counts, etc.
222 /// The stream to which to dump the object description.
223 //------------------------------------------------------------------
225 DumpDebug (Stream *s) const;
227 //------------------------------------------------------------------
228 /// Get accessor for the base address of the range.
231 /// A reference to the base address object.
232 //------------------------------------------------------------------
234 GetBaseAddress() { return m_base_addr; }
236 //------------------------------------------------------------------
237 /// Get const accessor for the base address of the range.
240 /// A const reference to the base address object.
241 //------------------------------------------------------------------
243 GetBaseAddress() const { return m_base_addr; }
245 //------------------------------------------------------------------
246 /// Get accessor for the byte size of this range.
249 /// The size in bytes of this address range.
250 //------------------------------------------------------------------
252 GetByteSize () const { return m_byte_size; }
254 //------------------------------------------------------------------
255 /// Get the memory cost of this object.
258 /// The number of bytes that this object occupies in memory.
259 //------------------------------------------------------------------
261 MemorySize () const {
262 // Noting special for the memory size of a single AddressRange object,
263 // it is just the size of itself.
264 return sizeof(AddressRange);
267 //------------------------------------------------------------------
268 /// Set accessor for the byte size of this range.
270 /// @param[in] byte_size
271 /// The new size in bytes of this address range.
272 //------------------------------------------------------------------
274 SetByteSize (lldb::addr_t byte_size) { m_byte_size = byte_size; }
277 //------------------------------------------------------------------
279 //------------------------------------------------------------------
280 Address m_base_addr; ///< The section offset base address of this range.
281 lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
284 //bool operator== (const AddressRange& lhs, const AddressRange& rhs);
286 } // namespace lldb_private
288 #endif // liblldb_AddressRange_h_