]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Section.h
Merge ^/head r274961 through r276418.
[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     bool
68     GetSectionData (const DataExtractor& module_data, DataExtractor& section_data) const;
69
70     // Get the number of sections in this list only
71     size_t
72     GetSize () const
73     {
74         return m_sections.size();
75     }
76
77     // Get the number of sections in this list, and any contained child sections
78     size_t
79     GetNumSections (uint32_t depth) const;
80
81     bool
82     ReplaceSection (lldb::user_id_t sect_id, const lldb::SectionSP& section_sp, uint32_t depth = UINT32_MAX);
83
84     // Warning, this can be slow as it's removing items from a std::vector.
85     bool
86     DeleteSection (size_t idx);
87
88     lldb::SectionSP
89     GetSectionAtIndex (size_t idx) const;
90
91     size_t
92     Slide (lldb::addr_t slide_amount, bool slide_children);
93     
94     void
95     Clear ()
96     {
97         m_sections.clear();
98     }
99
100 protected:
101     collection  m_sections;
102 };
103
104
105 class Section :
106     public std::enable_shared_from_this<Section>,
107     public ModuleChild,
108     public UserID,
109     public Flags
110 {
111 public:
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,
122              uint32_t log2align,
123              uint32_t flags);
124
125     // Create a section that is a child of parent_section_sp
126     Section (const lldb::SectionSP &parent_section_sp,    // NULL for top level sections, non-NULL for child sections
127              const lldb::ModuleSP &module_sp,
128              ObjectFile *obj_file,
129              lldb::user_id_t sect_id,
130              const ConstString &name,
131              lldb::SectionType sect_type,
132              lldb::addr_t file_vm_addr,
133              lldb::addr_t vm_size,
134              lldb::offset_t file_offset,
135              lldb::offset_t file_size,
136              uint32_t log2align,
137              uint32_t flags);
138
139     ~Section ();
140
141     static int
142     Compare (const Section& a, const Section& b);
143
144     bool
145     ContainsFileAddress (lldb::addr_t vm_addr) const;
146
147     SectionList&
148     GetChildren ()
149     {
150         return m_children;
151     }
152
153     const SectionList&
154     GetChildren () const
155     {
156         return m_children;
157     }
158
159     void
160     Dump (Stream *s, Target *target, uint32_t depth) const;
161
162     void
163     DumpName (Stream *s) const;
164
165     lldb::addr_t
166     GetLoadBaseAddress (Target *target) const;
167
168     bool
169     ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const;
170
171     lldb::offset_t
172     GetFileOffset () const
173     {
174         return m_file_offset;
175     }
176
177     void
178     SetFileOffset (lldb::offset_t file_offset) 
179     {
180         m_file_offset = file_offset;
181     }
182
183     lldb::offset_t
184     GetFileSize () const
185     {
186         return m_file_size;
187     }
188
189     void
190     SetFileSize (lldb::offset_t file_size)
191     {
192         m_file_size = file_size;
193     }
194
195     lldb::addr_t
196     GetFileAddress () const;
197
198     bool
199     SetFileAddress (lldb::addr_t file_addr);
200
201     lldb::addr_t
202     GetOffset () const;
203
204
205     lldb::addr_t
206     GetByteSize () const
207     {
208         return m_byte_size;
209     }
210     
211     void
212     SetByteSize (lldb::addr_t byte_size)
213     {
214         m_byte_size = byte_size;
215     }
216     
217     bool
218     IsFake() const
219     {
220         return m_fake;
221     }
222
223     void
224     SetIsFake(bool fake)
225     {
226         m_fake = fake;
227     }
228     
229     bool
230     IsEncrypted () const
231     {
232         return m_encrypted;
233     }
234     
235     void
236     SetIsEncrypted (bool b)
237     {
238         m_encrypted = b;
239     }
240
241     bool
242     IsDescendant (const Section *section);
243
244     const ConstString&
245     GetName () const
246     {
247         return m_name;
248     }
249
250     bool
251     Slide (lldb::addr_t slide_amount, bool slide_children);
252
253
254     lldb::SectionType
255     GetType () const
256     {
257         return m_type;
258     }
259
260     lldb::SectionSP
261     GetParent () const
262     {
263         return m_parent_wp.lock();
264     }
265     
266     bool
267     IsThreadSpecific () const
268     {
269         return m_thread_specific;
270     }
271
272     void
273     SetIsThreadSpecific (bool b)
274     {
275         m_thread_specific = b;
276     }
277     
278     ObjectFile *
279     GetObjectFile ()
280     {
281         return m_obj_file;
282     }
283     const ObjectFile *
284     GetObjectFile () const 
285     {
286         return m_obj_file;
287     }
288
289     uint32_t GetLog2Align()
290     {
291         return m_log2align;
292     }
293
294     void
295     SetLog2Align(uint32_t align)
296     {
297         m_log2align = align;
298     }
299
300
301 protected:
302
303     ObjectFile      *m_obj_file;        // The object file that data for this section should be read from
304     lldb::SectionType m_type;           // The type of this section
305     lldb::SectionWP m_parent_wp;        // Weak pointer to parent section
306     ConstString     m_name;             // Name of this section
307     lldb::addr_t    m_file_addr;        // The absolute file virtual address range of this section if m_parent == NULL,
308                                         // offset from parent file virtual address if m_parent != NULL
309     lldb::addr_t    m_byte_size;        // Size in bytes that this section will occupy in memory at runtime
310     lldb::offset_t  m_file_offset;      // Object file offset (if any)
311     lldb::offset_t  m_file_size;        // Object file size (can be smaller than m_byte_size for zero filled sections...)
312     uint32_t        m_log2align;        // log_2(align) of the section (i.e. section has to be aligned to 2^m_log2align)
313     SectionList     m_children;         // Child sections
314     bool            m_fake:1,           // If true, then this section only can contain the address if one of its
315                                         // children contains an address. This allows for gaps between the children
316                                         // that are contained in the address range for this section, but do not produce
317                                         // hits unless the children contain the address.
318                     m_encrypted:1,      // Set to true if the contents are encrypted
319                     m_thread_specific:1;// This section is thread specific
320 private:
321     DISALLOW_COPY_AND_ASSIGN (Section);
322 };
323
324
325 } // namespace lldb_private
326
327 #endif  // liblldb_Section_h_