]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Section.h
Merge ^/head r294777 through r294960.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / Section.h
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 "lldb/Symbol/ObjectFile.h"
22 #include <limits.h>
23
24 namespace lldb_private {
25
26 class SectionList
27 {
28 public:
29     typedef std::vector<lldb::SectionSP>  collection;
30     typedef collection::iterator        iterator;
31     typedef collection::const_iterator  const_iterator;
32
33     SectionList();
34
35     ~SectionList();
36
37     SectionList &
38     operator =(const SectionList& rhs);
39
40     size_t
41     AddSection (const lldb::SectionSP& section_sp);
42
43     size_t
44     AddUniqueSection (const lldb::SectionSP& section_sp);
45
46     size_t
47     FindSectionIndex (const Section* sect);
48
49     bool
50     ContainsSection(lldb::user_id_t sect_id) const;
51
52     void
53     Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const;
54
55     lldb::SectionSP
56     FindSectionByName (const ConstString &section_dstr) const;
57
58     lldb::SectionSP
59     FindSectionByID (lldb::user_id_t sect_id) const;
60
61     lldb::SectionSP
62     FindSectionByType (lldb::SectionType sect_type, bool check_children, size_t start_idx = 0) const;
63
64     lldb::SectionSP
65     FindSectionContainingFileAddress (lldb::addr_t addr, uint32_t depth = UINT32_MAX) const;
66
67     // Get the number of sections in this list only
68     size_t
69     GetSize () const
70     {
71         return m_sections.size();
72     }
73
74     // Get the number of sections in this list, and any contained child sections
75     size_t
76     GetNumSections (uint32_t depth) const;
77
78     bool
79     ReplaceSection (lldb::user_id_t sect_id, const lldb::SectionSP& section_sp, uint32_t depth = UINT32_MAX);
80
81     // Warning, this can be slow as it's removing items from a std::vector.
82     bool
83     DeleteSection (size_t idx);
84
85     lldb::SectionSP
86     GetSectionAtIndex (size_t idx) const;
87
88     size_t
89     Slide (lldb::addr_t slide_amount, bool slide_children);
90     
91     void
92     Clear ()
93     {
94         m_sections.clear();
95     }
96
97 protected:
98     collection  m_sections;
99 };
100
101
102 class Section :
103     public std::enable_shared_from_this<Section>,
104     public ModuleChild,
105     public UserID,
106     public Flags
107 {
108 public:
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,
119              uint32_t log2align,
120              uint32_t flags,
121              uint32_t target_byte_size = 1);
122
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,
134              uint32_t log2align,
135              uint32_t flags,
136              uint32_t target_byte_size = 1);
137
138     ~Section ();
139
140     static int
141     Compare (const Section& a, const Section& b);
142
143     bool
144     ContainsFileAddress (lldb::addr_t vm_addr) const;
145
146     SectionList&
147     GetChildren ()
148     {
149         return m_children;
150     }
151
152     const SectionList&
153     GetChildren () const
154     {
155         return m_children;
156     }
157
158     void
159     Dump (Stream *s, Target *target, uint32_t depth) const;
160
161     void
162     DumpName (Stream *s) const;
163
164     lldb::addr_t
165     GetLoadBaseAddress (Target *target) const;
166
167     bool
168     ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const;
169
170     lldb::offset_t
171     GetFileOffset () const
172     {
173         return m_file_offset;
174     }
175
176     void
177     SetFileOffset (lldb::offset_t file_offset) 
178     {
179         m_file_offset = file_offset;
180     }
181
182     lldb::offset_t
183     GetFileSize () const
184     {
185         return m_file_size;
186     }
187
188     void
189     SetFileSize (lldb::offset_t file_size)
190     {
191         m_file_size = file_size;
192     }
193
194     lldb::addr_t
195     GetFileAddress () const;
196
197     bool
198     SetFileAddress (lldb::addr_t file_addr);
199
200     lldb::addr_t
201     GetOffset () const;
202
203
204     lldb::addr_t
205     GetByteSize () const
206     {
207         return m_byte_size;
208     }
209     
210     void
211     SetByteSize (lldb::addr_t byte_size)
212     {
213         m_byte_size = byte_size;
214     }
215     
216     bool
217     IsFake() const
218     {
219         return m_fake;
220     }
221
222     void
223     SetIsFake(bool fake)
224     {
225         m_fake = fake;
226     }
227     
228     bool
229     IsEncrypted () const
230     {
231         return m_encrypted;
232     }
233     
234     void
235     SetIsEncrypted (bool b)
236     {
237         m_encrypted = b;
238     }
239
240     bool
241     IsDescendant (const Section *section);
242
243     const ConstString&
244     GetName () const
245     {
246         return m_name;
247     }
248
249     bool
250     Slide (lldb::addr_t slide_amount, bool slide_children);
251
252
253     lldb::SectionType
254     GetType () const
255     {
256         return m_type;
257     }
258
259     lldb::SectionSP
260     GetParent () const
261     {
262         return m_parent_wp.lock();
263     }
264     
265     bool
266     IsThreadSpecific () const
267     {
268         return m_thread_specific;
269     }
270
271     void
272     SetIsThreadSpecific (bool b)
273     {
274         m_thread_specific = b;
275     }
276     
277     ObjectFile *
278     GetObjectFile ()
279     {
280         return m_obj_file;
281     }
282     const ObjectFile *
283     GetObjectFile () const 
284     {
285         return m_obj_file;
286     }
287
288     //------------------------------------------------------------------
289     /// Read the section data from the object file that the section
290     /// resides in.
291     ///
292     /// @param[in] dst
293     ///     Where to place the data
294     ///
295     /// @param[in] dst_len
296     ///     How many bytes of section data to read
297     ///
298     /// @param[in] offset
299     ///     The offset in bytes within this section's data at which to
300     ///     start copying data from.
301     ///
302     /// @return
303     ///     The number of bytes read from the section, or zero if the
304     ///     section has no data or \a offset is not a valid offset
305     ///     in this section.
306     //------------------------------------------------------------------
307     lldb::offset_t
308     GetSectionData (void *dst, lldb::offset_t dst_len, lldb::offset_t offset = 0);
309     
310     //------------------------------------------------------------------
311     /// Get the shared reference to the section data from the object
312     /// file that the section resides in. No copies of the data will be
313     /// make unless the object file has been read from memory. If the
314     /// object file is on disk, it will shared the mmap data for the
315     /// entire object file.
316     ///
317     /// @param[in] data
318     ///     Where to place the data, address byte size, and byte order
319     ///
320     /// @return
321     ///     The number of bytes read from the section, or zero if the
322     ///     section has no data or \a offset is not a valid offset
323     ///     in this section.
324     //------------------------------------------------------------------
325     lldb::offset_t
326     GetSectionData (DataExtractor& data) const;
327
328     uint32_t GetLog2Align()
329     {
330         return m_log2align;
331     }
332
333     void
334     SetLog2Align(uint32_t align)
335     {
336         m_log2align = align;
337     }
338
339     // Get the number of host bytes required to hold a target byte
340     uint32_t
341     GetTargetByteSize() const
342     {
343         return m_target_byte_size; 
344     }     
345
346 protected:
347
348     ObjectFile      *m_obj_file;        // The object file that data for this section should be read from
349     lldb::SectionType m_type;           // The type of this section
350     lldb::SectionWP m_parent_wp;        // Weak pointer to parent section
351     ConstString     m_name;             // Name of this section
352     lldb::addr_t    m_file_addr;        // The absolute file virtual address range of this section if m_parent == NULL,
353                                         // offset from parent file virtual address if m_parent != NULL
354     lldb::addr_t    m_byte_size;        // Size in bytes that this section will occupy in memory at runtime
355     lldb::offset_t  m_file_offset;      // Object file offset (if any)
356     lldb::offset_t  m_file_size;        // Object file size (can be smaller than m_byte_size for zero filled sections...)
357     uint32_t        m_log2align;        // log_2(align) of the section (i.e. section has to be aligned to 2^m_log2align)
358     SectionList     m_children;         // Child sections
359     bool            m_fake:1,           // If true, then this section only can contain the address if one of its
360                                         // children contains an address. This allows for gaps between the children
361                                         // that are contained in the address range for this section, but do not produce
362                                         // hits unless the children contain the address.
363                     m_encrypted:1,      // Set to true if the contents are encrypted
364                     m_thread_specific:1;// This section is thread specific
365     uint32_t        m_target_byte_size; // Some architectures have non-8-bit byte size. This is specified as
366                                         // as a multiple number of a host bytes   
367 private:
368     DISALLOW_COPY_AND_ASSIGN (Section);
369 };
370
371
372 } // namespace lldb_private
373
374 #endif  // liblldb_Section_h_