HashedNameToDIE.h revision 341825
1//===-- HashedNameToDIE.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_HashedNameToDIE_h_ 11#define SymbolFileDWARF_HashedNameToDIE_h_ 12 13#include <vector> 14 15#include "lldb/Core/MappedHash.h" 16#include "lldb/Core/dwarf.h" 17#include "lldb/Utility/RegularExpression.h" 18#include "lldb/lldb-defines.h" 19 20#include "DWARFDefines.h" 21#include "DWARFFormValue.h" 22#include "NameToDIE.h" 23 24class DWARFMappedHash { 25public: 26 enum AtomType : uint16_t { 27 eAtomTypeNULL = 0u, 28 eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding 29 eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that 30 // contains the item in question 31 eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1 32 // (if no tags exceed 255) or DW_FORM_data2 33 eAtomTypeNameFlags = 4u, // Flags from enum NameFlags 34 eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags, 35 eAtomTypeQualNameHash = 6u // A 32 bit hash of the full qualified name 36 // (since all hash entries are basename only) 37 // For example a type like "std::vector<int>::iterator" would have a name of 38 // "iterator" 39 // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not 40 // have to pull 41 // in debug info for a type when we know the fully qualified name. 42 }; 43 44 // Bit definitions for the eAtomTypeTypeFlags flags 45 enum TypeFlags { 46 // Always set for C++, only set for ObjC if this is the 47 // @implementation for class 48 eTypeFlagClassIsImplementation = (1u << 1) 49 }; 50 51 struct DIEInfo { 52 dw_offset_t cu_offset; 53 dw_offset_t offset; // The DIE offset 54 dw_tag_t tag; 55 uint32_t type_flags; // Any flags for this DIEInfo 56 uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name 57 58 DIEInfo(); 59 DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h); 60 }; 61 62 struct Atom { 63 AtomType type; 64 dw_form_t form; 65 }; 66 67 typedef std::vector<DIEInfo> DIEInfoArray; 68 typedef std::vector<Atom> AtomArray; 69 70 class Prologue { 71 public: 72 Prologue(dw_offset_t _die_base_offset = 0); 73 74 void ClearAtoms(); 75 76 bool ContainsAtom(AtomType atom_type) const; 77 78 void Clear(); 79 80 void AppendAtom(AtomType type, dw_form_t form); 81 82 lldb::offset_t Read(const lldb_private::DataExtractor &data, 83 lldb::offset_t offset); 84 85 size_t GetByteSize() const; 86 87 size_t GetMinimumHashDataByteSize() const; 88 89 bool HashDataHasFixedByteSize() const; 90 91 // DIE offset base so die offsets in hash_data can be CU relative 92 dw_offset_t die_base_offset; 93 AtomArray atoms; 94 uint32_t atom_mask; 95 size_t min_hash_data_byte_size; 96 bool hash_data_has_fixed_byte_size; 97 }; 98 99 class Header : public MappedHash::Header<Prologue> { 100 public: 101 size_t GetByteSize(const HeaderData &header_data) override; 102 103 lldb::offset_t Read(lldb_private::DataExtractor &data, 104 lldb::offset_t offset) override; 105 106 bool Read(const lldb_private::DWARFDataExtractor &data, 107 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const; 108 109 void Dump(lldb_private::Stream &strm, const DIEInfo &hash_data) const; 110 }; 111 112 // A class for reading and using a saved hash table from a block of data 113 // in memory 114 class MemoryTable 115 : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header, 116 DIEInfoArray> { 117 public: 118 MemoryTable(lldb_private::DWARFDataExtractor &table_data, 119 const lldb_private::DWARFDataExtractor &string_table, 120 const char *name); 121 122 const char *GetStringForKeyType(KeyType key) const override; 123 124 bool ReadHashData(uint32_t hash_data_offset, 125 HashData &hash_data) const override; 126 127 size_t 128 AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression ®ex, 129 DIEInfoArray &die_info_array) const; 130 131 size_t AppendAllDIEsInRange(const uint32_t die_offset_start, 132 const uint32_t die_offset_end, 133 DIEInfoArray &die_info_array) const; 134 135 size_t FindByName(llvm::StringRef name, DIEArray &die_offsets); 136 137 size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag, 138 DIEArray &die_offsets); 139 140 size_t FindByNameAndTagAndQualifiedNameHash( 141 llvm::StringRef name, const dw_tag_t tag, 142 const uint32_t qualified_name_hash, DIEArray &die_offsets); 143 144 size_t FindCompleteObjCClassByName(llvm::StringRef name, 145 DIEArray &die_offsets, 146 bool must_be_implementation); 147 148 protected: 149 Result AppendHashDataForRegularExpression( 150 const lldb_private::RegularExpression ®ex, 151 lldb::offset_t *hash_data_offset_ptr, Pair &pair) const; 152 153 size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array); 154 155 Result GetHashDataForName(llvm::StringRef name, 156 lldb::offset_t *hash_data_offset_ptr, 157 Pair &pair) const override; 158 159 lldb_private::DWARFDataExtractor m_data; 160 lldb_private::DWARFDataExtractor m_string_table; 161 std::string m_name; 162 }; 163 164 static void ExtractDIEArray(const DIEInfoArray &die_info_array, 165 DIEArray &die_offsets); 166 167protected: 168 static void ExtractDIEArray(const DIEInfoArray &die_info_array, 169 const dw_tag_t tag, DIEArray &die_offsets); 170 171 static void ExtractDIEArray(const DIEInfoArray &die_info_array, 172 const dw_tag_t tag, 173 const uint32_t qualified_name_hash, 174 DIEArray &die_offsets); 175 176 static void 177 ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array, 178 bool return_implementation_only_if_available, 179 DIEArray &die_offsets); 180 181 static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array, 182 uint32_t type_flag_mask, 183 uint32_t type_flag_value, 184 DIEArray &die_offsets); 185 186 static const char *GetAtomTypeName(uint16_t atom); 187}; 188 189#endif // SymbolFileDWARF_HashedNameToDIE_h_ 190