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 SymbolFileDWARF;
25 class DWARFCompileUnit;
26 class DWARFDebugInfoEntry;
28 class DWARFMappedHash {
30 enum AtomType : uint16_t {
32 eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
33 eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that
34 // contains the item in question
35 eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1
36 // (if no tags exceed 255) or DW_FORM_data2
37 eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
38 eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags,
39 eAtomTypeQualNameHash = 6u // A 32 bit hash of the full qualified name
40 // (since all hash entries are basename only)
41 // For example a type like "std::vector<int>::iterator" would have a name of
43 // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not
45 // in debug info for a type when we know the fully qualified name.
48 // Bit definitions for the eAtomTypeTypeFlags flags
50 // Always set for C++, only set for ObjC if this is the
51 // @implementation for class
52 eTypeFlagClassIsImplementation = (1u << 1)
56 dw_offset_t cu_offset;
57 dw_offset_t offset; // The DIE offset
59 uint32_t type_flags; // Any flags for this DIEInfo
60 uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name
63 DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
71 typedef std::vector<DIEInfo> DIEInfoArray;
72 typedef std::vector<Atom> AtomArray;
76 Prologue(dw_offset_t _die_base_offset = 0);
80 bool ContainsAtom(AtomType atom_type) const;
84 void AppendAtom(AtomType type, dw_form_t form);
86 lldb::offset_t Read(const lldb_private::DataExtractor &data,
87 lldb::offset_t offset);
89 size_t GetByteSize() const;
91 size_t GetMinimumHashDataByteSize() const;
93 bool HashDataHasFixedByteSize() const;
95 // DIE offset base so die offsets in hash_data can be CU relative
96 dw_offset_t die_base_offset;
99 size_t min_hash_data_byte_size;
100 bool hash_data_has_fixed_byte_size;
103 class Header : public MappedHash::Header<Prologue> {
105 size_t GetByteSize(const HeaderData &header_data) override;
107 lldb::offset_t Read(lldb_private::DataExtractor &data,
108 lldb::offset_t offset) override;
110 bool Read(const lldb_private::DWARFDataExtractor &data,
111 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
113 void Dump(lldb_private::Stream &strm, const 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(const char *name, DIEArray &die_offsets);
141 size_t FindByNameAndTag(const char *name, const dw_tag_t tag,
142 DIEArray &die_offsets);
145 FindByNameAndTagAndQualifiedNameHash(const char *name, const dw_tag_t tag,
146 const uint32_t qualified_name_hash,
147 DIEArray &die_offsets);
149 size_t FindCompleteObjCClassByName(const char *name, 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(const char *name, DIEInfoArray &die_info_array);
159 Result GetHashDataForName(const char *name,
160 lldb::offset_t *hash_data_offset_ptr,
161 Pair &pair) const override;
163 const lldb_private::DWARFDataExtractor &m_data;
164 const 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_