1 //===-- Section.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Section_h_
11 #define liblldb_Section_h_
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 "lldb/Symbol/ObjectFile.h"
24 namespace lldb_private {
29 typedef std::vector<lldb::SectionSP> collection;
30 typedef collection::iterator iterator;
31 typedef collection::const_iterator const_iterator;
38 operator =(const SectionList& rhs);
41 AddSection (const lldb::SectionSP& section_sp);
44 AddUniqueSection (const lldb::SectionSP& section_sp);
47 FindSectionIndex (const Section* sect);
50 ContainsSection(lldb::user_id_t sect_id) const;
53 Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const;
56 FindSectionByName (const ConstString §ion_dstr) const;
59 FindSectionByID (lldb::user_id_t sect_id) const;
62 FindSectionByType (lldb::SectionType sect_type, bool check_children, size_t start_idx = 0) const;
65 FindSectionContainingFileAddress (lldb::addr_t addr, uint32_t depth = UINT32_MAX) const;
68 GetSectionData (const DataExtractor& module_data, DataExtractor& section_data) const;
70 // Get the number of sections in this list only
74 return m_sections.size();
77 // Get the number of sections in this list, and any contained child sections
79 GetNumSections (uint32_t depth) const;
82 ReplaceSection (lldb::user_id_t sect_id, const lldb::SectionSP& section_sp, uint32_t depth = UINT32_MAX);
84 // Warning, this can be slow as it's removing items from a std::vector.
86 DeleteSection (size_t idx);
89 GetSectionAtIndex (size_t idx) const;
92 Slide (lldb::addr_t slide_amount, bool slide_children);
101 collection m_sections;
106 public std::enable_shared_from_this<Section>,
112 // Create a root section (one that has no parent)
113 Section (const lldb::ModuleSP &module_sp,
114 ObjectFile *obj_file,
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 lldb::offset_t file_offset,
121 lldb::offset_t file_size,
124 // Create a section that is a child of parent_section_sp
125 Section (const lldb::SectionSP &parent_section_sp, // NULL for top level sections, non-NULL for child sections
126 const lldb::ModuleSP &module_sp,
127 ObjectFile *obj_file,
128 lldb::user_id_t sect_id,
129 const ConstString &name,
130 lldb::SectionType sect_type,
131 lldb::addr_t file_vm_addr,
132 lldb::addr_t vm_size,
133 lldb::offset_t file_offset,
134 lldb::offset_t file_size,
140 Compare (const Section& a, const Section& b);
143 ContainsFileAddress (lldb::addr_t vm_addr) const;
158 Dump (Stream *s, Target *target, uint32_t depth) const;
161 DumpName (Stream *s) const;
164 GetLoadBaseAddress (Target *target) const;
167 ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const;
170 GetFileOffset () const
172 return m_file_offset;
176 SetFileOffset (lldb::offset_t file_offset)
178 m_file_offset = file_offset;
188 SetFileSize (lldb::offset_t file_size)
190 m_file_size = file_size;
194 GetFileAddress () const;
197 SetFileAddress (lldb::addr_t file_addr);
210 SetByteSize (lldb::addr_t byte_size)
212 m_byte_size = byte_size;
234 SetIsEncrypted (bool b)
240 IsDescendant (const Section *section);
249 Slide (lldb::addr_t slide_amount, bool slide_children);
261 return m_parent_wp.lock();
265 IsThreadSpecific () const
267 return m_thread_specific;
271 SetIsThreadSpecific (bool b)
273 m_thread_specific = b;
282 GetObjectFile () const
290 ObjectFile *m_obj_file; // The object file that data for this section should be read from
291 lldb::SectionType m_type; // The type of this section
292 lldb::SectionWP m_parent_wp; // Weak pointer to parent section
293 ConstString m_name; // Name of this section
294 lldb::addr_t m_file_addr; // The absolute file virtual address range of this section if m_parent == NULL,
295 // offset from parent file virtual address if m_parent != NULL
296 lldb::addr_t m_byte_size; // Size in bytes that this section will occupy in memory at runtime
297 lldb::offset_t m_file_offset; // Object file offset (if any)
298 lldb::offset_t m_file_size; // Object file size (can be smaller than m_byte_size for zero filled sections...)
299 SectionList m_children; // Child sections
300 bool m_fake:1, // If true, then this section only can contain the address if one of its
301 // children contains an address. This allows for gaps between the children
302 // that are contained in the address range for this section, but do not produce
303 // hits unless the children contain the address.
304 m_encrypted:1, // Set to true if the contents are encrypted
305 m_thread_specific:1;// This section is thread specific
307 DISALLOW_COPY_AND_ASSIGN (Section);
311 } // namespace lldb_private
313 #endif // liblldb_Section_h_