]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
Upgrade to OpenPAM Radula.
[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/lldb-defines.h"
16 #include "lldb/Core/dwarf.h"
17 #include "lldb/Core/RegularExpression.h"
18 #include "lldb/Core/MappedHash.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 {
30 public:
31     enum AtomType : uint16_t
32     {
33         eAtomTypeNULL         = 0u,
34         eAtomTypeDIEOffset    = 1u, // DIE offset, check form for encoding
35         eAtomTypeCUOffset     = 2u, // DIE offset of the compiler unit header that contains the item in question
36         eAtomTypeTag          = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1 (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 (since all hash entries are basename only)
40                                     // For example a type like "std::vector<int>::iterator" would have a name of "iterator"
41                                     // and a 32 bit hash for "std::vector<int>::iterator" to allow us to not have to pull
42                                     // in debug info for a type when we know the fully qualified name.
43     };
44
45     // Bit definitions for the eAtomTypeTypeFlags flags
46     enum TypeFlags
47     {
48         // Always set for C++, only set for ObjC if this is the 
49         // @implementation for class
50         eTypeFlagClassIsImplementation  = ( 1u << 1 )
51     };
52
53     struct DIEInfo
54     {
55         dw_offset_t cu_offset;
56         dw_offset_t offset;  // The DIE offset
57         dw_tag_t tag;
58         uint32_t type_flags; // Any flags for this DIEInfo
59         uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name
60
61         DIEInfo ();
62         DIEInfo (dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
63     };
64
65     struct Atom
66     {
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     {
76     public:
77         Prologue (dw_offset_t _die_base_offset = 0);
78
79         void
80         ClearAtoms ();
81
82         bool
83         ContainsAtom (AtomType atom_type) const;
84
85         void
86         Clear ();
87
88         void
89         AppendAtom (AtomType type, dw_form_t form);
90
91         lldb::offset_t
92         Read (const lldb_private::DataExtractor &data, lldb::offset_t offset);
93
94         size_t
95         GetByteSize () const;
96
97         size_t
98         GetMinimumHashDataByteSize () const;
99
100         bool
101         HashDataHasFixedByteSize() const;
102
103         // DIE offset base so die offsets in hash_data can be CU relative
104         dw_offset_t die_base_offset;
105         AtomArray atoms;
106         uint32_t atom_mask;
107         size_t min_hash_data_byte_size;
108         bool hash_data_has_fixed_byte_size;
109     };
110     
111     class Header : public MappedHash::Header<Prologue>
112     {
113     public:
114         size_t
115         GetByteSize (const HeaderData &header_data) override;
116
117         lldb::offset_t
118         Read (lldb_private::DataExtractor &data, lldb::offset_t offset) override;
119
120         bool
121         Read (const lldb_private::DWARFDataExtractor &data, 
122               lldb::offset_t *offset_ptr, 
123               DIEInfo &hash_data) const;
124
125         void
126         Dump (lldb_private::Stream& strm, const DIEInfo &hash_data) const;
127     };
128
129     // A class for reading and using a saved hash table from a block of data
130     // in memory
131     class MemoryTable : public MappedHash::MemoryTable<uint32_t, DWARFMappedHash::Header, DIEInfoArray>
132     {
133     public:
134         MemoryTable (lldb_private::DWARFDataExtractor &table_data, 
135                      const lldb_private::DWARFDataExtractor &string_table,
136                      const char *name);
137
138         const char *
139         GetStringForKeyType (KeyType key) const override;
140         
141         bool
142         ReadHashData (uint32_t hash_data_offset, HashData &hash_data) const override;
143
144         size_t
145         AppendAllDIEsThatMatchingRegex (const lldb_private::RegularExpression& regex, 
146                                         DIEInfoArray &die_info_array) const;
147
148         size_t
149         AppendAllDIEsInRange (const uint32_t die_offset_start, 
150                               const uint32_t die_offset_end, 
151                               DIEInfoArray &die_info_array) const;
152
153         size_t
154         FindByName (const char *name, DIEArray &die_offsets);
155
156         size_t
157         FindByNameAndTag (const char *name, const dw_tag_t tag, DIEArray &die_offsets);
158
159         size_t
160         FindByNameAndTagAndQualifiedNameHash (const char *name,
161                                               const dw_tag_t tag,
162                                               const uint32_t qualified_name_hash,
163                                               DIEArray &die_offsets);
164
165         size_t
166         FindCompleteObjCClassByName (const char *name,
167                                      DIEArray &die_offsets,
168                                      bool must_be_implementation);
169
170     protected:
171         Result
172         AppendHashDataForRegularExpression (const lldb_private::RegularExpression& regex,
173                                             lldb::offset_t* hash_data_offset_ptr, 
174                                             Pair &pair) const;
175
176         size_t 
177         FindByName (const char *name, DIEInfoArray &die_info_array);
178
179         Result
180         GetHashDataForName (const char *name,
181                             lldb::offset_t* hash_data_offset_ptr,
182                             Pair &pair) const override;
183
184         const lldb_private::DWARFDataExtractor &m_data;
185         const lldb_private::DWARFDataExtractor &m_string_table;
186         std::string m_name;
187     };
188
189     static void
190     ExtractDIEArray (const DIEInfoArray &die_info_array, DIEArray &die_offsets);
191
192 protected:
193     static void
194     ExtractDIEArray (const DIEInfoArray &die_info_array,
195                      const dw_tag_t tag,
196                      DIEArray &die_offsets);
197
198     static void
199     ExtractDIEArray (const DIEInfoArray &die_info_array,
200                      const dw_tag_t tag,
201                      const uint32_t qualified_name_hash,
202                      DIEArray &die_offsets);
203
204     static void
205     ExtractClassOrStructDIEArray (const DIEInfoArray &die_info_array,
206                                   bool return_implementation_only_if_available,
207                                   DIEArray &die_offsets);
208
209     static void
210     ExtractTypesFromDIEArray (const DIEInfoArray &die_info_array,
211                               uint32_t type_flag_mask,
212                               uint32_t type_flag_value,
213                               DIEArray &die_offsets);
214
215     static const char *
216     GetAtomTypeName (uint16_t atom);
217 };
218
219 #endif  // SymbolFileDWARF_HashedNameToDIE_h_