1 //===-- HashedNameToDIE.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_HashedNameToDIE_h_
11 #define SymbolFileDWARF_HashedNameToDIE_h_
15 #include "lldb/Core/MappedHash.h"
16 #include "lldb/Core/dwarf.h"
17 #include "lldb/Utility/RegularExpression.h"
18 #include "lldb/lldb-defines.h"
20 #include "DWARFDefines.h"
21 #include "DWARFFormValue.h"
22 #include "NameToDIE.h"
24 class DWARFMappedHash {
26 enum AtomType : uint16_t {
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
39 // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not
41 // in debug info for a type when we know the fully qualified name.
44 // Bit definitions for the eAtomTypeTypeFlags flags
46 // Always set for C++, only set for ObjC if this is the
47 // @implementation for class
48 eTypeFlagClassIsImplementation = (1u << 1)
52 dw_offset_t cu_offset;
53 dw_offset_t offset; // The DIE offset
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
59 DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
67 typedef std::vector<DIEInfo> DIEInfoArray;
68 typedef std::vector<Atom> AtomArray;
72 Prologue(dw_offset_t _die_base_offset = 0);
76 bool ContainsAtom(AtomType atom_type) const;
80 void AppendAtom(AtomType type, dw_form_t form);
82 lldb::offset_t Read(const lldb_private::DataExtractor &data,
83 lldb::offset_t offset);
85 size_t GetByteSize() const;
87 size_t GetMinimumHashDataByteSize() const;
89 bool HashDataHasFixedByteSize() const;
91 // DIE offset base so die offsets in hash_data can be CU relative
92 dw_offset_t die_base_offset;
95 size_t min_hash_data_byte_size;
96 bool hash_data_has_fixed_byte_size;
99 class Header : public MappedHash::Header<Prologue> {
101 size_t GetByteSize(const HeaderData &header_data) override;
103 lldb::offset_t Read(lldb_private::DataExtractor &data,
104 lldb::offset_t offset) override;
106 bool Read(const lldb_private::DWARFDataExtractor &data,
107 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
109 void Dump(lldb_private::Stream &strm, const DIEInfo &hash_data) const;
112 // A class for reading and using a saved hash table from a block of data
115 : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
118 MemoryTable(lldb_private::DWARFDataExtractor &table_data,
119 const lldb_private::DWARFDataExtractor &string_table,
122 const char *GetStringForKeyType(KeyType key) const override;
124 bool ReadHashData(uint32_t hash_data_offset,
125 HashData &hash_data) const override;
128 AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression ®ex,
129 DIEInfoArray &die_info_array) const;
131 size_t AppendAllDIEsInRange(const uint32_t die_offset_start,
132 const uint32_t die_offset_end,
133 DIEInfoArray &die_info_array) const;
135 size_t FindByName(llvm::StringRef name, DIEArray &die_offsets);
137 size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
138 DIEArray &die_offsets);
140 size_t FindByNameAndTagAndQualifiedNameHash(
141 llvm::StringRef name, const dw_tag_t tag,
142 const uint32_t qualified_name_hash, DIEArray &die_offsets);
144 size_t FindCompleteObjCClassByName(llvm::StringRef name,
145 DIEArray &die_offsets,
146 bool must_be_implementation);
149 Result AppendHashDataForRegularExpression(
150 const lldb_private::RegularExpression ®ex,
151 lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
153 size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
155 Result GetHashDataForName(llvm::StringRef name,
156 lldb::offset_t *hash_data_offset_ptr,
157 Pair &pair) const override;
159 lldb_private::DWARFDataExtractor m_data;
160 lldb_private::DWARFDataExtractor m_string_table;
164 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
165 DIEArray &die_offsets);
168 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
169 const dw_tag_t tag, DIEArray &die_offsets);
171 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
173 const uint32_t qualified_name_hash,
174 DIEArray &die_offsets);
177 ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
178 bool return_implementation_only_if_available,
179 DIEArray &die_offsets);
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);
186 static const char *GetAtomTypeName(uint16_t atom);
189 #endif // SymbolFileDWARF_HashedNameToDIE_h_