1 //===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef SymbolFileDWARF_DWARFCompileUnit_h_
11 #define SymbolFileDWARF_DWARFCompileUnit_h_
14 #include "DWARFDebugInfoEntry.h"
15 #include "lldb/lldb-enumerations.h"
18 class SymbolFileDWARF;
19 class SymbolFileDWARFDwo;
21 typedef std::shared_ptr<DWARFCompileUnit> DWARFCompileUnitSP;
23 class DWARFCompileUnit {
33 static DWARFCompileUnitSP Extract(SymbolFileDWARF *dwarf2Data,
34 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,
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();
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;
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();
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 {
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);
77 lldb::ByteOrder GetByteOrder() const;
79 lldb_private::TypeSystem *GetTypeSystem();
81 DWARFFormValue::FixedFormSizes GetFixedFormSizes();
83 void SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; }
86 GetCompileUnitDIEOnly() { return DWARFDIE(this, GetCompileUnitDIEPtrOnly()); }
89 DIE() { return DWARFDIE(this, DIEPtr()); }
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.
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
101 if (m_die_array.empty())
102 m_die_array.reserve(GetDebugInfoSize() / 24);
103 m_die_array.push_back(die);
106 void AddCompileUnitDIE(DWARFDebugInfoEntry &die);
108 bool HasDIEsParsed() const { return m_die_array.size() > 1; }
111 GetDIE(dw_offset_t die_offset);
113 static uint8_t GetAddressByteSize(const DWARFCompileUnit *cu);
115 static bool IsDWARF64(const DWARFCompileUnit *cu);
117 static uint8_t GetDefaultAddressSize();
119 static void SetDefaultAddressSize(uint8_t addr_size);
121 void *GetUserData() const { return m_user_data; }
123 void SetUserData(void *d);
125 bool Supports_DW_AT_APPLE_objc_complete_type();
127 bool DW_AT_decl_file_attributes_are_invalid();
129 bool Supports_unnamed_objc_bitfields();
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);
136 const DWARFDebugAranges &GetFunctionAranges();
138 SymbolFileDWARF *GetSymbolFileDWARF() const { return m_dwarf2Data; }
140 Producer GetProducer();
142 uint32_t GetProducerVersionMajor();
144 uint32_t GetProducerVersionMinor();
146 uint32_t GetProducerVersionUpdate();
148 static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val);
150 lldb::LanguageType GetLanguageType();
152 bool IsDWARF64() const;
154 bool GetIsOptimized();
156 SymbolFileDWARFDwo *GetDwoSymbolFile() const {
157 return m_dwo_symbol_file.get();
160 dw_offset_t GetBaseObjOffset() const { return m_base_obj_offset; }
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
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;
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;
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;
194 void ParseProducerInfo();
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);
205 DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
207 const DWARFDebugInfoEntry *GetCompileUnitDIEPtrOnly() {
208 ExtractDIEsIfNeeded(true);
209 if (m_die_array.empty())
211 return &m_die_array[0];
214 const DWARFDebugInfoEntry *DIEPtr() {
215 ExtractDIEsIfNeeded(false);
216 if (m_die_array.empty())
218 return &m_die_array[0];
221 DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit);
224 #endif // SymbolFileDWARF_DWARFCompileUnit_h_