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