1254721Semaste//===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef SymbolFileDWARF_DWARFCompileUnit_h_ 11254721Semaste#define SymbolFileDWARF_DWARFCompileUnit_h_ 12254721Semaste 13254721Semaste#include "DWARFDebugInfoEntry.h" 14254721Semaste#include "SymbolFileDWARF.h" 15254721Semaste 16254721Semasteclass NameToDIE; 17254721Semaste 18254721Semasteclass DWARFCompileUnit 19254721Semaste{ 20254721Semastepublic: 21254721Semaste enum Producer 22254721Semaste { 23254721Semaste eProducerInvalid = 0, 24254721Semaste eProducerClang, 25254721Semaste eProducerGCC, 26254721Semaste eProducerLLVMGCC, 27254721Semaste eProcucerOther 28254721Semaste }; 29254721Semaste 30254721Semaste DWARFCompileUnit(SymbolFileDWARF* dwarf2Data); 31254721Semaste 32254721Semaste bool Extract(const lldb_private::DataExtractor &debug_info, lldb::offset_t *offset_ptr); 33254721Semaste dw_offset_t Extract(lldb::offset_t offset, const lldb_private::DataExtractor& debug_info_data, const DWARFAbbreviationDeclarationSet* abbrevs); 34254721Semaste size_t ExtractDIEsIfNeeded (bool cu_die_only); 35254721Semaste bool LookupAddress( 36254721Semaste const dw_addr_t address, 37254721Semaste DWARFDebugInfoEntry** function_die, 38254721Semaste DWARFDebugInfoEntry** block_die); 39254721Semaste 40254721Semaste size_t AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, uint32_t depth = UINT32_MAX) const; 41254721Semaste void Clear(); 42254721Semaste bool Verify(lldb_private::Stream *s) const; 43254721Semaste void Dump(lldb_private::Stream *s) const; 44254721Semaste dw_offset_t GetOffset() const { return m_offset; } 45254721Semaste uint32_t Size() const { return 11; /* Size in bytes of the compile unit header */ } 46254721Semaste bool ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); } 47254721Semaste dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); } 48254721Semaste dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + 4; } 49254721Semaste size_t GetDebugInfoSize() const { return m_length + 4 - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ } 50254721Semaste uint32_t GetLength() const { return m_length; } 51254721Semaste uint16_t GetVersion() const { return m_version; } 52254721Semaste const DWARFAbbreviationDeclarationSet* GetAbbreviations() const { return m_abbrevs; } 53254721Semaste dw_offset_t GetAbbrevOffset() const; 54254721Semaste uint8_t GetAddressByteSize() const { return m_addr_size; } 55254721Semaste dw_addr_t GetBaseAddress() const { return m_base_addr; } 56254721Semaste void ClearDIEs(bool keep_compile_unit_die); 57254721Semaste void BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, 58254721Semaste DWARFDebugAranges* debug_aranges, 59254721Semaste bool clear_dies_if_already_not_parsed); 60254721Semaste 61254721Semaste void 62254721Semaste SetBaseAddress(dw_addr_t base_addr) 63254721Semaste { 64254721Semaste m_base_addr = base_addr; 65254721Semaste } 66254721Semaste 67254721Semaste const DWARFDebugInfoEntry* 68254721Semaste GetCompileUnitDIEOnly() 69254721Semaste { 70254721Semaste ExtractDIEsIfNeeded (true); 71254721Semaste if (m_die_array.empty()) 72254721Semaste return NULL; 73254721Semaste return &m_die_array[0]; 74254721Semaste } 75254721Semaste 76254721Semaste const DWARFDebugInfoEntry* 77254721Semaste DIE() 78254721Semaste { 79254721Semaste ExtractDIEsIfNeeded (false); 80254721Semaste if (m_die_array.empty()) 81254721Semaste return NULL; 82254721Semaste return &m_die_array[0]; 83254721Semaste } 84254721Semaste 85254721Semaste void 86254721Semaste AddDIE (DWARFDebugInfoEntry& die) 87254721Semaste { 88254721Semaste // The average bytes per DIE entry has been seen to be 89254721Semaste // around 14-20 so lets pre-reserve half of that since 90254721Semaste // we are now stripping the NULL tags. 91254721Semaste 92254721Semaste // Only reserve the memory if we are adding children of 93254721Semaste // the main compile unit DIE. The compile unit DIE is always 94254721Semaste // the first entry, so if our size is 1, then we are adding 95254721Semaste // the first compile unit child DIE and should reserve 96254721Semaste // the memory. 97254721Semaste if (m_die_array.empty()) 98254721Semaste m_die_array.reserve(GetDebugInfoSize() / 24); 99254721Semaste m_die_array.push_back(die); 100254721Semaste } 101254721Semaste 102254721Semaste bool 103254721Semaste HasDIEsParsed () const 104254721Semaste { 105254721Semaste return m_die_array.size() > 1; 106254721Semaste } 107254721Semaste 108254721Semaste DWARFDebugInfoEntry* 109254721Semaste GetDIEAtIndexUnchecked (uint32_t idx) 110254721Semaste { 111254721Semaste return &m_die_array[idx]; 112254721Semaste } 113254721Semaste 114254721Semaste DWARFDebugInfoEntry* 115254721Semaste GetDIEPtr (dw_offset_t die_offset); 116254721Semaste 117254721Semaste const DWARFDebugInfoEntry* 118254721Semaste GetDIEPtrContainingOffset (dw_offset_t die_offset); 119254721Semaste 120254721Semaste static uint8_t 121254721Semaste GetAddressByteSize(const DWARFCompileUnit* cu); 122254721Semaste 123254721Semaste static uint8_t 124254721Semaste GetDefaultAddressSize(); 125254721Semaste 126254721Semaste static void 127254721Semaste SetDefaultAddressSize(uint8_t addr_size); 128254721Semaste 129254721Semaste void * 130254721Semaste GetUserData() const 131254721Semaste { 132254721Semaste return m_user_data; 133254721Semaste } 134254721Semaste 135254721Semaste void 136254721Semaste SetUserData(void *d) 137254721Semaste { 138254721Semaste m_user_data = d; 139254721Semaste } 140254721Semaste 141254721Semaste bool 142254721Semaste Supports_DW_AT_APPLE_objc_complete_type (); 143254721Semaste 144254721Semaste bool 145254721Semaste DW_AT_decl_file_attributes_are_invalid(); 146254721Semaste 147254721Semaste bool 148254721Semaste Supports_unnamed_objc_bitfields (); 149254721Semaste 150254721Semaste// void 151254721Semaste// AddGlobalDIEByIndex (uint32_t die_idx); 152254721Semaste// 153254721Semaste// void 154254721Semaste// AddGlobal (const DWARFDebugInfoEntry* die); 155254721Semaste// 156254721Semaste void 157254721Semaste Index (const uint32_t cu_idx, 158254721Semaste NameToDIE& func_basenames, 159254721Semaste NameToDIE& func_fullnames, 160254721Semaste NameToDIE& func_methods, 161254721Semaste NameToDIE& func_selectors, 162254721Semaste NameToDIE& objc_class_selectors, 163254721Semaste NameToDIE& globals, 164254721Semaste NameToDIE& types, 165254721Semaste NameToDIE& namespaces); 166254721Semaste 167254721Semaste const DWARFDebugAranges & 168254721Semaste GetFunctionAranges (); 169254721Semaste 170254721Semaste SymbolFileDWARF* 171254721Semaste GetSymbolFileDWARF () const 172254721Semaste { 173254721Semaste return m_dwarf2Data; 174254721Semaste } 175254721Semaste 176254721Semaste Producer 177254721Semaste GetProducer (); 178254721Semaste 179254721Semaste uint32_t 180254721Semaste GetProducerVersionMajor(); 181254721Semaste 182254721Semaste uint32_t 183254721Semaste GetProducerVersionMinor(); 184254721Semaste 185254721Semaste uint32_t 186254721Semaste GetProducerVersionUpdate(); 187254721Semaste 188254721Semasteprotected: 189254721Semaste SymbolFileDWARF* m_dwarf2Data; 190254721Semaste const DWARFAbbreviationDeclarationSet *m_abbrevs; 191254721Semaste void * m_user_data; 192254721Semaste DWARFDebugInfoEntry::collection m_die_array; // The compile unit debug information entry item 193254721Semaste 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 194254721Semaste dw_addr_t m_base_addr; 195254721Semaste dw_offset_t m_offset; 196254721Semaste uint32_t m_length; 197254721Semaste uint16_t m_version; 198254721Semaste uint8_t m_addr_size; 199254721Semaste Producer m_producer; 200254721Semaste uint32_t m_producer_version_major; 201254721Semaste uint32_t m_producer_version_minor; 202254721Semaste uint32_t m_producer_version_update; 203254721Semaste 204254721Semaste void 205254721Semaste ParseProducerInfo (); 206254721Semasteprivate: 207254721Semaste DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit); 208254721Semaste}; 209254721Semaste 210254721Semaste#endif // SymbolFileDWARF_DWARFCompileUnit_h_ 211