1//===-- AddressRange.h ------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_AddressRange_h_ 11#define liblldb_AddressRange_h_ 12 13#include "lldb/Core/Address.h" 14 15namespace lldb_private { 16 17//---------------------------------------------------------------------- 18/// @class AddressRange AddressRange.h "lldb/Core/AddressRange.h" 19/// @brief A section + offset based address range class. 20//---------------------------------------------------------------------- 21class AddressRange 22{ 23public: 24 //------------------------------------------------------------------ 25 /// Default constructor. 26 /// 27 /// Initialize with a invalid section (NULL), an invalid 28 /// offset (LLDB_INVALID_ADDRESS), and zero byte size. 29 //------------------------------------------------------------------ 30 AddressRange (); 31 32 //------------------------------------------------------------------ 33 /// Construct with a section pointer, offset, and byte_size. 34 /// 35 /// Initialize the address with the supplied \a section, \a 36 /// offset and \a byte_size. 37 /// 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. 41 /// 42 /// @param[in] offset 43 /// The offset in bytes into \a section. 44 /// 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); 49 50 //------------------------------------------------------------------ 51 /// Construct with a virtual address, section list and byte size. 52 /// 53 /// Initialize and resolve the address with the supplied virtual 54 /// address \a file_addr, and byte size \a byte_size. 55 /// 56 /// @param[in] file_addr 57 /// A virtual address. 58 /// 59 /// @param[in] byte_size 60 /// The size in bytes of the address range. 61 /// 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); 66 67 //------------------------------------------------------------------ 68 /// Construct with a Address object address and byte size. 69 /// 70 /// Initialize by copying the section offset address in \a so_addr, 71 /// and setting the byte size to \a byte_size. 72 /// 73 /// @param[in] so_addr 74 /// A section offset address object. 75 /// 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); 80 81 //------------------------------------------------------------------ 82 /// Destructor. 83 /// 84 /// The destructor is virtual in case this class is subclassed. 85 //------------------------------------------------------------------ 86 ~AddressRange (); 87 88 //------------------------------------------------------------------ 89 /// Clear the object's state. 90 /// 91 /// Sets the section to an invalid value (NULL), an invalid offset 92 /// (LLDB_INVALID_ADDRESS) and a zero byte size. 93 //------------------------------------------------------------------ 94 void 95 Clear (); 96 97 //------------------------------------------------------------------ 98 /// Check if a section offset address is contained in this range. 99 /// 100 /// @param[in] so_addr 101 /// A section offset address object reference. 102 /// 103 /// @return 104 /// Returns \b true if \a so_addr is contained in this range, 105 /// \b false otherwise. 106 //------------------------------------------------------------------ 107// bool 108// Contains (const Address &so_addr) const; 109 110 //------------------------------------------------------------------ 111 /// Check if a section offset address is contained in this range. 112 /// 113 /// @param[in] so_addr_ptr 114 /// A section offset address object pointer. 115 /// 116 /// @return 117 /// Returns \b true if \a so_addr is contained in this range, 118 /// \b false otherwise. 119 //------------------------------------------------------------------ 120// bool 121// Contains (const Address *so_addr_ptr) const; 122 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. 126 /// 127 /// @param[in] so_addr 128 /// A section offset address object reference. 129 /// 130 /// @return 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 //------------------------------------------------------------------ 135 bool 136 ContainsFileAddress (const Address &so_addr) const; 137 138 //------------------------------------------------------------------ 139 /// Check if the resolved file address \a file_addr is contained 140 /// within this object's file address range. 141 /// 142 /// @param[in] so_addr 143 /// A section offset address object reference. 144 /// 145 /// @return 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 //------------------------------------------------------------------ 150 bool 151 ContainsFileAddress (lldb::addr_t file_addr) const; 152 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. 156 /// 157 /// @param[in] so_addr 158 /// A section offset address object reference. 159 /// 160 /// @return 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 //------------------------------------------------------------------ 165 bool 166 ContainsLoadAddress (const Address &so_addr, Target *target) const; 167 168 //------------------------------------------------------------------ 169 /// Check if the resolved load address \a load_addr is contained 170 /// within this object's load address range. 171 /// 172 /// @param[in] so_addr 173 /// A section offset address object reference. 174 /// 175 /// @return 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 //------------------------------------------------------------------ 180 bool 181 ContainsLoadAddress (lldb::addr_t load_addr, Target *target) const; 182 183 //------------------------------------------------------------------ 184 /// Dump a description of this object to a Stream. 185 /// 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. 190 /// 191 /// @param[in] s 192 /// The stream to which to dump the object descripton. 193 /// 194 /// @param[in] style 195 /// The display style for the address. 196 /// 197 /// @return 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 201 /// in such cases. 202 /// 203 /// @see Address::DumpStyle 204 //------------------------------------------------------------------ 205 bool 206 Dump (Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style = Address::DumpStyleInvalid) const; 207 208 //------------------------------------------------------------------ 209 /// Dump a debug description of this object to a Stream. 210 /// 211 /// Dump a debug description of the contents of this object to the 212 /// supplied stream \a s. 213 /// 214 /// The debug description contains verbose internal state such 215 /// and pointer values, reference counts, etc. 216 /// 217 /// @param[in] s 218 /// The stream to which to dump the object descripton. 219 //------------------------------------------------------------------ 220 void 221 DumpDebug (Stream *s) const; 222 223 //------------------------------------------------------------------ 224 /// Get accessor for the base address of the range. 225 /// 226 /// @return 227 /// A reference to the base address object. 228 //------------------------------------------------------------------ 229 Address & 230 GetBaseAddress() { return m_base_addr; } 231 232 //------------------------------------------------------------------ 233 /// Get const accessor for the base address of the range. 234 /// 235 /// @return 236 /// A const reference to the base address object. 237 //------------------------------------------------------------------ 238 const Address & 239 GetBaseAddress() const { return m_base_addr; } 240 241 //------------------------------------------------------------------ 242 /// Get accessor for the byte size of this range. 243 /// 244 /// @return 245 /// The size in bytes of this address range. 246 //------------------------------------------------------------------ 247 lldb::addr_t 248 GetByteSize () const { return m_byte_size; } 249 250 //------------------------------------------------------------------ 251 /// Get the memory cost of this object. 252 /// 253 /// @return 254 /// The number of bytes that this object occupies in memory. 255 //------------------------------------------------------------------ 256 size_t 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); 261 } 262 263 //------------------------------------------------------------------ 264 /// Set accessor for the byte size of this range. 265 /// 266 /// @param[in] byte_size 267 /// The new size in bytes of this address range. 268 //------------------------------------------------------------------ 269 void 270 SetByteSize (lldb::addr_t byte_size) { m_byte_size = byte_size; } 271 272protected: 273 //------------------------------------------------------------------ 274 // Member variables 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. 278}; 279 280//bool operator== (const AddressRange& lhs, const AddressRange& rhs); 281 282} // namespace lldb_private 283 284#endif // liblldb_AddressRange_h_ 285