LLDB mainline
HashedNameToDIE.h
Go to the documentation of this file.
1//===-- HashedNameToDIE.h ---------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_HASHEDNAMETODIE_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_HASHEDNAMETODIE_H
11
12#include <vector>
13
15#include "lldb/Core/dwarf.h"
17#include "lldb/lldb-defines.h"
18
19#include "DWARFDefines.h"
20#include "DWARFFormValue.h"
21#include "NameToDIE.h"
22
24public:
27 /// DIE offset, check form for encoding.
29 /// DIE offset of the compiler unit header that contains the item in
30 /// question.
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.
37 // Flags from enum TypeFlags.
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.
45 };
46
47 /// Bit definitions for the eAtomTypeTypeFlags flags.
48 enum TypeFlags {
49 /// Always set for C++, only set for ObjC if this is the
50 /// @implementation for class.
52 };
53
54 struct DIEInfo {
56 dw_tag_t tag = llvm::dwarf::DW_TAG_null;
57
58 /// Any flags for this DIEInfo.
60
61 /// A 32 bit hash of the fully qualified name.
63
64 DIEInfo() = default;
66
67 explicit operator DIERef() const {
68 return DIERef(std::nullopt, DIERef::Section::DebugInfo, die_offset);
69 }
70 };
71
72 struct Atom {
75 };
76
77 typedef std::vector<DIEInfo> DIEInfoArray;
78 typedef std::vector<Atom> AtomArray;
79
80 class Prologue {
81 public:
82 Prologue(dw_offset_t _die_base_offset = 0);
83
84 void ClearAtoms();
85
86 bool ContainsAtom(AtomType atom_type) const;
87
88 void Clear();
89
90 void AppendAtom(AtomType type, dw_form_t form);
91
93 lldb::offset_t offset);
94
95 size_t GetByteSize() const;
96
97 size_t GetMinimumHashDataByteSize() const;
98
99 bool HashDataHasFixedByteSize() const;
100
101 /// DIE offset base so die offsets in hash_data can be CU relative.
107 };
108
109 class Header : public MappedHash::Header<Prologue> {
110 public:
111 size_t GetByteSize(const HeaderData &header_data) override;
112
114 lldb::offset_t offset) override;
115
116 bool Read(const lldb_private::DWARFDataExtractor &data,
117 lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
118 };
119
120 /// A class for reading and using a saved hash table from a block of data in
121 /// memory.
123 : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
124 DIEInfoArray> {
125 public:
127 const lldb_private::DWARFDataExtractor &string_table,
128 const char *name);
129
130 const char *GetStringForKeyType(KeyType key) const override;
131
132 bool ReadHashData(uint32_t hash_data_offset,
133 HashData &hash_data) const override;
134
135 void
137 DIEInfoArray &die_info_array) const;
138
139 void AppendAllDIEsInRange(const uint32_t die_offset_start,
140 const uint32_t die_offset_end,
141 DIEInfoArray &die_info_array) const;
142
143 bool FindByName(llvm::StringRef name,
144 llvm::function_ref<bool(DIERef ref)> callback);
145
146 void FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
147 llvm::function_ref<bool(DIERef ref)> callback);
148
150 llvm::StringRef name, const dw_tag_t tag,
151 const uint32_t qualified_name_hash,
152 llvm::function_ref<bool(DIERef ref)> callback);
153
154 void
155 FindCompleteObjCClassByName(llvm::StringRef name,
156 llvm::function_ref<bool(DIERef ref)> callback,
157 bool must_be_implementation);
158
159 protected:
162 lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
163
164 void FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
165
166 Result GetHashDataForName(llvm::StringRef name,
167 lldb::offset_t *hash_data_offset_ptr,
168 Pair &pair) const override;
169
172 std::string m_name;
173 };
174
175 static bool ExtractDIEArray(const DIEInfoArray &die_info_array,
176 llvm::function_ref<bool(DIERef ref)> callback);
177
178protected:
179 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
180 const dw_tag_t tag,
181 llvm::function_ref<bool(DIERef ref)> callback);
182
183 static void ExtractDIEArray(const DIEInfoArray &die_info_array,
184 const dw_tag_t tag,
185 const uint32_t qualified_name_hash,
186 llvm::function_ref<bool(DIERef ref)> callback);
187
188 static void
189 ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
190 bool return_implementation_only_if_available,
191 llvm::function_ref<bool(DIERef ref)> callback);
192
193 static void
194 ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array,
195 uint32_t type_flag_mask, uint32_t type_flag_value,
196 llvm::function_ref<bool(DIERef ref)> callback);
197
198 static const char *GetAtomTypeName(uint16_t atom);
199};
200
201#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_HASHEDNAMETODIE_H
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:28
@ DebugInfo
Definition: DIERef.h:30
lldb::offset_t Read(lldb_private::DataExtractor &data, lldb::offset_t offset) override
A class for reading and using a saved hash table from a block of data in memory.
void FindCompleteObjCClassByName(llvm::StringRef name, llvm::function_ref< bool(DIERef ref)> callback, bool must_be_implementation)
Result AppendHashDataForRegularExpression(const lldb_private::RegularExpression &regex, lldb::offset_t *hash_data_offset_ptr, Pair &pair) const
lldb_private::DWARFDataExtractor m_string_table
Result GetHashDataForName(llvm::StringRef name, lldb::offset_t *hash_data_offset_ptr, Pair &pair) const override
void FindByNameAndTagAndQualifiedNameHash(llvm::StringRef name, const dw_tag_t tag, const uint32_t qualified_name_hash, llvm::function_ref< bool(DIERef ref)> callback)
bool ReadHashData(uint32_t hash_data_offset, HashData &hash_data) const override
void AppendAllDIEsInRange(const uint32_t die_offset_start, const uint32_t die_offset_end, DIEInfoArray &die_info_array) const
void FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag, llvm::function_ref< bool(DIERef ref)> callback)
bool FindByName(llvm::StringRef name, llvm::function_ref< bool(DIERef ref)> callback)
const char * GetStringForKeyType(KeyType key) const override
void AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression &regex, DIEInfoArray &die_info_array) const
lldb_private::DWARFDataExtractor m_data
lldb::offset_t Read(const lldb_private::DataExtractor &data, lldb::offset_t offset)
size_t GetMinimumHashDataByteSize() const
dw_offset_t die_base_offset
DIE offset base so die offsets in hash_data can be CU relative.
void AppendAtom(AtomType type, dw_form_t form)
bool ContainsAtom(AtomType atom_type) const
static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array, uint32_t type_flag_mask, uint32_t type_flag_value, llvm::function_ref< bool(DIERef ref)> callback)
static const char * GetAtomTypeName(uint16_t atom)
static void ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array, bool return_implementation_only_if_available, llvm::function_ref< bool(DIERef ref)> callback)
TypeFlags
Bit definitions for the eAtomTypeTypeFlags flags.
@ eTypeFlagClassIsImplementation
Always set for C++, only set for ObjC if this is the @implementation for class.
std::vector< Atom > AtomArray
@ eAtomTypeQualNameHash
A 32 bit hash of the full qualified name (since all hash entries are basename only) For example a typ...
@ eAtomTypeCUOffset
DIE offset of the compiler unit header that contains the item in question.
@ eAtomTypeDIEOffset
DIE offset, check form for encoding.
@ eAtomTypeTag
DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed 255) or DW_FORM_data2.
std::vector< DIEInfo > DIEInfoArray
static bool ExtractDIEArray(const DIEInfoArray &die_info_array, llvm::function_ref< bool(DIERef ref)> callback)
An data extractor class.
Definition: DataExtractor.h:48
uint64_t dw_offset_t
Definition: dwarf.h:31
#define DW_INVALID_OFFSET
Definition: dwarf.h:36
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:26
llvm::dwarf::Form dw_form_t
Definition: dwarf.h:25
uint64_t offset_t
Definition: lldb-types.h:83
uint32_t type_flags
Any flags for this DIEInfo.
uint32_t qualified_name_hash
A 32 bit hash of the fully qualified name.