]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
MFV r299425:
[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
63     lldb_private::TypeSystem *
64                 GetTypeSystem();
65
66     DWARFFormValue::FixedFormSizes
67                 GetFixedFormSizes ();
68
69     void
70     SetBaseAddress(dw_addr_t base_addr)
71     {
72         m_base_addr = base_addr;
73     }
74
75     DWARFDIE
76     GetCompileUnitDIEOnly()
77     {
78         return DWARFDIE(this, GetCompileUnitDIEPtrOnly());
79     }
80
81     DWARFDIE
82     DIE ()
83     {
84         return DWARFDIE(this, DIEPtr());
85     }
86
87     void
88     AddDIE (DWARFDebugInfoEntry& die)
89     {
90         // The average bytes per DIE entry has been seen to be
91         // around 14-20 so lets pre-reserve half of that since
92         // we are now stripping the NULL tags. 
93
94         // Only reserve the memory if we are adding children of
95         // the main compile unit DIE. The compile unit DIE is always
96         // the first entry, so if our size is 1, then we are adding
97         // the first compile unit child DIE and should reserve
98         // the memory.
99         if (m_die_array.empty())
100             m_die_array.reserve(GetDebugInfoSize() / 24);
101         m_die_array.push_back(die);
102     }
103     
104     void
105     AddCompileUnitDIE (DWARFDebugInfoEntry& die);
106
107     bool
108     HasDIEsParsed () const
109     {
110         return m_die_array.size() > 1;
111     }
112
113     DWARFDIE
114     GetDIE (dw_offset_t die_offset);
115
116     static uint8_t
117     GetAddressByteSize(const DWARFCompileUnit* cu);
118
119     static bool
120     IsDWARF64(const DWARFCompileUnit* cu);
121
122     static uint8_t
123     GetDefaultAddressSize();
124
125     static void
126     SetDefaultAddressSize(uint8_t addr_size);
127
128     void *
129     GetUserData() const
130     {
131         return m_user_data;
132     }
133
134     void
135     SetUserData(void *d);
136
137     bool
138     Supports_DW_AT_APPLE_objc_complete_type ();
139
140     bool
141     DW_AT_decl_file_attributes_are_invalid();
142
143     bool
144     Supports_unnamed_objc_bitfields ();
145
146     void
147     Index (NameToDIE& func_basenames,
148            NameToDIE& func_fullnames,
149            NameToDIE& func_methods,
150            NameToDIE& func_selectors,
151            NameToDIE& objc_class_selectors,
152            NameToDIE& globals,
153            NameToDIE& types,
154            NameToDIE& namespaces);
155
156     const DWARFDebugAranges &
157     GetFunctionAranges ();
158
159     SymbolFileDWARF*
160     GetSymbolFileDWARF () const
161     {
162         return m_dwarf2Data;
163     }
164     
165     Producer
166     GetProducer ();
167     
168     uint32_t
169     GetProducerVersionMajor();
170
171     uint32_t
172     GetProducerVersionMinor();
173     
174     uint32_t
175     GetProducerVersionUpdate();
176
177     static lldb::LanguageType
178     LanguageTypeFromDWARF(uint64_t val);
179
180     lldb::LanguageType
181     GetLanguageType();
182
183     bool
184     IsDWARF64() const;
185
186     bool
187     GetIsOptimized ();
188
189     SymbolFileDWARFDwo*
190     GetDwoSymbolFile() const
191     {
192         return m_dwo_symbol_file.get();
193     }
194
195     dw_offset_t
196     GetBaseObjOffset() const
197     {
198         return m_base_obj_offset;
199     }
200
201 protected:
202     SymbolFileDWARF*    m_dwarf2Data;
203     std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
204     const DWARFAbbreviationDeclarationSet *m_abbrevs;
205     void *              m_user_data;
206     DWARFDebugInfoEntry::collection m_die_array;    // The compile unit debug information entry item
207     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
208     dw_addr_t           m_base_addr;
209     dw_offset_t         m_offset;
210     dw_offset_t         m_length;
211     uint16_t            m_version;
212     uint8_t             m_addr_size;
213     Producer            m_producer;
214     uint32_t            m_producer_version_major;
215     uint32_t            m_producer_version_minor;
216     uint32_t            m_producer_version_update;
217     lldb::LanguageType  m_language_type;
218     bool                m_is_dwarf64;
219     lldb_private::LazyBool m_is_optimized;
220     dw_addr_t           m_addr_base;       // Value of DW_AT_addr_base
221     dw_offset_t         m_base_obj_offset; // If this is a dwo compile unit this is the offset of
222                                            // the base compile unit in the main object file
223
224     void
225     ParseProducerInfo ();
226
227     static void
228     IndexPrivate (DWARFCompileUnit* dwarf_cu,
229                   const lldb::LanguageType cu_language,
230                   const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
231                   const dw_offset_t cu_offset,
232                   NameToDIE& func_basenames,
233                   NameToDIE& func_fullnames,
234                   NameToDIE& func_methods,
235                   NameToDIE& func_selectors,
236                   NameToDIE& objc_class_selectors,
237                   NameToDIE& globals,
238                   NameToDIE& types,
239                   NameToDIE& namespaces);
240
241 private:
242
243     const DWARFDebugInfoEntry*
244     GetCompileUnitDIEPtrOnly()
245     {
246         ExtractDIEsIfNeeded (true);
247         if (m_die_array.empty())
248             return NULL;
249         return &m_die_array[0];
250     }
251
252     const DWARFDebugInfoEntry*
253     DIEPtr()
254     {
255         ExtractDIEsIfNeeded (false);
256         if (m_die_array.empty())
257             return NULL;
258         return &m_die_array[0];
259     }
260
261
262     DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
263 };
264
265 #endif  // SymbolFileDWARF_DWARFCompileUnit_h_