]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
MFV r311899:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFCompileUnit.h
1 //===-- DWARFCompileUnit.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 SymbolFileDWARF_DWARFCompileUnit_h_
11 #define SymbolFileDWARF_DWARFCompileUnit_h_
12
13 #include "lldb/lldb-enumerations.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "DWARFDIE.h"
16
17 class NameToDIE;
18 class SymbolFileDWARF;
19 class SymbolFileDWARFDwo;
20
21 class DWARFCompileUnit
22 {
23 public:
24     enum Producer 
25     {
26         eProducerInvalid = 0,
27         eProducerClang,
28         eProducerGCC,
29         eProducerLLVMGCC,
30         eProcucerOther
31     };
32
33     DWARFCompileUnit(SymbolFileDWARF* dwarf2Data);
34     ~DWARFCompileUnit();
35
36     bool        Extract(const lldb_private::DWARFDataExtractor &debug_info, lldb::offset_t *offset_ptr);
37     size_t      ExtractDIEsIfNeeded (bool cu_die_only);
38     DWARFDIE    LookupAddress(const dw_addr_t address);
39     size_t      AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, uint32_t depth = UINT32_MAX) const;
40     void        Clear();
41     bool        Verify(lldb_private::Stream *s) const;
42     void        Dump(lldb_private::Stream *s) const;
43     dw_offset_t GetOffset() const { return m_offset; }
44     lldb::user_id_t GetID () const;
45     uint32_t    Size() const { return m_is_dwarf64 ? 23 : 11; /* Size in bytes of the compile unit header */ }
46     bool        ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); }
47     dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); }
48     dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + (m_is_dwarf64 ? 12 : 4); }
49     size_t      GetDebugInfoSize() const { return m_length + (m_is_dwarf64 ? 12 : 4) - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ }
50     uint32_t    GetLength() const { return m_length; }
51     uint16_t    GetVersion() const { return m_version; }
52     const DWARFAbbreviationDeclarationSet*  GetAbbreviations() const { return m_abbrevs; }
53     dw_offset_t GetAbbrevOffset() const;
54     uint8_t     GetAddressByteSize() const { return m_addr_size; }
55     dw_addr_t   GetBaseAddress() const { return m_base_addr; }
56     dw_addr_t   GetAddrBase() const { return m_addr_base; }
57     void        SetAddrBase(dw_addr_t addr_base, dw_offset_t base_obj_offset);
58     void        ClearDIEs(bool keep_compile_unit_die);
59     void        BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data,
60                                         DWARFDebugAranges* debug_aranges);
61
62     lldb::ByteOrder
63     GetByteOrder() const;
64
65     lldb_private::TypeSystem *
66                 GetTypeSystem();
67
68     DWARFFormValue::FixedFormSizes
69                 GetFixedFormSizes ();
70
71     void
72     SetBaseAddress(dw_addr_t base_addr)
73     {
74         m_base_addr = base_addr;
75     }
76
77     DWARFDIE
78     GetCompileUnitDIEOnly()
79     {
80         return DWARFDIE(this, GetCompileUnitDIEPtrOnly());
81     }
82
83     DWARFDIE
84     DIE ()
85     {
86         return DWARFDIE(this, DIEPtr());
87     }
88
89     void
90     AddDIE (DWARFDebugInfoEntry& die)
91     {
92         // The average bytes per DIE entry has been seen to be
93         // around 14-20 so lets pre-reserve half of that since
94         // we are now stripping the NULL tags. 
95
96         // Only reserve the memory if we are adding children of
97         // the main compile unit DIE. The compile unit DIE is always
98         // the first entry, so if our size is 1, then we are adding
99         // the first compile unit child DIE and should reserve
100         // the memory.
101         if (m_die_array.empty())
102             m_die_array.reserve(GetDebugInfoSize() / 24);
103         m_die_array.push_back(die);
104     }
105     
106     void
107     AddCompileUnitDIE (DWARFDebugInfoEntry& die);
108
109     bool
110     HasDIEsParsed () const
111     {
112         return m_die_array.size() > 1;
113     }
114
115     DWARFDIE
116     GetDIE (dw_offset_t die_offset);
117
118     static uint8_t
119     GetAddressByteSize(const DWARFCompileUnit* cu);
120
121     static bool
122     IsDWARF64(const DWARFCompileUnit* cu);
123
124     static uint8_t
125     GetDefaultAddressSize();
126
127     static void
128     SetDefaultAddressSize(uint8_t addr_size);
129
130     void *
131     GetUserData() const
132     {
133         return m_user_data;
134     }
135
136     void
137     SetUserData(void *d);
138
139     bool
140     Supports_DW_AT_APPLE_objc_complete_type ();
141
142     bool
143     DW_AT_decl_file_attributes_are_invalid();
144
145     bool
146     Supports_unnamed_objc_bitfields ();
147
148     void
149     Index (NameToDIE& func_basenames,
150            NameToDIE& func_fullnames,
151            NameToDIE& func_methods,
152            NameToDIE& func_selectors,
153            NameToDIE& objc_class_selectors,
154            NameToDIE& globals,
155            NameToDIE& types,
156            NameToDIE& namespaces);
157
158     const DWARFDebugAranges &
159     GetFunctionAranges ();
160
161     SymbolFileDWARF*
162     GetSymbolFileDWARF () const
163     {
164         return m_dwarf2Data;
165     }
166     
167     Producer
168     GetProducer ();
169     
170     uint32_t
171     GetProducerVersionMajor();
172
173     uint32_t
174     GetProducerVersionMinor();
175     
176     uint32_t
177     GetProducerVersionUpdate();
178
179     static lldb::LanguageType
180     LanguageTypeFromDWARF(uint64_t val);
181
182     lldb::LanguageType
183     GetLanguageType();
184
185     bool
186     IsDWARF64() const;
187
188     bool
189     GetIsOptimized ();
190
191     SymbolFileDWARFDwo*
192     GetDwoSymbolFile() const
193     {
194         return m_dwo_symbol_file.get();
195     }
196
197     dw_offset_t
198     GetBaseObjOffset() const
199     {
200         return m_base_obj_offset;
201     }
202
203 protected:
204     SymbolFileDWARF*    m_dwarf2Data;
205     std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
206     const DWARFAbbreviationDeclarationSet *m_abbrevs;
207     void *              m_user_data;
208     DWARFDebugInfoEntry::collection m_die_array;    // The compile unit debug information entry item
209     std::unique_ptr<DWARFDebugAranges> m_func_aranges_ap;   // A table similar to the .debug_aranges table, but this one points to the exact DW_TAG_subprogram DIEs
210     dw_addr_t           m_base_addr;
211     dw_offset_t         m_offset;
212     dw_offset_t         m_length;
213     uint16_t            m_version;
214     uint8_t             m_addr_size;
215     Producer            m_producer;
216     uint32_t            m_producer_version_major;
217     uint32_t            m_producer_version_minor;
218     uint32_t            m_producer_version_update;
219     lldb::LanguageType  m_language_type;
220     bool                m_is_dwarf64;
221     lldb_private::LazyBool m_is_optimized;
222     dw_addr_t           m_addr_base;       // Value of DW_AT_addr_base
223     dw_offset_t         m_base_obj_offset; // If this is a dwo compile unit this is the offset of
224                                            // the base compile unit in the main object file
225
226     void
227     ParseProducerInfo ();
228
229     static void
230     IndexPrivate (DWARFCompileUnit* dwarf_cu,
231                   const lldb::LanguageType cu_language,
232                   const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
233                   const dw_offset_t cu_offset,
234                   NameToDIE& func_basenames,
235                   NameToDIE& func_fullnames,
236                   NameToDIE& func_methods,
237                   NameToDIE& func_selectors,
238                   NameToDIE& objc_class_selectors,
239                   NameToDIE& globals,
240                   NameToDIE& types,
241                   NameToDIE& namespaces);
242
243 private:
244
245     const DWARFDebugInfoEntry*
246     GetCompileUnitDIEPtrOnly()
247     {
248         ExtractDIEsIfNeeded (true);
249         if (m_die_array.empty())
250             return NULL;
251         return &m_die_array[0];
252     }
253
254     const DWARFDebugInfoEntry*
255     DIEPtr()
256     {
257         ExtractDIEsIfNeeded (false);
258         if (m_die_array.empty())
259             return NULL;
260         return &m_die_array[0];
261     }
262
263
264     DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
265 };
266
267 #endif  // SymbolFileDWARF_DWARFCompileUnit_h_