1 //===-- HashedNameToDIE.h ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef SymbolFileDWARF_HashedNameToDIE_h_
10 #define SymbolFileDWARF_HashedNameToDIE_h_
14 #include "lldb/Core/MappedHash.h"
15 #include "lldb/Core/dwarf.h"
16 #include "lldb/Utility/RegularExpression.h"
17 #include "lldb/lldb-defines.h"
19 #include "DWARFDefines.h"
20 #include "DWARFFormValue.h"
21 #include "NameToDIE.h"
23 class DWARFMappedHash {
25 enum AtomType : uint16_t {
27 eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
28 eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that
29 // contains the item in question
30 eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1
31 // (if no tags exceed 255) or DW_FORM_data2
32 eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
33 eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags,
34 eAtomTypeQualNameHash = 6u // A 32 bit hash of the full qualified name
35 // (since all hash entries are basename only)
36 // For example a type like "std::vector<int>::iterator" would have a name of
38 // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not
40 // in debug info for a type when we know the fully qualified name.
43 // Bit definitions for the eAtomTypeTypeFlags flags
45 // Always set for C++, only set for ObjC if this is the
46 // @implementation for class
47 eTypeFlagClassIsImplementation = (1u << 1)
51 dw_offset_t die_offset = DW_INVALID_OFFSET;
54 /// Any flags for this DIEInfo
55 uint32_t type_flags = 0;
57 /// A 32 bit hash of the fully qualified name
58 uint32_t qualified_name_hash = 0;
61 DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
63 explicit operator DIERef() const {
64 return DIERef(llvm::None, DIERef::Section::DebugInfo, die_offset);
73 typedef std::vector<DIEInfo> DIEInfoArray;
74 typedef std::vector<Atom> AtomArray;
78 Prologue(dw_offset_t _die_base_offset = 0);
82 bool ContainsAtom(AtomType atom_type) const;
86 void AppendAtom(AtomType type, dw_form_t form);
88 lldb::offset_t Read(const lldb_private::DataExtractor &data,
89 lldb::offset_t offset);
91 size_t GetByteSize() const;
93 size_t GetMinimumHashDataByteSize() const;
95 bool HashDataHasFixedByteSize() const;
97 // DIE offset base so die offsets in hash_data can be CU relative
98 dw_offset_t die_base_offset;
101 size_t min_hash_data_byte_size;
102 bool hash_data_has_fixed_byte_size;
105 class Header : public MappedHash::Header<Prologue> {
107 size_t GetByteSize(const HeaderData &header_data) override;
109 lldb::offset_t Read(lldb_private::DataExtractor &data,
110 lldb::offset_t offset) override;
112 bool Read(const lldb_private::DWARFDataExtractor &data,
113 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
116 // A class for reading and using a saved hash table from a block of data
119 : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
122 MemoryTable(lldb_private::DWARFDataExtractor &table_data,
123 const lldb_private::DWARFDataExtractor &string_table,
126 const char *GetStringForKeyType(KeyType key) const override;
128 bool ReadHashData(uint32_t hash_data_offset,
129 HashData &hash_data) const override;
132 AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression ®ex,
133 DIEInfoArray &die_info_array) const;
135 size_t AppendAllDIEsInRange(const uint32_t die_offset_start,
136 const uint32_t die_offset_end,
137 DIEInfoArray &die_info_array) const;
139 size_t FindByName(llvm::StringRef name, DIEArray &die_offsets);
141 size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
142 DIEArray &die_offsets);
144 size_t FindByNameAndTagAndQualifiedNameHash(
145 llvm::StringRef name, const dw_tag_t tag,
146 const uint32_t qualified_name_hash, DIEArray &die_offsets);
148 size_t FindCompleteObjCClassByName(llvm::StringRef name,
149 DIEArray &die_offsets,
150 bool must_be_implementation);
153 Result AppendHashDataForRegularExpression(
154 const lldb_private::RegularExpression ®ex,
155 lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
157 size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
159 Result GetHashDataForName(llvm::StringRef name,
160 lldb::offset_t *hash_data_offset_ptr,
161 Pair &pair) const override;
163 lldb_private::DWARFDataExtractor m_data;
164 lldb_private::DWARFDataExtractor m_string_table;
168 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
169 DIEArray &die_offsets);
172 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
173 const dw_tag_t tag, DIEArray &die_offsets);
175 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
177 const uint32_t qualified_name_hash,
178 DIEArray &die_offsets);
181 ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
182 bool return_implementation_only_if_available,
183 DIEArray &die_offsets);
185 static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array,
186 uint32_t type_flag_mask,
187 uint32_t type_flag_value,
188 DIEArray &die_offsets);
190 static const char *GetAtomTypeName(uint16_t atom);
193 #endif // SymbolFileDWARF_HashedNameToDIE_h_