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"
15 namespace lldb_private {
17 //----------------------------------------------------------------------
18 /// @class AddressRange AddressRange.h "lldb/Core/AddressRange.h"
19 /// @brief A section + offset based address range class.
20 //----------------------------------------------------------------------
24 //------------------------------------------------------------------
25 /// Default constructor.
27 /// Initialize with a invalid section (NULL), an invalid
28 /// offset (LLDB_INVALID_ADDRESS), and zero byte size.
29 //------------------------------------------------------------------
32 //------------------------------------------------------------------
33 /// Construct with a section pointer, offset, and byte_size.
35 /// Initialize the address with the supplied \a section, \a
36 /// offset and \a byte_size.
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 //------------------------------------------------------------------
48 AddressRange (const lldb::SectionSP §ion, lldb::addr_t offset, lldb::addr_t byte_size);
50 //------------------------------------------------------------------
51 /// Construct with a virtual address, section list and byte size.
53 /// Initialize and resolve the address with the supplied virtual
54 /// address \a file_addr, and byte size \a byte_size.
56 /// @param[in] file_addr
57 /// A virtual address.
59 /// @param[in] byte_size
60 /// The size in bytes of the address range.
62 /// @param[in] section_list
63 /// A list of sections, one of which may contain the \a vaddr.
64 //------------------------------------------------------------------
65 AddressRange (lldb::addr_t file_addr, lldb::addr_t byte_size, const SectionList *section_list = NULL);
67 //------------------------------------------------------------------
68 /// Construct with a Address object address and byte size.
70 /// Initialize by copying the section offset address in \a so_addr,
71 /// and setting the byte size to \a byte_size.
73 /// @param[in] so_addr
74 /// A section offset address object.
76 /// @param[in] byte_size
77 /// The size in bytes of the address range.
78 //------------------------------------------------------------------
79 AddressRange (const Address& so_addr, lldb::addr_t byte_size);
81 //------------------------------------------------------------------
84 /// The destructor is virtual in case this class is subclassed.
85 //------------------------------------------------------------------
88 //------------------------------------------------------------------
89 /// Clear the object's state.
91 /// Sets the section to an invalid value (NULL), an invalid offset
92 /// (LLDB_INVALID_ADDRESS) and a zero byte size.
93 //------------------------------------------------------------------
97 //------------------------------------------------------------------
98 /// Check if a section offset address is contained in this range.
100 /// @param[in] so_addr
101 /// A section offset address object reference.
104 /// Returns \b true if \a so_addr is contained in this range,
105 /// \b false otherwise.
106 //------------------------------------------------------------------
108 // Contains (const Address &so_addr) const;
110 //------------------------------------------------------------------
111 /// Check if a section offset address is contained in this range.
113 /// @param[in] so_addr_ptr
114 /// A section offset address object pointer.
117 /// Returns \b true if \a so_addr is contained in this range,
118 /// \b false otherwise.
119 //------------------------------------------------------------------
121 // Contains (const Address *so_addr_ptr) const;
123 //------------------------------------------------------------------
124 /// Check if a section offset \a so_addr when represented as a file
125 /// address is contained within this object's file address range.
127 /// @param[in] so_addr
128 /// A section offset address object reference.
131 /// Returns \b true if both \a this and \a so_addr have
132 /// resolvable file address values and \a so_addr is contained
133 /// in the address range, \b false otherwise.
134 //------------------------------------------------------------------
136 ContainsFileAddress (const Address &so_addr) const;
138 //------------------------------------------------------------------
139 /// Check if the resolved file address \a file_addr is contained
140 /// within this object's file address range.
142 /// @param[in] so_addr
143 /// A section offset address object reference.
146 /// Returns \b true if both \a this has a resolvable file
147 /// address value and \a so_addr is contained in the address
148 /// range, \b false otherwise.
149 //------------------------------------------------------------------
151 ContainsFileAddress (lldb::addr_t file_addr) const;
153 //------------------------------------------------------------------
154 /// Check if a section offset \a so_addr when represented as a load
155 /// address is contained within this object's load address range.
157 /// @param[in] so_addr
158 /// A section offset address object reference.
161 /// Returns \b true if both \a this and \a so_addr have
162 /// resolvable load address values and \a so_addr is contained
163 /// in the address range, \b false otherwise.
164 //------------------------------------------------------------------
166 ContainsLoadAddress (const Address &so_addr, Target *target) const;
168 //------------------------------------------------------------------
169 /// Check if the resolved load address \a load_addr is contained
170 /// within this object's load address range.
172 /// @param[in] so_addr
173 /// A section offset address object reference.
176 /// Returns \b true if both \a this has a resolvable load
177 /// address value and \a so_addr is contained in the address
178 /// range, \b false otherwise.
179 //------------------------------------------------------------------
181 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 descripton.
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, Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const;
208 //------------------------------------------------------------------
209 /// Dump a debug description of this object to a Stream.
211 /// Dump a debug description of the contents of this object to the
212 /// supplied stream \a s.
214 /// The debug description contains verbose internal state such
215 /// and pointer values, reference counts, etc.
218 /// The stream to which to dump the object descripton.
219 //------------------------------------------------------------------
221 DumpDebug (Stream *s) const;
223 //------------------------------------------------------------------
224 /// Get accessor for the base address of the range.
227 /// A reference to the base address object.
228 //------------------------------------------------------------------
230 GetBaseAddress() { return m_base_addr; }
232 //------------------------------------------------------------------
233 /// Get const accessor for the base address of the range.
236 /// A const reference to the base address object.
237 //------------------------------------------------------------------
239 GetBaseAddress() const { return m_base_addr; }
241 //------------------------------------------------------------------
242 /// Get accessor for the byte size of this range.
245 /// The size in bytes of this address range.
246 //------------------------------------------------------------------
248 GetByteSize () const { return m_byte_size; }
250 //------------------------------------------------------------------
251 /// Get the memory cost of this object.
254 /// The number of bytes that this object occupies in memory.
255 //------------------------------------------------------------------
257 MemorySize () const {
258 // Noting special for the memory size of a single AddressRange object,
259 // it is just the size of itself.
260 return sizeof(AddressRange);
263 //------------------------------------------------------------------
264 /// Set accessor for the byte size of this range.
266 /// @param[in] byte_size
267 /// The new size in bytes of this address range.
268 //------------------------------------------------------------------
270 SetByteSize (lldb::addr_t byte_size) { m_byte_size = byte_size; }
273 //------------------------------------------------------------------
275 //------------------------------------------------------------------
276 Address m_base_addr; ///< The section offset base address of this range.
277 lldb::addr_t m_byte_size; ///< The size in bytes of this address range.
280 //bool operator== (const AddressRange& lhs, const AddressRange& rhs);
282 } // namespace lldb_private
284 #endif // liblldb_AddressRange_h_