]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ release_60 r321788,
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / HashedNameToDIE.h
1 //===-- HashedNameToDIE.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SymbolFileDWARF_HashedNameToDIE_h_
11 #define SymbolFileDWARF_HashedNameToDIE_h_
12
13 #include <vector>
14
15 #include "lldb/Core/MappedHash.h"
16 #include "lldb/Core/dwarf.h"
17 #include "lldb/Utility/RegularExpression.h"
18 #include "lldb/lldb-defines.h"
19
20 #include "DWARFDefines.h"
21 #include "DWARFFormValue.h"
22 #include "NameToDIE.h"
23
24 class SymbolFileDWARF;
25 class DWARFCompileUnit;
26 class DWARFDebugInfoEntry;
27
28 class DWARFMappedHash {
29 public:
30   enum AtomType : uint16_t {
31     eAtomTypeNULL = 0u,
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
42     // "iterator"
43     // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not
44     // have to pull
45     // in debug info for a type when we know the fully qualified name.
46   };
47
48   // Bit definitions for the eAtomTypeTypeFlags flags
49   enum TypeFlags {
50     // Always set for C++, only set for ObjC if this is the
51     // @implementation for class
52     eTypeFlagClassIsImplementation = (1u << 1)
53   };
54
55   struct DIEInfo {
56     dw_offset_t cu_offset;
57     dw_offset_t offset; // The DIE offset
58     dw_tag_t tag;
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
61
62     DIEInfo();
63     DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
64   };
65
66   struct Atom {
67     AtomType type;
68     dw_form_t form;
69   };
70
71   typedef std::vector<DIEInfo> DIEInfoArray;
72   typedef std::vector<Atom> AtomArray;
73
74   class Prologue {
75   public:
76     Prologue(dw_offset_t _die_base_offset = 0);
77
78     void ClearAtoms();
79
80     bool ContainsAtom(AtomType atom_type) const;
81
82     void Clear();
83
84     void AppendAtom(AtomType type, dw_form_t form);
85
86     lldb::offset_t Read(const lldb_private::DataExtractor &data,
87                         lldb::offset_t offset);
88
89     size_t GetByteSize() const;
90
91     size_t GetMinimumHashDataByteSize() const;
92
93     bool HashDataHasFixedByteSize() const;
94
95     // DIE offset base so die offsets in hash_data can be CU relative
96     dw_offset_t die_base_offset;
97     AtomArray atoms;
98     uint32_t atom_mask;
99     size_t min_hash_data_byte_size;
100     bool hash_data_has_fixed_byte_size;
101   };
102
103   class Header : public MappedHash::Header<Prologue> {
104   public:
105     size_t GetByteSize(const HeaderData &header_data) override;
106
107     lldb::offset_t Read(lldb_private::DataExtractor &data,
108                         lldb::offset_t offset) override;
109
110     bool Read(const lldb_private::DWARFDataExtractor &data,
111               lldb::offset_t *offset_ptr, DIEInfo &hash_data) const;
112
113     void Dump(lldb_private::Stream &strm, const DIEInfo &hash_data) const;
114   };
115
116   // A class for reading and using a saved hash table from a block of data
117   // in memory
118   class MemoryTable
119       : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header,
120                                        DIEInfoArray> {
121   public:
122     MemoryTable(lldb_private::DWARFDataExtractor &table_data,
123                 const lldb_private::DWARFDataExtractor &string_table,
124                 const char *name);
125
126     const char *GetStringForKeyType(KeyType key) const override;
127
128     bool ReadHashData(uint32_t hash_data_offset,
129                       HashData &hash_data) const override;
130
131     size_t
132     AppendAllDIEsThatMatchingRegex(const lldb_private::RegularExpression &regex,
133                                    DIEInfoArray &die_info_array) const;
134
135     size_t AppendAllDIEsInRange(const uint32_t die_offset_start,
136                                 const uint32_t die_offset_end,
137                                 DIEInfoArray &die_info_array) const;
138
139     size_t FindByName(const char *name, DIEArray &die_offsets);
140
141     size_t FindByNameAndTag(const char *name, const dw_tag_t tag,
142                             DIEArray &die_offsets);
143
144     size_t
145     FindByNameAndTagAndQualifiedNameHash(const char *name, const dw_tag_t tag,
146                                          const uint32_t qualified_name_hash,
147                                          DIEArray &die_offsets);
148
149     size_t FindCompleteObjCClassByName(const char *name, DIEArray &die_offsets,
150                                        bool must_be_implementation);
151
152   protected:
153     Result AppendHashDataForRegularExpression(
154         const lldb_private::RegularExpression &regex,
155         lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
156
157     size_t FindByName(const char *name, DIEInfoArray &die_info_array);
158
159     Result GetHashDataForName(const char *name,
160                               lldb::offset_t *hash_data_offset_ptr,
161                               Pair &pair) const override;
162
163     const lldb_private::DWARFDataExtractor &m_data;
164     const lldb_private::DWARFDataExtractor &m_string_table;
165     std::string m_name;
166   };
167
168   static void ExtractDIEArray(const DIEInfoArray &die_info_array,
169                               DIEArray &die_offsets);
170
171 protected:
172   static void ExtractDIEArray(const DIEInfoArray &die_info_array,
173                               const dw_tag_t tag, DIEArray &die_offsets);
174
175   static void ExtractDIEArray(const DIEInfoArray &die_info_array,
176                               const dw_tag_t tag,
177                               const uint32_t qualified_name_hash,
178                               DIEArray &die_offsets);
179
180   static void
181   ExtractClassOrStructDIEArray(const DIEInfoArray &die_info_array,
182                                bool return_implementation_only_if_available,
183                                DIEArray &die_offsets);
184
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);
189
190   static const char *GetAtomTypeName(uint16_t atom);
191 };
192
193 #endif // SymbolFileDWARF_HashedNameToDIE_h_