Section.h revision 9dd6edde116d93777dae51ec550dee741019487e
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// FindSectionByNames (const char *sect, ...) const; 56 57 lldb::SectionSP 58 FindSectionByID (lldb::user_id_t sect_id) const; 59 60 lldb::SectionSP 61 GetSharedPointer (const Section *section, bool check_children) const; 62 63 lldb::SectionSP 64 FindSectionContainingFileAddress (lldb::addr_t addr, uint32_t depth = UINT_MAX) const; 65 66 lldb::SectionSP 67 FindSectionContainingLinkedFileAddress (lldb::addr_t vm_addr) const; 68 69 bool 70 GetSectionData (const DataExtractor& module_data, DataExtractor& section_data) const; 71 72 // Get the number of sections in this list only 73 size_t 74 GetSize () const; 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 const SectionList& 128 GetChildren () const; 129 130 void 131 Dump (Stream *s, Process *process) const; 132 133 void 134 DumpName (Stream *s) const; 135 136 lldb::addr_t 137 GetLoadBaseAddress (Process *process) const; 138 139 bool 140 ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const; 141 142 uint64_t 143 GetFileOffset () const; 144 145 uint64_t 146 GetFileSize () const; 147 148 lldb::addr_t 149 GetFileAddress () const; 150 151 lldb::addr_t 152 GetOffset () const; 153 154 lldb::addr_t 155 GetByteSize () const; 156 157 void 158 SetByteSize (lldb::addr_t byte_size); 159 160 size_t 161 GetSectionDataFromImage (const DataExtractor& image_data, DataExtractor& section_data) const; 162 163 bool 164 IsFake() const; 165 166 void 167 SetIsFake(bool fake); 168 169 bool 170 IsDescendant (const Section *section); 171 172 size_t 173 MemoryMapSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; 174 175 size_t 176 ReadSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; 177 178 ConstString& 179 GetName (); 180 181 const ConstString& 182 GetName () const; 183 184 bool 185 Slide (lldb::addr_t slide_amount, bool slide_children); 186 187 void 188 SetLinkedLocation (const Section *linked_section, uint64_t linked_offset); 189 190 bool 191 ContainsLinkedFileAddress (lldb::addr_t vm_addr) const; 192 193 const Section * 194 GetLinkedSection () const; 195 196 uint64_t 197 GetLinkedOffset () const; 198 199 lldb::addr_t 200 GetLinkedFileAddress () const; 201 202 lldb::SectionType 203 GetSectionType () const 204 { 205 return m_type; 206 } 207 208protected: 209 210 Section * m_parent; // Parent section or NULL if no parent. 211 ConstString m_name; // Name of this section 212 lldb::SectionType m_type; // The type of this section 213 lldb::addr_t m_file_addr; // The absolute file virtual address range of this section if m_parent == NULL, 214 // offset from parent file virtual address if m_parent != NULL 215 lldb::addr_t m_byte_size; // Size in bytes that this section will occupy in memory at runtime 216 uint64_t m_file_offset; // Object file offset (if any) 217 uint64_t m_file_size; // Object file size (can be smaller than m_byte_size for zero filled sections...) 218 SectionList m_children; // Child sections 219 bool m_fake; // If true, then this section only can contain the address if one of its 220 // children contains an address. This allows for gaps between the children 221 // that are contained in the address range for this section, but do not produce 222 // hits unless the children contain the address. 223 const Section * m_linked_section; 224 uint64_t m_linked_offset; 225private: 226 DISALLOW_COPY_AND_ASSIGN (Section); 227}; 228 229 230} // namespace lldb_private 231 232#endif // liblldb_Section_h_ 233