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 "DWARFDebugInfoEntry.h" 14 #include "SymbolFileDWARF.h" 15 16 class NameToDIE; 17 18 class DWARFCompileUnit 19 { 20 public: 21 enum Producer 22 { 23 eProducerInvalid = 0, 24 eProducerClang, 25 eProducerGCC, 26 eProducerLLVMGCC, 27 eProcucerOther 28 }; 29 30 DWARFCompileUnit(SymbolFileDWARF* dwarf2Data); 31 32 bool Extract(const lldb_private::DataExtractor &debug_info, lldb::offset_t *offset_ptr); 33 dw_offset_t Extract(lldb::offset_t offset, const lldb_private::DataExtractor& debug_info_data, const DWARFAbbreviationDeclarationSet* abbrevs); 34 size_t ExtractDIEsIfNeeded (bool cu_die_only); 35 bool LookupAddress( 36 const dw_addr_t address, 37 DWARFDebugInfoEntry** function_die, 38 DWARFDebugInfoEntry** block_die); 39 40 size_t AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, 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; GetOffset()44 dw_offset_t GetOffset() const { return m_offset; } Size()45 uint32_t Size() const { return 11; /* Size in bytes of the compile unit header */ } ContainsDIEOffset(dw_offset_t die_offset)46 bool ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); } GetFirstDIEOffset()47 dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); } GetNextCompileUnitOffset()48 dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + 4; } GetDebugInfoSize()49 size_t GetDebugInfoSize() const { return m_length + 4 - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ } GetLength()50 uint32_t GetLength() const { return m_length; } GetVersion()51 uint16_t GetVersion() const { return m_version; } GetAbbreviations()52 const DWARFAbbreviationDeclarationSet* GetAbbreviations() const { return m_abbrevs; } 53 dw_offset_t GetAbbrevOffset() const; GetAddressByteSize()54 uint8_t GetAddressByteSize() const { return m_addr_size; } GetBaseAddress()55 dw_addr_t GetBaseAddress() const { return m_base_addr; } 56 void ClearDIEs(bool keep_compile_unit_die); 57 void BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, 58 DWARFDebugAranges* debug_aranges, 59 bool clear_dies_if_already_not_parsed); 60 61 void SetBaseAddress(dw_addr_t base_addr)62 SetBaseAddress(dw_addr_t base_addr) 63 { 64 m_base_addr = base_addr; 65 } 66 67 const DWARFDebugInfoEntry* GetCompileUnitDIEOnly()68 GetCompileUnitDIEOnly() 69 { 70 ExtractDIEsIfNeeded (true); 71 if (m_die_array.empty()) 72 return NULL; 73 return &m_die_array[0]; 74 } 75 76 const DWARFDebugInfoEntry* DIE()77 DIE() 78 { 79 ExtractDIEsIfNeeded (false); 80 if (m_die_array.empty()) 81 return NULL; 82 return &m_die_array[0]; 83 } 84 85 void AddDIE(DWARFDebugInfoEntry & die)86 AddDIE (DWARFDebugInfoEntry& die) 87 { 88 // The average bytes per DIE entry has been seen to be 89 // around 14-20 so lets pre-reserve half of that since 90 // we are now stripping the NULL tags. 91 92 // Only reserve the memory if we are adding children of 93 // the main compile unit DIE. The compile unit DIE is always 94 // the first entry, so if our size is 1, then we are adding 95 // the first compile unit child DIE and should reserve 96 // the memory. 97 if (m_die_array.empty()) 98 m_die_array.reserve(GetDebugInfoSize() / 24); 99 m_die_array.push_back(die); 100 } 101 102 bool HasDIEsParsed()103 HasDIEsParsed () const 104 { 105 return m_die_array.size() > 1; 106 } 107 108 DWARFDebugInfoEntry* GetDIEAtIndexUnchecked(uint32_t idx)109 GetDIEAtIndexUnchecked (uint32_t idx) 110 { 111 return &m_die_array[idx]; 112 } 113 114 DWARFDebugInfoEntry* 115 GetDIEPtr (dw_offset_t die_offset); 116 117 const DWARFDebugInfoEntry* 118 GetDIEPtrContainingOffset (dw_offset_t die_offset); 119 120 static uint8_t 121 GetAddressByteSize(const DWARFCompileUnit* cu); 122 123 static uint8_t 124 GetDefaultAddressSize(); 125 126 static void 127 SetDefaultAddressSize(uint8_t addr_size); 128 129 void * GetUserData()130 GetUserData() const 131 { 132 return m_user_data; 133 } 134 135 void SetUserData(void * d)136 SetUserData(void *d) 137 { 138 m_user_data = d; 139 } 140 141 bool 142 Supports_DW_AT_APPLE_objc_complete_type (); 143 144 bool 145 DW_AT_decl_file_attributes_are_invalid(); 146 147 bool 148 Supports_unnamed_objc_bitfields (); 149 150 // void 151 // AddGlobalDIEByIndex (uint32_t die_idx); 152 // 153 // void 154 // AddGlobal (const DWARFDebugInfoEntry* die); 155 // 156 void 157 Index (const uint32_t cu_idx, 158 NameToDIE& func_basenames, 159 NameToDIE& func_fullnames, 160 NameToDIE& func_methods, 161 NameToDIE& func_selectors, 162 NameToDIE& objc_class_selectors, 163 NameToDIE& globals, 164 NameToDIE& types, 165 NameToDIE& namespaces); 166 167 const DWARFDebugAranges & 168 GetFunctionAranges (); 169 170 SymbolFileDWARF* GetSymbolFileDWARF()171 GetSymbolFileDWARF () const 172 { 173 return m_dwarf2Data; 174 } 175 176 Producer 177 GetProducer (); 178 179 uint32_t 180 GetProducerVersionMajor(); 181 182 uint32_t 183 GetProducerVersionMinor(); 184 185 uint32_t 186 GetProducerVersionUpdate(); 187 188 protected: 189 SymbolFileDWARF* m_dwarf2Data; 190 const DWARFAbbreviationDeclarationSet *m_abbrevs; 191 void * m_user_data; 192 DWARFDebugInfoEntry::collection m_die_array; // The compile unit debug information entry item 193 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 194 dw_addr_t m_base_addr; 195 dw_offset_t m_offset; 196 uint32_t m_length; 197 uint16_t m_version; 198 uint8_t m_addr_size; 199 Producer m_producer; 200 uint32_t m_producer_version_major; 201 uint32_t m_producer_version_minor; 202 uint32_t m_producer_version_update; 203 204 void 205 ParseProducerInfo (); 206 private: 207 DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit); 208 }; 209 210 #endif // SymbolFileDWARF_DWARFCompileUnit_h_ 211