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;
67 // Get the number of sections in this list only
71 return m_sections.size();
74 // Get the number of sections in this list, and any contained child sections
76 GetNumSections (uint32_t depth) const;
79 ReplaceSection (lldb::user_id_t sect_id, const lldb::SectionSP& section_sp, uint32_t depth = UINT32_MAX);
81 // Warning, this can be slow as it's removing items from a std::vector.
83 DeleteSection (size_t idx);
86 GetSectionAtIndex (size_t idx) const;
89 Slide (lldb::addr_t slide_amount, bool slide_children);
98 collection m_sections;
103 public std::enable_shared_from_this<Section>,
109 // Create a root section (one that has no parent)
110 Section (const lldb::ModuleSP &module_sp,
111 ObjectFile *obj_file,
112 lldb::user_id_t sect_id,
113 const ConstString &name,
114 lldb::SectionType sect_type,
115 lldb::addr_t file_vm_addr,
116 lldb::addr_t vm_size,
117 lldb::offset_t file_offset,
118 lldb::offset_t file_size,
121 uint32_t target_byte_size = 1);
123 // Create a section that is a child of parent_section_sp
124 Section (const lldb::SectionSP &parent_section_sp, // NULL for top level sections, non-NULL for child sections
125 const lldb::ModuleSP &module_sp,
126 ObjectFile *obj_file,
127 lldb::user_id_t sect_id,
128 const ConstString &name,
129 lldb::SectionType sect_type,
130 lldb::addr_t file_vm_addr,
131 lldb::addr_t vm_size,
132 lldb::offset_t file_offset,
133 lldb::offset_t file_size,
136 uint32_t target_byte_size = 1);
141 Compare (const Section& a, const Section& b);
144 ContainsFileAddress (lldb::addr_t vm_addr) const;
159 Dump (Stream *s, Target *target, uint32_t depth) const;
162 DumpName (Stream *s) const;
165 GetLoadBaseAddress (Target *target) const;
168 ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const;
171 GetFileOffset () const
173 return m_file_offset;
177 SetFileOffset (lldb::offset_t file_offset)
179 m_file_offset = file_offset;
189 SetFileSize (lldb::offset_t file_size)
191 m_file_size = file_size;
195 GetFileAddress () const;
198 SetFileAddress (lldb::addr_t file_addr);
211 SetByteSize (lldb::addr_t byte_size)
213 m_byte_size = byte_size;
235 SetIsEncrypted (bool b)
241 IsDescendant (const Section *section);
250 Slide (lldb::addr_t slide_amount, bool slide_children);
262 return m_parent_wp.lock();
266 IsThreadSpecific () const
268 return m_thread_specific;
272 SetIsThreadSpecific (bool b)
274 m_thread_specific = b;
277 //------------------------------------------------------------------
278 /// Get the permissions as OR'ed bits from lldb::Permissions
279 //------------------------------------------------------------------
281 GetPermissions() const;
283 //------------------------------------------------------------------
284 /// Set the permissions using bits OR'ed from lldb::Permissions
285 //------------------------------------------------------------------
287 SetPermissions(uint32_t permissions);
295 GetObjectFile () const
300 //------------------------------------------------------------------
301 /// Read the section data from the object file that the section
305 /// Where to place the data
307 /// @param[in] dst_len
308 /// How many bytes of section data to read
310 /// @param[in] offset
311 /// The offset in bytes within this section's data at which to
312 /// start copying data from.
315 /// The number of bytes read from the section, or zero if the
316 /// section has no data or \a offset is not a valid offset
318 //------------------------------------------------------------------
320 GetSectionData (void *dst, lldb::offset_t dst_len, lldb::offset_t offset = 0);
322 //------------------------------------------------------------------
323 /// Get the shared reference to the section data from the object
324 /// file that the section resides in. No copies of the data will be
325 /// make unless the object file has been read from memory. If the
326 /// object file is on disk, it will shared the mmap data for the
327 /// entire object file.
330 /// Where to place the data, address byte size, and byte order
333 /// The number of bytes read from the section, or zero if the
334 /// section has no data or \a offset is not a valid offset
336 //------------------------------------------------------------------
338 GetSectionData (DataExtractor& data) const;
340 uint32_t GetLog2Align()
346 SetLog2Align(uint32_t align)
351 // Get the number of host bytes required to hold a target byte
353 GetTargetByteSize() const
355 return m_target_byte_size;
360 ObjectFile *m_obj_file; // The object file that data for this section should be read from
361 lldb::SectionType m_type; // The type of this section
362 lldb::SectionWP m_parent_wp; // Weak pointer to parent section
363 ConstString m_name; // Name of this section
364 lldb::addr_t m_file_addr; // The absolute file virtual address range of this section if m_parent == NULL,
365 // offset from parent file virtual address if m_parent != NULL
366 lldb::addr_t m_byte_size; // Size in bytes that this section will occupy in memory at runtime
367 lldb::offset_t m_file_offset; // Object file offset (if any)
368 lldb::offset_t m_file_size; // Object file size (can be smaller than m_byte_size for zero filled sections...)
369 uint32_t m_log2align; // log_2(align) of the section (i.e. section has to be aligned to 2^m_log2align)
370 SectionList m_children; // Child sections
371 bool m_fake : 1, // If true, then this section only can contain the address if one of its
372 // children contains an address. This allows for gaps between the children
373 // that are contained in the address range for this section, but do not produce
374 // hits unless the children contain the address.
375 m_encrypted : 1, // Set to true if the contents are encrypted
376 m_thread_specific : 1, // This section is thread specific
377 m_readable : 1, // If this section has read permissions
378 m_writable : 1, // If this section has write permissions
379 m_executable : 1; // If this section has executable permissions
380 uint32_t m_target_byte_size; // Some architectures have non-8-bit byte size. This is specified as
381 // as a multiple number of a host bytes
383 DISALLOW_COPY_AND_ASSIGN (Section);
387 } // namespace lldb_private
389 #endif // liblldb_Section_h_