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