LLVM 23.0.0git
SymbolCache.h
Go to the documentation of this file.
1//==- SymbolCache.h - Cache of native symbols and ids ------------*- 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 LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H
11
12#include "llvm/ADT/DenseMap.h"
23
24#include <memory>
25#include <vector>
26
27namespace llvm {
28namespace codeview {
29class InlineSiteSym;
31} // namespace codeview
32namespace pdb {
33class IPDBSourceFile;
34class NativeSession;
35class PDBSymbol;
37class DbiStream;
38
40 NativeSession &Session;
41 DbiStream *Dbi = nullptr;
42
43 /// Cache of all stable symbols, indexed by SymIndexId. Just because a
44 /// symbol has been parsed does not imply that it will be stable and have
45 /// an Id. Id allocation is an implementation, with the only guarantee
46 /// being that once an Id is allocated, the symbol can be assumed to be
47 /// cached.
48 mutable std::vector<std::unique_ptr<NativeRawSymbol>> Cache;
49
50 /// For type records from the TPI stream which have been paresd and cached,
51 /// stores a mapping to SymIndexId of the cached symbol.
52 mutable DenseMap<codeview::TypeIndex, SymIndexId> TypeIndexToSymbolId;
53
54 /// For field list members which have been parsed and cached, stores a mapping
55 /// from (IndexOfClass, MemberIndex) to the corresponding SymIndexId of the
56 /// cached symbol.
58 FieldListMembersToSymbolId;
59
60 /// List of SymIndexIds for each compiland, indexed by compiland index as they
61 /// appear in the PDB file.
62 mutable std::vector<SymIndexId> Compilands;
63
64 /// List of source files, indexed by unique source file index.
65 mutable std::vector<std::unique_ptr<NativeSourceFile>> SourceFiles;
66
67 /// Map from string table offset to source file Id.
68 mutable DenseMap<uint32_t, SymIndexId> FileNameOffsetToId;
69
70 /// Map from global symbol offset to SymIndexId.
71 mutable DenseMap<uint32_t, SymIndexId> GlobalOffsetToSymbolId;
72
73 /// Map from virtual address range to function symbols.
74 using IMapTy =
76 IMapTy::Allocator IMapAllocator;
77 mutable IMapTy AddressToSymbolId;
78 DenseSet<uint16_t> FuncSymCachedModIndexes;
79
80 /// Map from segment and code offset to public symbols.
82 AddressToPublicSymId;
83
84 /// Map from module index and symbol table offset to SymIndexId.
86 SymTabOffsetToSymbolId;
87
88 struct LineTableEntry {
89 uint64_t Addr;
91 uint32_t ColumnNumber;
92 uint32_t FileNameIndex;
93 bool IsTerminalEntry;
94 };
95
96 std::vector<LineTableEntry> findLineTable(uint16_t Modi) const;
98
99 SymIndexId createSymbolPlaceholder() const {
100 SymIndexId Id = Cache.size();
101 Cache.push_back(nullptr);
102 return Id;
103 }
104
105 template <typename ConcreteSymbolT, typename CVRecordT, typename... Args>
106 SymIndexId createSymbolForType(codeview::TypeIndex TI, codeview::CVType CVT,
107 Args &&...ConstructorArgs) const {
108 CVRecordT Record;
109 if (auto EC =
111 consumeError(std::move(EC));
112 return 0;
113 }
114
116 TI, std::move(Record), std::forward<Args>(ConstructorArgs)...);
117 }
118
119 SymIndexId createSymbolForModifiedType(codeview::TypeIndex ModifierTI,
120 codeview::CVType CVT) const;
121
122 SymIndexId createSimpleType(codeview::TypeIndex TI,
123 codeview::ModifierOptions Mods) const;
124
125 std::unique_ptr<PDBSymbol> findFunctionSymbolByVA(uint64_t VA);
126 std::unique_ptr<PDBSymbol> findPublicSymbolBySectOffset(uint32_t Sect,
128
129public:
131
132 template <typename ConcreteSymbolT, typename... Args>
133 SymIndexId createSymbol(Args &&...ConstructorArgs) const {
134 SymIndexId Id = Cache.size();
135
136 // Initial construction must not access the cache, since it must be done
137 // atomically.
138 auto Result = std::make_unique<ConcreteSymbolT>(
139 Session, Id, std::forward<Args>(ConstructorArgs)...);
140 Result->SymbolId = Id;
141
142 NativeRawSymbol *NRS = static_cast<NativeRawSymbol *>(Result.get());
143 Cache.push_back(std::move(Result));
144
145 // After the item is in the cache, we can do further initialization which
146 // is then allowed to access the cache.
147 NRS->initialize();
148 return Id;
149 }
150
151 LLVM_ABI std::unique_ptr<IPDBEnumSymbols>
153
154 LLVM_ABI std::unique_ptr<IPDBEnumSymbols>
155 createTypeEnumerator(std::vector<codeview::TypeLeafKind> Kinds);
156
157 LLVM_ABI std::unique_ptr<IPDBEnumSymbols>
159
161
162 template <typename ConcreteSymbolT, typename... Args>
164 uint32_t Index,
165 Args &&... ConstructorArgs) {
166 SymIndexId SymId = Cache.size();
167 std::pair<codeview::TypeIndex, uint32_t> Key{FieldListTI, Index};
168 auto Result = FieldListMembersToSymbolId.try_emplace(Key, SymId);
169 if (Result.second)
170 SymId =
171 createSymbol<ConcreteSymbolT>(std::forward<Args>(ConstructorArgs)...);
172 else
173 SymId = Result.first->second;
174 return SymId;
175 }
176
179 uint64_t ParentAddr,
180 uint16_t Modi,
181 uint32_t RecordOffset) const;
182
183 LLVM_ABI std::unique_ptr<PDBSymbol> findSymbolByVA(uint64_t VA,
185
186 LLVM_ABI std::unique_ptr<IPDBEnumLineNumbers>
188
189 LLVM_ABI std::unique_ptr<PDBSymbolCompiland>
192
193 LLVM_ABI std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const;
194
196
197 template <typename ConcreteT>
198 ConcreteT &getNativeSymbolById(SymIndexId SymbolId) const {
199 return static_cast<ConcreteT &>(getNativeSymbolById(SymbolId));
200 }
201
202 LLVM_ABI std::unique_ptr<IPDBSourceFile>
203 getSourceFileById(SymIndexId FileId) const;
206};
207
208} // namespace pdb
209} // namespace llvm
210
211#endif
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
This file implements a coalescing interval map for small objects.
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
static Error deserializeAs(CVType &CVT, T &Record)
A 32-bit type reference.
Definition TypeIndex.h:97
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e....
Definition PDBSymbol.h:72
LLVM_ABI std::unique_ptr< IPDBEnumSymbols > createGlobalsEnumerator(codeview::SymbolKind Kind)
LLVM_ABI SymIndexId getOrCreateInlineSymbol(codeview::InlineSiteSym Sym, uint64_t ParentAddr, uint16_t Modi, uint32_t RecordOffset) const
SymIndexId getOrCreateFieldListMember(codeview::TypeIndex FieldListTI, uint32_t Index, Args &&... ConstructorArgs)
LLVM_ABI std::unique_ptr< IPDBEnumSymbols > createTypeEnumerator(codeview::TypeLeafKind Kind)
LLVM_ABI std::unique_ptr< PDBSymbol > findSymbolByVA(uint64_t VA, PDB_SymType Type)
LLVM_ABI std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
LLVM_ABI SymbolCache(NativeSession &Session, DbiStream *Dbi)
LLVM_ABI SymIndexId getOrCreateSourceFile(const codeview::FileChecksumEntry &Checksum) const
LLVM_ABI SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
LLVM_ABI NativeRawSymbol & getNativeSymbolById(SymIndexId SymbolId) const
ConcreteT & getNativeSymbolById(SymIndexId SymbolId) const
LLVM_ABI std::unique_ptr< PDBSymbolCompiland > getOrCreateCompiland(uint32_t Index)
LLVM_ABI uint32_t getNumCompilands() const
LLVM_ABI std::unique_ptr< IPDBSourceFile > getSourceFileById(SymIndexId FileId) const
LLVM_ABI std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByVA(uint64_t VA, uint32_t Length) const
SymIndexId createSymbol(Args &&...ConstructorArgs) const
LLVM_ABI SymIndexId getOrCreateGlobalSymbolByOffset(uint32_t Offset)
CVRecord< TypeLeafKind > CVType
Definition CVRecord.h:64
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition CodeView.h:34
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition CodeView.h:48
ModifierOptions
Equivalent to CV_modifier_t.
Definition CodeView.h:283
uint32_t SymIndexId
Definition PDBTypes.h:26
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition PDBTypes.h:243
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:532
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106