]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Section.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 flags);
123
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,
135              uint32_t flags);
136
137     ~Section ();
138
139     static int
140     Compare (const Section& a, const Section& b);
141
142     bool
143     ContainsFileAddress (lldb::addr_t vm_addr) const;
144
145     SectionList&
146     GetChildren ()
147     {
148         return m_children;
149     }
150
151     const SectionList&
152     GetChildren () const
153     {
154         return m_children;
155     }
156
157     void
158     Dump (Stream *s, Target *target, uint32_t depth) const;
159
160     void
161     DumpName (Stream *s) const;
162
163     lldb::addr_t
164     GetLoadBaseAddress (Target *target) const;
165
166     bool
167     ResolveContainedAddress (lldb::addr_t offset, Address &so_addr) const;
168
169     lldb::offset_t
170     GetFileOffset () const
171     {
172         return m_file_offset;
173     }
174
175     void
176     SetFileOffset (lldb::offset_t file_offset) 
177     {
178         m_file_offset = file_offset;
179     }
180
181     lldb::offset_t
182     GetFileSize () const
183     {
184         return m_file_size;
185     }
186
187     void
188     SetFileSize (lldb::offset_t file_size)
189     {
190         m_file_size = file_size;
191     }
192
193     lldb::addr_t
194     GetFileAddress () const;
195
196     bool
197     SetFileAddress (lldb::addr_t file_addr);
198
199     lldb::addr_t
200     GetOffset () const;
201
202
203     lldb::addr_t
204     GetByteSize () const
205     {
206         return m_byte_size;
207     }
208     
209     void
210     SetByteSize (lldb::addr_t byte_size)
211     {
212         m_byte_size = byte_size;
213     }
214     
215     bool
216     IsFake() const
217     {
218         return m_fake;
219     }
220
221     void
222     SetIsFake(bool fake)
223     {
224         m_fake = fake;
225     }
226     
227     bool
228     IsEncrypted () const
229     {
230         return m_encrypted;
231     }
232     
233     void
234     SetIsEncrypted (bool b)
235     {
236         m_encrypted = b;
237     }
238
239     bool
240     IsDescendant (const Section *section);
241
242     const ConstString&
243     GetName () const
244     {
245         return m_name;
246     }
247
248     bool
249     Slide (lldb::addr_t slide_amount, bool slide_children);
250
251
252     lldb::SectionType
253     GetType () const
254     {
255         return m_type;
256     }
257
258     lldb::SectionSP
259     GetParent () const
260     {
261         return m_parent_wp.lock();
262     }
263     
264     bool
265     IsThreadSpecific () const
266     {
267         return m_thread_specific;
268     }
269
270     void
271     SetIsThreadSpecific (bool b)
272     {
273         m_thread_specific = b;
274     }
275     
276     ObjectFile *
277     GetObjectFile ()
278     {
279         return m_obj_file;
280     }
281     const ObjectFile *
282     GetObjectFile () const 
283     {
284         return m_obj_file;
285     }
286
287
288 protected:
289
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
306 private:
307     DISALLOW_COPY_AND_ASSIGN (Section);
308 };
309
310
311 } // namespace lldb_private
312
313 #endif  // liblldb_Section_h_