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_
13 #include "lldb/lldb-enumerations.h"
14 #include "DWARFDebugInfoEntry.h"
18 class SymbolFileDWARF;
19 class SymbolFileDWARFDwo;
21 class DWARFCompileUnit
33 DWARFCompileUnit(SymbolFileDWARF* dwarf2Data);
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;
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);
65 lldb_private::TypeSystem *
68 DWARFFormValue::FixedFormSizes
72 SetBaseAddress(dw_addr_t base_addr)
74 m_base_addr = base_addr;
78 GetCompileUnitDIEOnly()
80 return DWARFDIE(this, GetCompileUnitDIEPtrOnly());
86 return DWARFDIE(this, DIEPtr());
90 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);
107 AddCompileUnitDIE (DWARFDebugInfoEntry& die);
110 HasDIEsParsed () const
112 return m_die_array.size() > 1;
116 GetDIE (dw_offset_t die_offset);
119 GetAddressByteSize(const DWARFCompileUnit* cu);
122 IsDWARF64(const DWARFCompileUnit* cu);
125 GetDefaultAddressSize();
128 SetDefaultAddressSize(uint8_t addr_size);
137 SetUserData(void *d);
140 Supports_DW_AT_APPLE_objc_complete_type ();
143 DW_AT_decl_file_attributes_are_invalid();
146 Supports_unnamed_objc_bitfields ();
149 Index (NameToDIE& func_basenames,
150 NameToDIE& func_fullnames,
151 NameToDIE& func_methods,
152 NameToDIE& func_selectors,
153 NameToDIE& objc_class_selectors,
156 NameToDIE& namespaces);
158 const DWARFDebugAranges &
159 GetFunctionAranges ();
162 GetSymbolFileDWARF () const
171 GetProducerVersionMajor();
174 GetProducerVersionMinor();
177 GetProducerVersionUpdate();
179 static lldb::LanguageType
180 LanguageTypeFromDWARF(uint64_t val);
192 GetDwoSymbolFile() const
194 return m_dwo_symbol_file.get();
198 GetBaseObjOffset() const
200 return m_base_obj_offset;
204 SymbolFileDWARF* m_dwarf2Data;
205 std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
206 const DWARFAbbreviationDeclarationSet *m_abbrevs;
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;
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;
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
227 ParseProducerInfo ();
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,
241 NameToDIE& namespaces);
245 const DWARFDebugInfoEntry*
246 GetCompileUnitDIEPtrOnly()
248 ExtractDIEsIfNeeded (true);
249 if (m_die_array.empty())
251 return &m_die_array[0];
254 const DWARFDebugInfoEntry*
257 ExtractDIEsIfNeeded (false);
258 if (m_die_array.empty())
260 return &m_die_array[0];
264 DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
267 #endif // SymbolFileDWARF_DWARFCompileUnit_h_