Section.h revision 704363531ee4877ccc6d35d0702876096f54c67b
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 (lldb::SectionSP& sect_sp); 38 39 uint32_t 40 AddUniqueSection (lldb::SectionSP& sect_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, Process *process, bool show_header) 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 GetSharedPointer (const Section *section, bool check_children) const; 59 60 lldb::SectionSP 61 FindSectionContainingFileAddress (lldb::addr_t addr, uint32_t depth = UINT_MAX) const; 62 63 lldb::SectionSP 64 FindSectionContainingLinkedFileAddress (lldb::addr_t vm_addr) 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, lldb::SectionSP& sect_sp, uint32_t depth = UINT_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 ModuleChild, 96 public UserID, 97 public Flags 98{ 99public: 100 Section ( 101 Section *parent, // NULL for top level sections, non-NULL for child sections 102 Module* module, 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 ~Section (); 113 114 static int 115 Compare (const Section& a, const Section& b); 116 117 // Get a valid shared pointer to this section object 118 lldb::SectionSP 119 GetSharedPointer() const; 120 121 bool 122 ContainsFileAddress (lldb::addr_t vm_addr) const; 123 124 SectionList& 125 GetChildren () 126 { 127 return m_children; 128 } 129 130 const SectionList& 131 GetChildren () const 132 { 133 return m_children; 134 } 135 136 void 137 Dump (Stream *s, Process *process) const; 138 139 void 140 DumpName (Stream *s) const; 141 142 lldb::addr_t 143 GetLoadBaseAddress (Process *process) const; 144 145 bool 146 ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const; 147 148 uint64_t 149 GetFileOffset () const 150 { 151 return m_file_offset; 152 } 153 154 void 155 SetFileOffset (uint64_t file_offset) 156 { 157 m_file_offset = file_offset; 158 } 159 160 uint64_t 161 GetFileSize () const 162 { 163 return m_file_size; 164 } 165 166 void 167 SetFileSize (uint64_t file_size) 168 { 169 m_file_size = file_size; 170 } 171 172 lldb::addr_t 173 GetFileAddress () const; 174 175 lldb::addr_t 176 GetOffset () const 177 { 178 // This section has a parent which means m_file_addr is an offset. 179 if (m_parent) 180 return m_file_addr; 181 182 // This section has no parent, so there is no offset to be had 183 return 0; 184 } 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 size_t 200 GetSectionDataFromImage (const DataExtractor& image_data, DataExtractor& section_data) const; 201 202 bool 203 IsFake() const 204 { 205 return m_fake; 206 } 207 208 void 209 SetIsFake(bool fake) 210 { 211 m_fake = fake; 212 } 213 214 bool 215 IsDescendant (const Section *section); 216 217 size_t 218 MemoryMapSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; 219 220 size_t 221 ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const; 222 223 size_t 224 ReadSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; 225 226 ConstString& 227 GetName (); 228 229 const ConstString& 230 GetName () const; 231 232 bool 233 Slide (lldb::addr_t slide_amount, bool slide_children); 234 235 void 236 SetLinkedLocation (const Section *linked_section, uint64_t linked_offset); 237 238 bool 239 ContainsLinkedFileAddress (lldb::addr_t vm_addr) const; 240 241 const Section * 242 GetLinkedSection () const 243 { 244 return m_linked_section; 245 } 246 247 uint64_t 248 GetLinkedOffset () const 249 { 250 return m_linked_offset; 251 } 252 253 lldb::addr_t 254 GetLinkedFileAddress () const; 255 256 lldb::SectionType 257 GetSectionType () const 258 { 259 return m_type; 260 } 261 262protected: 263 264 Section * m_parent; // Parent section or NULL if no parent. 265 ConstString m_name; // Name of this section 266 lldb::SectionType m_type; // The type of this section 267 lldb::addr_t m_file_addr; // The absolute file virtual address range of this section if m_parent == NULL, 268 // offset from parent file virtual address if m_parent != NULL 269 lldb::addr_t m_byte_size; // Size in bytes that this section will occupy in memory at runtime 270 uint64_t m_file_offset; // Object file offset (if any) 271 uint64_t m_file_size; // Object file size (can be smaller than m_byte_size for zero filled sections...) 272 SectionList m_children; // Child sections 273 bool m_fake; // If true, then this section only can contain the address if one of its 274 // children contains an address. This allows for gaps between the children 275 // that are contained in the address range for this section, but do not produce 276 // hits unless the children contain the address. 277 const Section * m_linked_section; 278 uint64_t m_linked_offset; 279private: 280 DISALLOW_COPY_AND_ASSIGN (Section); 281}; 282 283 284} // namespace lldb_private 285 286#endif // liblldb_Section_h_ 287