DWARFCompileUnit.h revision 0e0e81dada17e960cc7e35b9e91aaad56b99582e
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 liblldb_DWARFCompileUnit_h_ 11#define SymbolFileDWARF_DWARFCompileUnit_h_ 12 13#include "SymbolFileDWARF.h" 14#include "DWARFDebugInfoEntry.h" 15 16class NameToDIE; 17 18class DWARFCompileUnit 19{ 20public: 21 DWARFCompileUnit(SymbolFileDWARF* dwarf2Data); 22 23 bool Extract(const lldb_private::DataExtractor &debug_info, uint32_t* offset_ptr); 24 dw_offset_t Extract(dw_offset_t offset, const lldb_private::DataExtractor& debug_info_data, const DWARFAbbreviationDeclarationSet* abbrevs); 25 size_t ExtractDIEsIfNeeded (bool cu_die_only); 26 bool LookupAddress( 27 const dw_addr_t address, 28 DWARFDebugInfoEntry** function_die, 29 DWARFDebugInfoEntry** block_die); 30 31 size_t AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, uint32_t depth = UINT32_MAX) const; 32 void Clear(); 33 bool Verify(lldb_private::Stream *s) const; 34 void Dump(lldb_private::Stream *s) const; 35 dw_offset_t GetOffset() const { return m_offset; } 36 uint32_t Size() const { return 11; /* Size in bytes of the compile unit header */ } 37 bool ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); } 38 dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); } 39 dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + 4; } 40 size_t GetDebugInfoSize() const { return m_length + 4 - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ } 41 uint32_t GetLength() const { return m_length; } 42 uint16_t GetVersion() const { return m_version; } 43 const DWARFAbbreviationDeclarationSet* GetAbbreviations() const { return m_abbrevs; } 44 dw_offset_t GetAbbrevOffset() const; 45 uint8_t GetAddressByteSize() const { return m_addr_size; } 46 dw_addr_t GetBaseAddress() const { return m_base_addr; } 47 void ClearDIEs(bool keep_compile_unit_die); 48 49 void 50 SetBaseAddress(dw_addr_t base_addr) 51 { 52 m_base_addr = base_addr; 53 } 54 55 void 56 SetDIERelations(); 57 58 const DWARFDebugInfoEntry* 59 GetCompileUnitDIEOnly() 60 { 61 ExtractDIEsIfNeeded (true); 62 if (m_die_array.empty()) 63 return NULL; 64 return &m_die_array[0]; 65 } 66 67 const DWARFDebugInfoEntry* 68 DIE() 69 { 70 ExtractDIEsIfNeeded (false); 71 if (m_die_array.empty()) 72 return NULL; 73 return &m_die_array[0]; 74 } 75 76 void 77 AddDIE(DWARFDebugInfoEntry& die) 78 { 79 // The average bytes per DIE entry has been seen to be 80 // around 14-20 so lets pre-reserve the needed memory for 81 // our DIE entries accordingly. Search forward for "Compute 82 // average bytes per DIE" to see #if'ed out code that does 83 // that determination. 84 85 // Only reserve the memory if we are adding children of 86 // the main compile unit DIE. The compile unit DIE is always 87 // the first entry, so if our size is 1, then we are adding 88 // the first compile unit child DIE and should reserve 89 // the memory. 90 if (m_die_array.empty()) 91 m_die_array.reserve(GetDebugInfoSize() / 14); 92 m_die_array.push_back(die); 93 } 94 95 DWARFDebugInfoEntry* 96 GetDIEAtIndexUnchecked (uint32_t idx) 97 { 98 return &m_die_array[idx]; 99 } 100 101 DWARFDebugInfoEntry* 102 GetDIEPtr (dw_offset_t die_offset); 103 104 const DWARFDebugInfoEntry* 105 GetDIEPtrContainingOffset (dw_offset_t die_offset); 106 107 static uint8_t 108 GetAddressByteSize(const DWARFCompileUnit* cu); 109 110 static uint8_t 111 GetDefaultAddressSize(); 112 113 static void 114 SetDefaultAddressSize(uint8_t addr_size); 115 116 void * 117 GetUserData() const 118 { 119 return m_user_data; 120 } 121 122 void 123 SetUserData(void *d) 124 { 125 m_user_data = d; 126 } 127 128 129// void 130// AddGlobalDIEByIndex (uint32_t die_idx); 131// 132// void 133// AddGlobal (const DWARFDebugInfoEntry* die); 134// 135 void 136 Index (const uint32_t cu_idx, 137 NameToDIE& func_basenames, 138 NameToDIE& func_fullnames, 139 NameToDIE& func_methods, 140 NameToDIE& func_selectors, 141 NameToDIE& objc_class_selectors, 142 NameToDIE& globals, 143 NameToDIE& types, 144 NameToDIE& namespaces, 145 const DWARFDebugRanges* debug_ranges, 146 DWARFDebugAranges *aranges); 147 148 149protected: 150 SymbolFileDWARF* m_dwarf2Data; 151 dw_offset_t m_offset; 152 uint32_t m_length; 153 uint16_t m_version; 154 const DWARFAbbreviationDeclarationSet* 155 m_abbrevs; 156 uint8_t m_addr_size; 157 dw_addr_t m_base_addr; 158 DWARFDebugInfoEntry::collection 159 m_die_array; // The compile unit debug information entry item 160 std::auto_ptr<DWARFDebugAranges> m_aranges_ap; // A table similar to the .debug_aranges table, but this one points to the exact DW_TAG_subprogram DIEs 161 void * m_user_data; 162private: 163 DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit); 164}; 165 166#endif // SymbolFileDWARF_DWARFCompileUnit_h_ 167