]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Section.h
Merge ^/head r305346 through r305360.
[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     //------------------------------------------------------------------
278     /// Get the permissions as OR'ed bits from lldb::Permissions
279     //------------------------------------------------------------------
280     uint32_t
281     GetPermissions() const;
282
283     //------------------------------------------------------------------
284     /// Set the permissions using bits OR'ed from lldb::Permissions
285     //------------------------------------------------------------------
286     void
287     SetPermissions(uint32_t permissions);
288
289     ObjectFile *
290     GetObjectFile ()
291     {
292         return m_obj_file;
293     }
294     const ObjectFile *
295     GetObjectFile () const 
296     {
297         return m_obj_file;
298     }
299
300     //------------------------------------------------------------------
301     /// Read the section data from the object file that the section
302     /// resides in.
303     ///
304     /// @param[in] dst
305     ///     Where to place the data
306     ///
307     /// @param[in] dst_len
308     ///     How many bytes of section data to read
309     ///
310     /// @param[in] offset
311     ///     The offset in bytes within this section's data at which to
312     ///     start copying data from.
313     ///
314     /// @return
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
317     ///     in this section.
318     //------------------------------------------------------------------
319     lldb::offset_t
320     GetSectionData (void *dst, lldb::offset_t dst_len, lldb::offset_t offset = 0);
321     
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.
328     ///
329     /// @param[in] data
330     ///     Where to place the data, address byte size, and byte order
331     ///
332     /// @return
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
335     ///     in this section.
336     //------------------------------------------------------------------
337     lldb::offset_t
338     GetSectionData (DataExtractor& data) const;
339
340     uint32_t GetLog2Align()
341     {
342         return m_log2align;
343     }
344
345     void
346     SetLog2Align(uint32_t align)
347     {
348         m_log2align = align;
349     }
350
351     // Get the number of host bytes required to hold a target byte
352     uint32_t
353     GetTargetByteSize() const
354     {
355         return m_target_byte_size; 
356     }     
357
358 protected:
359
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   
382 private:
383     DISALLOW_COPY_AND_ASSIGN (Section);
384 };
385
386
387 } // namespace lldb_private
388
389 #endif  // liblldb_Section_h_