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 /// DIE offset, check form for encoding.
28 eAtomTypeDIEOffset = 1u,
29 /// DIE offset of the compiler unit header that contains the item in
31 eAtomTypeCUOffset = 2u,
32 /// DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed
33 /// 255) or DW_FORM_data2.
35 // Flags from enum NameFlags.
36 eAtomTypeNameFlags = 4u,
37 // Flags from enum TypeFlags.
38 eAtomTypeTypeFlags = 5u,
39 /// A 32 bit hash of the full qualified name (since all hash entries are
40 /// basename only) For example a type like "std::vector<int>::iterator"
41 /// would have a name of "iterator" and a 32 bit hash for
42 /// "std::vector<int>::iterator" to allow us to not have to pull in debug
43 /// info for a type when we know the fully qualified name.
44 eAtomTypeQualNameHash = 6u
47 /// Bit definitions for the eAtomTypeTypeFlags flags.
49 /// Always set for C++, only set for ObjC if this is the
50 /// @implementation for class.
51 eTypeFlagClassIsImplementation = (1u << 1)
55 dw_offset_t die_offset = DW_INVALID_OFFSET;
56 dw_tag_t tag = llvm::dwarf::DW_TAG_null;
58 /// Any flags for this DIEInfo.
59 uint32_t type_flags = 0;
61 /// A 32 bit hash of the fully qualified name.
62 uint32_t qualified_name_hash = 0;
65 DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
67 explicit operator DIERef() const {
68 return DIERef(llvm::None, DIERef::Section::DebugInfo, die_offset);
77 typedef std::vector<DIEInfo> DIEInfoArray;
78 typedef std::vector<Atom> AtomArray;
82 Prologue(dw_offset_t _die_base_offset = 0);
86 bool ContainsAtom(AtomType atom_type) const;
90 void AppendAtom(AtomType type, dw_form_t form);
92 lldb::offset_t Read(const lldb_private::DataExtractor &data,
93 lldb::offset_t offset);
95 size_t GetByteSize() const;
97 size_t GetMinimumHashDataByteSize() const;
99 bool HashDataHasFixedByteSize() const;
101 /// DIE offset base so die offsets in hash_data can be CU relative.
102 dw_offset_t die_base_offset;
105 size_t min_hash_data_byte_size;
106 bool hash_data_has_fixed_byte_size;
109 class Header : public MappedHash::Header<Prologue> {
111 size_t GetByteSize(const HeaderData &header_data) override;
113 lldb::offset_t Read(lldb_private::DataExtractor &data,
114 lldb::offset_t offset) override;
116 bool Read(const lldb_private::DWARFDataExtractor &data,
117 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
120 /// A class for reading and using a saved hash table from a block of data in
123 : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
126 MemoryTable(lldb_private::DWARFDataExtractor &table_data,
127 const lldb_private::DWARFDataExtractor &string_table,
130 const char *GetStringForKeyType(KeyType key) const override;
132 bool ReadHashData(uint32_t hash_data_offset,
133 HashData &hash_data) const override;
136 AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression ®ex,
137 DIEInfoArray &die_info_array) const;
139 size_t AppendAllDIEsInRange(const uint32_t die_offset_start,
140 const uint32_t die_offset_end,
141 DIEInfoArray &die_info_array) const;
143 size_t FindByName(llvm::StringRef name, DIEArray &die_offsets);
145 size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
146 DIEArray &die_offsets);
148 size_t FindByNameAndTagAndQualifiedNameHash(
149 llvm::StringRef name, const dw_tag_t tag,
150 const uint32_t qualified_name_hash, DIEArray &die_offsets);
152 size_t FindCompleteObjCClassByName(llvm::StringRef name,
153 DIEArray &die_offsets,
154 bool must_be_implementation);
157 Result AppendHashDataForRegularExpression(
158 const lldb_private::RegularExpression ®ex,
159 lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
161 size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
163 Result GetHashDataForName(llvm::StringRef name,
164 lldb::offset_t *hash_data_offset_ptr,
165 Pair &pair) const override;
167 lldb_private::DWARFDataExtractor m_data;
168 lldb_private::DWARFDataExtractor m_string_table;
172 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
173 DIEArray &die_offsets);
176 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
177 const dw_tag_t tag, DIEArray &die_offsets);
179 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
181 const uint32_t qualified_name_hash,
182 DIEArray &die_offsets);
185 ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
186 bool return_implementation_only_if_available,
187 DIEArray &die_offsets);
189 static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array,
190 uint32_t type_flag_mask,
191 uint32_t type_flag_value,
192 DIEArray &die_offsets);
194 static const char *GetAtomTypeName(uint16_t atom);
197 #endif // SymbolFileDWARF_HashedNameToDIE_h_