Section.h revision 598df88bd6fc33c6fb330bc859bdc277795501f3
1//===-- Section.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_Section_h_ 11#define liblldb_Section_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Core/AddressRange.h" 15#include "lldb/Core/Flags.h" 16#include "lldb/Core/ModuleChild.h" 17#include "lldb/Core/ConstString.h" 18#include "lldb/Core/UserID.h" 19#include "lldb/Core/VMRange.h" 20#include <limits.h> 21 22namespace lldb_private { 23 24class SectionList 25{ 26public: 27 typedef std::vector<lldb::SectionSP> collection; 28 typedef collection::iterator iterator; 29 typedef collection::const_iterator const_iterator; 30 31 SectionList(); 32 33 virtual 34 ~SectionList(); 35 36 uint32_t 37 AddSection (const lldb::SectionSP& section_sp); 38 39 uint32_t 40 AddUniqueSection (const lldb::SectionSP& section_sp); 41 42 uint32_t 43 FindSectionIndex (const Section* sect); 44 45 bool 46 ContainsSection(lldb::user_id_t sect_id) const; 47 48 void 49 Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const; 50 51 lldb::SectionSP 52 FindSectionByName (const ConstString §ion_dstr) const; 53 54 lldb::SectionSP 55 FindSectionByID (lldb::user_id_t sect_id) const; 56 57 lldb::SectionSP 58 FindSectionByType (lldb::SectionType sect_type, bool check_children, uint32_t start_idx = 0) const; 59 60 lldb::SectionSP 61 FindSectionContainingFileAddress (lldb::addr_t addr, uint32_t depth = UINT32_MAX) const; 62 63 lldb::SectionSP 64 FindSectionContainingLinkedFileAddress (lldb::addr_t vm_addr, uint32_t depth) const; 65 66 bool 67 GetSectionData (const DataExtractor& module_data, DataExtractor& section_data) const; 68 69 // Get the number of sections in this list only 70 size_t 71 GetSize () const 72 { 73 return m_sections.size(); 74 } 75 76 // Get the number of sections in this list, and any contained child sections 77 size_t 78 GetNumSections (uint32_t depth) const; 79 80 bool 81 ReplaceSection (lldb::user_id_t sect_id, const lldb::SectionSP& section_sp, uint32_t depth = UINT32_MAX); 82 83 lldb::SectionSP 84 GetSectionAtIndex (uint32_t idx) const; 85 86 size_t 87 Slide (lldb::addr_t slide_amount, bool slide_children); 88 89protected: 90 collection m_sections; 91}; 92 93 94class Section : 95 public STD_ENABLE_SHARED_FROM_THIS(Section), 96 public ModuleChild, 97 public UserID, 98 public Flags 99{ 100public: 101 // Create a root section (one that has no parent) 102 Section (const lldb::ModuleSP &module_sp, 103 lldb::user_id_t sect_id, 104 const ConstString &name, 105 lldb::SectionType sect_type, 106 lldb::addr_t file_vm_addr, 107 lldb::addr_t vm_size, 108 uint64_t file_offset, 109 uint64_t file_size, 110 uint32_t flags); 111 112 // Create a section that is a child of parent_section_sp 113 Section (const lldb::SectionSP &parent_section_sp, // NULL for top level sections, non-NULL for child sections 114 const lldb::ModuleSP &module_sp, 115 lldb::user_id_t sect_id, 116 const ConstString &name, 117 lldb::SectionType sect_type, 118 lldb::addr_t file_vm_addr, 119 lldb::addr_t vm_size, 120 uint64_t file_offset, 121 uint64_t file_size, 122 uint32_t flags); 123 124 ~Section (); 125 126 static int 127 Compare (const Section& a, const Section& b); 128 129 bool 130 ContainsFileAddress (lldb::addr_t vm_addr) const; 131 132 SectionList& 133 GetChildren () 134 { 135 return m_children; 136 } 137 138 const SectionList& 139 GetChildren () const 140 { 141 return m_children; 142 } 143 144 void 145 Dump (Stream *s, Target *target, uint32_t depth) const; 146 147 void 148 DumpName (Stream *s) const; 149 150 lldb::addr_t 151 GetLoadBaseAddress (Target *target) const; 152 153 bool 154 ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const; 155 156 uint64_t 157 GetFileOffset () const 158 { 159 return m_file_offset; 160 } 161 162 void 163 SetFileOffset (uint64_t file_offset) 164 { 165 m_file_offset = file_offset; 166 } 167 168 uint64_t 169 GetFileSize () const 170 { 171 return m_file_size; 172 } 173 174 void 175 SetFileSize (uint64_t file_size) 176 { 177 m_file_size = file_size; 178 } 179 180 lldb::addr_t 181 GetFileAddress () const; 182 183 lldb::addr_t 184 GetOffset () const; 185 186 187 lldb::addr_t 188 GetByteSize () const 189 { 190 return m_byte_size; 191 } 192 193 void 194 SetByteSize (lldb::addr_t byte_size) 195 { 196 m_byte_size = byte_size; 197 } 198 199 bool 200 IsFake() const 201 { 202 return m_fake; 203 } 204 205 void 206 SetIsFake(bool fake) 207 { 208 m_fake = fake; 209 } 210 211 bool 212 IsEncrypted () const 213 { 214 return m_encrypted; 215 } 216 217 void 218 SetIsEncrypted (bool b) 219 { 220 m_encrypted = b; 221 } 222 223 bool 224 IsDescendant (const Section *section); 225 226 const ConstString& 227 GetName () const; 228 229 bool 230 Slide (lldb::addr_t slide_amount, bool slide_children); 231 232 void 233 SetLinkedLocation (const lldb::SectionSP &linked_section_sp, uint64_t linked_offset); 234 235 bool 236 ContainsLinkedFileAddress (lldb::addr_t vm_addr) const; 237 238 lldb::SectionSP 239 GetLinkedSection () const 240 { 241 return m_linked_section_wp.lock(); 242 } 243 244 uint64_t 245 GetLinkedOffset () const 246 { 247 return m_linked_offset; 248 } 249 250 lldb::addr_t 251 GetLinkedFileAddress () const; 252 253 lldb::SectionType 254 GetType () const 255 { 256 return m_type; 257 } 258 259 lldb::SectionSP 260 GetParent () const 261 { 262 return m_parent_wp.lock(); 263 } 264 265protected: 266 267 lldb::SectionWP m_parent_wp; // Weak pointer to parent section 268 ConstString m_name; // Name of this section 269 lldb::SectionType m_type; // The type of this section 270 lldb::addr_t m_file_addr; // The absolute file virtual address range of this section if m_parent == NULL, 271 // offset from parent file virtual address if m_parent != NULL 272 lldb::addr_t m_byte_size; // Size in bytes that this section will occupy in memory at runtime 273 uint64_t m_file_offset; // Object file offset (if any) 274 uint64_t m_file_size; // Object file size (can be smaller than m_byte_size for zero filled sections...) 275 SectionList m_children; // Child sections 276 bool m_fake:1, // If true, then this section only can contain the address if one of its 277 // children contains an address. This allows for gaps between the children 278 // that are contained in the address range for this section, but do not produce 279 // hits unless the children contain the address. 280 m_encrypted:1; // Set to true if the contents are encrypted 281 lldb::SectionWP m_linked_section_wp; 282 uint64_t m_linked_offset; 283private: 284 DISALLOW_COPY_AND_ASSIGN (Section); 285}; 286 287 288} // namespace lldb_private 289 290#endif // liblldb_Section_h_ 291