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 SymbolFileDWARF_HashedNameToDIE_h_
10 #define SymbolFileDWARF_HashedNameToDIE_h_
11 
12 #include <vector>
13 
14 #include "lldb/Core/MappedHash.h"
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 
24 public:
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
37  // "iterator"
38  // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not
39  // have to pull
40  // in debug info for a type when we know the fully qualified name.
41  };
42 
43  // Bit definitions for the eAtomTypeTypeFlags flags
44  enum TypeFlags {
45  // Always set for C++, only set for ObjC if this is the
46  // @implementation for class
48  };
49 
50  struct DIEInfo {
52  dw_offset_t offset; // The DIE offset
54  uint32_t type_flags; // Any flags for this DIEInfo
55  uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name
56 
57  DIEInfo();
59  };
60 
61  struct Atom {
64  };
65 
66  typedef std::vector<DIEInfo> DIEInfoArray;
67  typedef std::vector<Atom> AtomArray;
68 
69  class Prologue {
70  public:
71  Prologue(dw_offset_t _die_base_offset = 0);
72 
73  void ClearAtoms();
74 
75  bool ContainsAtom(AtomType atom_type) const;
76 
77  void Clear();
78 
79  void AppendAtom(AtomType type, dw_form_t form);
80 
83 
84  size_t GetByteSize() const;
85 
86  size_t GetMinimumHashDataByteSize() const;
87 
88  bool HashDataHasFixedByteSize() const;
89 
90  // DIE offset base so die offsets in hash_data can be CU relative
92  AtomArray atoms;
96  };
97 
98  class Header : public MappedHash::Header<Prologue> {
99  public:
100  size_t GetByteSize(const HeaderData &header_data) override;
101 
103  lldb::offset_t offset) override;
104 
105  bool Read(const lldb_private::DWARFDataExtractor &data,
106  lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
107  };
108 
109  // A class for reading and using a saved hash table from a block of data
110  // in memory
112  : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
113  DIEInfoArray> {
114  public:
116  const lldb_private::DWARFDataExtractor &string_table,
117  const char *name);
118 
119  const char *GetStringForKeyType(KeyType key) const override;
120 
121  bool ReadHashData(uint32_t hash_data_offset,
122  HashData &hash_data) const override;
123 
124  size_t
125  AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression &regex,
126  DIEInfoArray &die_info_array) const;
127 
128  size_t AppendAllDIEsInRange(const uint32_t die_offset_start,
129  const uint32_t die_offset_end,
130  DIEInfoArray &die_info_array) const;
131 
132  size_t FindByName(llvm::StringRef name, DIEArray &die_offsets);
133 
134  size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
135  DIEArray &die_offsets);
136 
137  size_t FindByNameAndTagAndQualifiedNameHash(
138  llvm::StringRef name, const dw_tag_t tag,
139  const uint32_t qualified_name_hash, DIEArray &die_offsets);
140 
141  size_t FindCompleteObjCClassByName(llvm::StringRef name,
142  DIEArray &die_offsets,
143  bool must_be_implementation);
144 
145  protected:
146  Result AppendHashDataForRegularExpression(
147  const lldb_private::RegularExpression &regex,
148  lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
149 
150  size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
151 
152  Result GetHashDataForName(llvm::StringRef name,
153  lldb::offset_t *hash_data_offset_ptr,
154  Pair &pair) const override;
155 
158  std::string m_name;
159  };
160 
161  static void ExtractDIEArray(const DIEInfoArray &die_info_array,
162  DIEArray &die_offsets);
163 
164 protected:
165  static void ExtractDIEArray(const DIEInfoArray &die_info_array,
166  const dw_tag_t tag, DIEArray &die_offsets);
167 
168  static void ExtractDIEArray(const DIEInfoArray &die_info_array,
169  const dw_tag_t tag,
171  DIEArray &die_offsets);
172 
173  static void
174  ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
175  bool return_implementation_only_if_available,
176  DIEArray &die_offsets);
177 
178  static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array,
179  uint32_t type_flag_mask,
180  uint32_t type_flag_value,
181  DIEArray &die_offsets);
182 
183  static const char *GetAtomTypeName(uint16_t atom);
184 };
185 
186 #endif // SymbolFileDWARF_HashedNameToDIE_h_
An data extractor class.
Definition: DataExtractor.h:47
static void ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array, bool return_implementation_only_if_available, DIEArray &die_offsets)
static void ExtractDIEArray(const DIEInfoArray &die_info_array, DIEArray &die_offsets)
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
std::vector< DIERef > DIEArray
Definition: DIERef.h:51
uint64_t offset_t
Definition: lldb-types.h:87
std::vector< DIEInfo > DIEInfoArray
static const char * GetAtomTypeName(uint16_t atom)
lldb_private::DWARFDataExtractor m_string_table
lldb_private::DWARFDataExtractor m_data
static void ExtractTypesFromDIEArray(const DIEInfoArray &die_info_array, uint32_t type_flag_mask, uint32_t type_flag_value, DIEArray &die_offsets)
std::vector< Atom > AtomArray