]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
MFV r337744:
[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 "DWARFDIE.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "lldb/lldb-enumerations.h"
16
17 class NameToDIE;
18 class SymbolFileDWARF;
19 class SymbolFileDWARFDwo;
20
21 typedef std::shared_ptr<DWARFCompileUnit> DWARFCompileUnitSP;
22
23 class DWARFCompileUnit {
24 public:
25   enum Producer {
26     eProducerInvalid = 0,
27     eProducerClang,
28     eProducerGCC,
29     eProducerLLVMGCC,
30     eProcucerOther
31   };
32
33   static DWARFCompileUnitSP Extract(SymbolFileDWARF *dwarf2Data,
34       lldb::offset_t *offset_ptr);
35   ~DWARFCompileUnit();
36
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,
40                            DWARFDIECollection &matching_dies,
41                            uint32_t depth = UINT32_MAX) const;
42   bool Verify(lldb_private::Stream *s) const;
43   void Dump(lldb_private::Stream *s) const;
44   // Offset of the initial length field.
45   dw_offset_t GetOffset() const { return m_offset; }
46   lldb::user_id_t GetID() const;
47   // Size in bytes of the initial length + compile unit header.
48   uint32_t Size() const { return m_is_dwarf64 ? 23 : 11; }
49   bool ContainsDIEOffset(dw_offset_t die_offset) const {
50     return die_offset >= GetFirstDIEOffset() &&
51            die_offset < GetNextCompileUnitOffset();
52   }
53   dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); }
54   dw_offset_t GetNextCompileUnitOffset() const {
55     return m_offset + (m_is_dwarf64 ? 12 : 4) + m_length;
56   }
57   // Size of the CU data (without initial length and without header).
58   size_t GetDebugInfoSize() const {
59     return (m_is_dwarf64 ? 12 : 4) + m_length - Size();
60   }
61   // Size of the CU data incl. header but without initial length.
62   uint32_t GetLength() const { return m_length; }
63   uint16_t GetVersion() const { return m_version; }
64   const DWARFAbbreviationDeclarationSet *GetAbbreviations() const {
65     return m_abbrevs;
66   }
67   dw_offset_t GetAbbrevOffset() const;
68   uint8_t GetAddressByteSize() const { return m_addr_size; }
69   dw_addr_t GetBaseAddress() const { return m_base_addr; }
70   dw_addr_t GetAddrBase() const { return m_addr_base; }
71   dw_addr_t GetRangesBase() const { return m_ranges_base; }
72   void SetAddrBase(dw_addr_t addr_base, dw_addr_t ranges_base, dw_offset_t base_obj_offset);
73   void ClearDIEs(bool keep_compile_unit_die);
74   void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data,
75                               DWARFDebugAranges *debug_aranges);
76
77   lldb::ByteOrder GetByteOrder() const;
78
79   lldb_private::TypeSystem *GetTypeSystem();
80
81   DWARFFormValue::FixedFormSizes GetFixedFormSizes();
82
83   void SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; }
84
85   DWARFDIE
86   GetCompileUnitDIEOnly() { return DWARFDIE(this, GetCompileUnitDIEPtrOnly()); }
87
88   DWARFDIE
89   DIE() { return DWARFDIE(this, DIEPtr()); }
90
91   void AddDIE(DWARFDebugInfoEntry &die) {
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 AddCompileUnitDIE(DWARFDebugInfoEntry &die);
107
108   bool HasDIEsParsed() const { return m_die_array.size() > 1; }
109
110   DWARFDIE
111   GetDIE(dw_offset_t die_offset);
112
113   static uint8_t GetAddressByteSize(const DWARFCompileUnit *cu);
114
115   static bool IsDWARF64(const DWARFCompileUnit *cu);
116
117   static uint8_t GetDefaultAddressSize();
118
119   static void SetDefaultAddressSize(uint8_t addr_size);
120
121   void *GetUserData() const { return m_user_data; }
122
123   void SetUserData(void *d);
124
125   bool Supports_DW_AT_APPLE_objc_complete_type();
126
127   bool DW_AT_decl_file_attributes_are_invalid();
128
129   bool Supports_unnamed_objc_bitfields();
130
131   void Index(NameToDIE &func_basenames, NameToDIE &func_fullnames,
132              NameToDIE &func_methods, NameToDIE &func_selectors,
133              NameToDIE &objc_class_selectors, NameToDIE &globals,
134              NameToDIE &types, NameToDIE &namespaces);
135
136   const DWARFDebugAranges &GetFunctionAranges();
137
138   SymbolFileDWARF *GetSymbolFileDWARF() const { return m_dwarf2Data; }
139
140   Producer GetProducer();
141
142   uint32_t GetProducerVersionMajor();
143
144   uint32_t GetProducerVersionMinor();
145
146   uint32_t GetProducerVersionUpdate();
147
148   static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val);
149
150   lldb::LanguageType GetLanguageType();
151
152   bool IsDWARF64() const;
153
154   bool GetIsOptimized();
155
156   SymbolFileDWARFDwo *GetDwoSymbolFile() const {
157     return m_dwo_symbol_file.get();
158   }
159
160   dw_offset_t GetBaseObjOffset() const { return m_base_obj_offset; }
161
162 protected:
163   SymbolFileDWARF *m_dwarf2Data;
164   std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
165   const DWARFAbbreviationDeclarationSet *m_abbrevs;
166   void *m_user_data = nullptr;
167   DWARFDebugInfoEntry::collection
168       m_die_array; // The compile unit debug information entry item
169   std::unique_ptr<DWARFDebugAranges> m_func_aranges_ap; // A table similar to
170                                                         // the .debug_aranges
171                                                         // table, but this one
172                                                         // points to the exact
173                                                         // DW_TAG_subprogram
174                                                         // DIEs
175   dw_addr_t m_base_addr = 0;
176   // Offset of the initial length field.
177   dw_offset_t m_offset;
178   dw_offset_t m_length;
179   uint16_t m_version;
180   uint8_t m_addr_size;
181   Producer m_producer = eProducerInvalid;
182   uint32_t m_producer_version_major = 0;
183   uint32_t m_producer_version_minor = 0;
184   uint32_t m_producer_version_update = 0;
185   lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown;
186   bool m_is_dwarf64;
187   lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate;
188   dw_addr_t m_addr_base = 0;     // Value of DW_AT_addr_base
189   dw_addr_t m_ranges_base = 0;   // Value of DW_AT_ranges_base
190   // If this is a dwo compile unit this is the offset of the base compile unit
191   // in the main object file
192   dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
193
194   void ParseProducerInfo();
195
196   static void
197   IndexPrivate(DWARFCompileUnit *dwarf_cu, const lldb::LanguageType cu_language,
198                const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
199                const dw_offset_t cu_offset, NameToDIE &func_basenames,
200                NameToDIE &func_fullnames, NameToDIE &func_methods,
201                NameToDIE &func_selectors, NameToDIE &objc_class_selectors,
202                NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces);
203
204 private:
205   DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
206
207   const DWARFDebugInfoEntry *GetCompileUnitDIEPtrOnly() {
208     ExtractDIEsIfNeeded(true);
209     if (m_die_array.empty())
210       return NULL;
211     return &m_die_array[0];
212   }
213
214   const DWARFDebugInfoEntry *DIEPtr() {
215     ExtractDIEsIfNeeded(false);
216     if (m_die_array.empty())
217       return NULL;
218     return &m_die_array[0];
219   }
220
221   DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit);
222 };
223
224 #endif // SymbolFileDWARF_DWARFCompileUnit_h_