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);
63 lldb_private::TypeSystem *
66 DWARFFormValue::FixedFormSizes
70 SetBaseAddress(dw_addr_t base_addr)
72 m_base_addr = base_addr;
76 GetCompileUnitDIEOnly()
78 return DWARFDIE(this, GetCompileUnitDIEPtrOnly());
84 return DWARFDIE(this, DIEPtr());
88 AddDIE (DWARFDebugInfoEntry& die)
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.
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
99 if (m_die_array.empty())
100 m_die_array.reserve(GetDebugInfoSize() / 24);
101 m_die_array.push_back(die);
105 AddCompileUnitDIE (DWARFDebugInfoEntry& die);
108 HasDIEsParsed () const
110 return m_die_array.size() > 1;
114 GetDIE (dw_offset_t die_offset);
117 GetAddressByteSize(const DWARFCompileUnit* cu);
120 IsDWARF64(const DWARFCompileUnit* cu);
123 GetDefaultAddressSize();
126 SetDefaultAddressSize(uint8_t addr_size);
135 SetUserData(void *d);
138 Supports_DW_AT_APPLE_objc_complete_type ();
141 DW_AT_decl_file_attributes_are_invalid();
144 Supports_unnamed_objc_bitfields ();
147 Index (NameToDIE& func_basenames,
148 NameToDIE& func_fullnames,
149 NameToDIE& func_methods,
150 NameToDIE& func_selectors,
151 NameToDIE& objc_class_selectors,
154 NameToDIE& namespaces);
156 const DWARFDebugAranges &
157 GetFunctionAranges ();
160 GetSymbolFileDWARF () const
169 GetProducerVersionMajor();
172 GetProducerVersionMinor();
175 GetProducerVersionUpdate();
177 static lldb::LanguageType
178 LanguageTypeFromDWARF(uint64_t val);
190 GetDwoSymbolFile() const
192 return m_dwo_symbol_file.get();
196 GetBaseObjOffset() const
198 return m_base_obj_offset;
202 SymbolFileDWARF* m_dwarf2Data;
203 std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
204 const DWARFAbbreviationDeclarationSet *m_abbrevs;
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;
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;
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
225 ParseProducerInfo ();
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,
239 NameToDIE& namespaces);
243 const DWARFDebugInfoEntry*
244 GetCompileUnitDIEPtrOnly()
246 ExtractDIEsIfNeeded (true);
247 if (m_die_array.empty())
249 return &m_die_array[0];
252 const DWARFDebugInfoEntry*
255 ExtractDIEsIfNeeded (false);
256 if (m_die_array.empty())
258 return &m_die_array[0];
262 DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
265 #endif // SymbolFileDWARF_DWARFCompileUnit_h_