Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SymbolCache.cpp
Go to the documentation of this file.
1#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
2
3#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
4#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
5#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
6#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
7#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
8#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
9#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
10#include "llvm/DebugInfo/CodeView/TypeRecord.h"
11#include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h"
12#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
13#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
14#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
15#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
16#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
17#include "llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h"
18#include "llvm/DebugInfo/PDB/Native/NativeEnumLineNumbers.h"
19#include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
20#include "llvm/DebugInfo/PDB/Native/NativeFunctionSymbol.h"
21#include "llvm/DebugInfo/PDB/Native/NativeInlineSiteSymbol.h"
22#include "llvm/DebugInfo/PDB/Native/NativeLineNumber.h"
23#include "llvm/DebugInfo/PDB/Native/NativePublicSymbol.h"
24#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
25#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
26#include "llvm/DebugInfo/PDB/Native/NativeTypeArray.h"
27#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
28#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
29#include "llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h"
30#include "llvm/DebugInfo/PDB/Native/NativeTypePointer.h"
31#include "llvm/DebugInfo/PDB/Native/NativeTypeTypedef.h"
32#include "llvm/DebugInfo/PDB/Native/NativeTypeUDT.h"
33#include "llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h"
34#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
35#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
36#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
37#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
38#include "llvm/DebugInfo/PDB/PDBSymbol.h"
39#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
40
41using namespacellvm;
42using namespacellvm::codeview;
43using namespacellvm::pdb;
44
45// Maps codeview::SimpleTypeKind of a built-in type to the parameters necessary
46// to instantiate a NativeBuiltinSymbol for that type.
47staticconststructBuiltinTypeEntry {
48codeview::SimpleTypeKindKind;
49PDB_BuiltinTypeType;
50uint32_tSize;
51}BuiltinTypes[] = {
52 {codeview::SimpleTypeKind::None, PDB_BuiltinType::None, 0},
53 {codeview::SimpleTypeKind::Void, PDB_BuiltinType::Void, 0},
54 {codeview::SimpleTypeKind::HResult, PDB_BuiltinType::HResult, 4},
55 {codeview::SimpleTypeKind::Int16Short, PDB_BuiltinType::Int, 2},
56 {codeview::SimpleTypeKind::UInt16Short, PDB_BuiltinType::UInt, 2},
57 {codeview::SimpleTypeKind::Int32, PDB_BuiltinType::Int, 4},
58 {codeview::SimpleTypeKind::UInt32, PDB_BuiltinType::UInt, 4},
59 {codeview::SimpleTypeKind::Int32Long, PDB_BuiltinType::Int, 4},
60 {codeview::SimpleTypeKind::UInt32Long, PDB_BuiltinType::UInt, 4},
61 {codeview::SimpleTypeKind::Int64Quad, PDB_BuiltinType::Int, 8},
62 {codeview::SimpleTypeKind::UInt64Quad, PDB_BuiltinType::UInt, 8},
63 {codeview::SimpleTypeKind::NarrowCharacter, PDB_BuiltinType::Char, 1},
64 {codeview::SimpleTypeKind::WideCharacter, PDB_BuiltinType::WCharT, 2},
65 {codeview::SimpleTypeKind::Character16, PDB_BuiltinType::Char16, 2},
66 {codeview::SimpleTypeKind::Character32, PDB_BuiltinType::Char32, 4},
67 {codeview::SimpleTypeKind::Character8, PDB_BuiltinType::Char8, 1},
68 {codeview::SimpleTypeKind::SignedCharacter, PDB_BuiltinType::Char, 1},
69 {codeview::SimpleTypeKind::UnsignedCharacter, PDB_BuiltinType::UInt, 1},
70 {codeview::SimpleTypeKind::Float32, PDB_BuiltinType::Float, 4},
71 {codeview::SimpleTypeKind::Float64, PDB_BuiltinType::Float, 8},
72 {codeview::SimpleTypeKind::Float80, PDB_BuiltinType::Float, 10},
73 {codeview::SimpleTypeKind::Boolean8, PDB_BuiltinType::Bool, 1},
74// This table can be grown as necessary, but these are the only types we've
75// needed so far.
76};
77
78SymbolCache::SymbolCache(NativeSession &Session,DbiStream *Dbi)
79 : Session(Session), Dbi(Dbi) {
80// Id 0 is reserved for the invalid symbol.
81 Cache.push_back(nullptr);
82 SourceFiles.push_back(nullptr);
83
84if (Dbi)
85 Compilands.resize(Dbi->modules().getModuleCount());
86}
87
88std::unique_ptr<IPDBEnumSymbols>
89SymbolCache::createTypeEnumerator(TypeLeafKind Kind) {
90returncreateTypeEnumerator(std::vector<TypeLeafKind>{Kind});
91}
92
93std::unique_ptr<IPDBEnumSymbols>
94SymbolCache::createTypeEnumerator(std::vector<TypeLeafKind> Kinds) {
95auto Tpi = Session.getPDBFile().getPDBTpiStream();
96if (!Tpi) {
97consumeError(Tpi.takeError());
98returnnullptr;
99 }
100auto &Types = Tpi->typeCollection();
101return std::unique_ptr<IPDBEnumSymbols>(
102newNativeEnumTypes(Session, Types, std::move(Kinds)));
103}
104
105std::unique_ptr<IPDBEnumSymbols>
106SymbolCache::createGlobalsEnumerator(codeview::SymbolKind Kind) {
107return std::unique_ptr<IPDBEnumSymbols>(
108newNativeEnumGlobals(Session, {Kind}));
109}
110
111SymIndexId SymbolCache::createSimpleType(TypeIndex Index,
112ModifierOptions Mods) const{
113if (Index.getSimpleMode() !=codeview::SimpleTypeMode::Direct)
114return createSymbol<NativeTypePointer>(Index);
115
116constauto Kind = Index.getSimpleKind();
117constauto It =
118llvm::find_if(BuiltinTypes, [Kind](constBuiltinTypeEntry &Builtin) {
119return Builtin.Kind == Kind;
120 });
121if (It == std::end(BuiltinTypes))
122return 0;
123return createSymbol<NativeTypeBuiltin>(Mods, It->Type, It->Size);
124}
125
126SymIndexId
127SymbolCache::createSymbolForModifiedType(codeview::TypeIndex ModifierTI,
128codeview::CVType CVT) const{
129ModifierRecordRecord;
130if (autoEC = TypeDeserializer::deserializeAs<ModifierRecord>(CVT,Record)) {
131consumeError(std::move(EC));
132return 0;
133 }
134
135if (Record.ModifiedType.isSimple())
136return createSimpleType(Record.ModifiedType,Record.Modifiers);
137
138// Make sure we create and cache a record for the unmodified type.
139SymIndexId UnmodifiedId =findSymbolByTypeIndex(Record.ModifiedType);
140NativeRawSymbol &UnmodifiedNRS = *Cache[UnmodifiedId];
141
142switch (UnmodifiedNRS.getSymTag()) {
143casePDB_SymType::Enum:
144return createSymbol<NativeTypeEnum>(
145static_cast<NativeTypeEnum &>(UnmodifiedNRS), std::move(Record));
146casePDB_SymType::UDT:
147return createSymbol<NativeTypeUDT>(
148static_cast<NativeTypeUDT &>(UnmodifiedNRS), std::move(Record));
149default:
150// No other types can be modified. (LF_POINTER, for example, records
151// its modifiers a different way.
152assert(false &&"Invalid LF_MODIFIER record");
153break;
154 }
155return 0;
156}
157
158SymIndexIdSymbolCache::findSymbolByTypeIndex(codeview::TypeIndex Index) const{
159// First see if it's already in our cache.
160constauto Entry = TypeIndexToSymbolId.find(Index);
161if (Entry != TypeIndexToSymbolId.end())
162return Entry->second;
163
164// Symbols for built-in types are created on the fly.
165if (Index.isSimple()) {
166SymIndexId Result = createSimpleType(Index, ModifierOptions::None);
167assert(TypeIndexToSymbolId.count(Index) == 0);
168 TypeIndexToSymbolId[Index] = Result;
169return Result;
170 }
171
172// We need to instantiate and cache the desired type symbol.
173auto Tpi = Session.getPDBFile().getPDBTpiStream();
174if (!Tpi) {
175consumeError(Tpi.takeError());
176return 0;
177 }
178codeview::LazyRandomTypeCollection &Types = Tpi->typeCollection();
179codeview::CVType CVT = Types.getType(Index);
180
181if (isUdtForwardRef(CVT)) {
182Expected<TypeIndex> EFD = Tpi->findFullDeclForForwardRef(Index);
183
184if (!EFD)
185consumeError(EFD.takeError());
186elseif (*EFD != Index) {
187assert(!isUdtForwardRef(Types.getType(*EFD)));
188SymIndexId Result =findSymbolByTypeIndex(*EFD);
189// Record a mapping from ForwardRef -> SymIndex of complete type so that
190// we'll take the fast path next time.
191assert(TypeIndexToSymbolId.count(Index) == 0);
192 TypeIndexToSymbolId[Index] = Result;
193return Result;
194 }
195 }
196
197// At this point if we still have a forward ref udt it means the full decl was
198// not in the PDB. We just have to deal with it and use the forward ref.
199SymIndexId Id = 0;
200switch (CVT.kind()) {
201case codeview::LF_ENUM:
202 Id = createSymbolForType<NativeTypeEnum, EnumRecord>(Index, std::move(CVT));
203break;
204case codeview::LF_ARRAY:
205 Id = createSymbolForType<NativeTypeArray, ArrayRecord>(Index,
206 std::move(CVT));
207break;
208case codeview::LF_CLASS:
209case codeview::LF_STRUCTURE:
210case codeview::LF_INTERFACE:
211 Id = createSymbolForType<NativeTypeUDT, ClassRecord>(Index, std::move(CVT));
212break;
213case codeview::LF_UNION:
214 Id = createSymbolForType<NativeTypeUDT, UnionRecord>(Index, std::move(CVT));
215break;
216case codeview::LF_POINTER:
217 Id = createSymbolForType<NativeTypePointer, PointerRecord>(Index,
218 std::move(CVT));
219break;
220case codeview::LF_MODIFIER:
221 Id = createSymbolForModifiedType(Index, std::move(CVT));
222break;
223case codeview::LF_PROCEDURE:
224 Id = createSymbolForType<NativeTypeFunctionSig, ProcedureRecord>(
225 Index, std::move(CVT));
226break;
227case codeview::LF_MFUNCTION:
228 Id = createSymbolForType<NativeTypeFunctionSig, MemberFunctionRecord>(
229 Index, std::move(CVT));
230break;
231case codeview::LF_VTSHAPE:
232 Id = createSymbolForType<NativeTypeVTShape, VFTableShapeRecord>(
233 Index, std::move(CVT));
234break;
235default:
236 Id = createSymbolPlaceholder();
237break;
238 }
239if (Id != 0) {
240assert(TypeIndexToSymbolId.count(Index) == 0);
241 TypeIndexToSymbolId[Index] = Id;
242 }
243return Id;
244}
245
246std::unique_ptr<PDBSymbol>
247SymbolCache::getSymbolById(SymIndexId SymbolId) const{
248assert(SymbolId < Cache.size());
249
250// Id 0 is reserved.
251if (SymbolId == 0 || SymbolId >= Cache.size())
252returnnullptr;
253
254// Make sure to handle the case where we've inserted a placeholder symbol
255// for types we don't yet support.
256NativeRawSymbol *NRS = Cache[SymbolId].get();
257if (!NRS)
258returnnullptr;
259
260returnPDBSymbol::create(Session, *NRS);
261}
262
263NativeRawSymbol &SymbolCache::getNativeSymbolById(SymIndexId SymbolId) const{
264return *Cache[SymbolId];
265}
266
267uint32_tSymbolCache::getNumCompilands() const{
268if (!Dbi)
269return 0;
270
271return Dbi->modules().getModuleCount();
272}
273
274SymIndexIdSymbolCache::getOrCreateGlobalSymbolByOffset(uint32_tOffset) {
275auto Iter = GlobalOffsetToSymbolId.find(Offset);
276if (Iter != GlobalOffsetToSymbolId.end())
277return Iter->second;
278
279SymbolStream &SS =cantFail(Session.getPDBFile().getPDBSymbolStream());
280CVSymbol CVS = SS.readRecord(Offset);
281SymIndexId Id = 0;
282switch (CVS.kind()) {
283case SymbolKind::S_UDT: {
284UDTSym US =cantFail(SymbolDeserializer::deserializeAs<UDTSym>(CVS));
285 Id = createSymbol<NativeTypeTypedef>(std::move(US));
286break;
287 }
288default:
289 Id = createSymbolPlaceholder();
290break;
291 }
292if (Id != 0) {
293assert(GlobalOffsetToSymbolId.count(Offset) == 0);
294 GlobalOffsetToSymbolId[Offset] = Id;
295 }
296
297return Id;
298}
299
300SymIndexIdSymbolCache::getOrCreateInlineSymbol(InlineSiteSymSym,
301uint64_t ParentAddr,
302uint16_t Modi,
303uint32_t RecordOffset) const{
304auto Iter = SymTabOffsetToSymbolId.find({Modi, RecordOffset});
305if (Iter != SymTabOffsetToSymbolId.end())
306return Iter->second;
307
308SymIndexId Id = createSymbol<NativeInlineSiteSymbol>(Sym, ParentAddr);
309 SymTabOffsetToSymbolId.insert({{Modi, RecordOffset}, Id});
310return Id;
311}
312
313std::unique_ptr<PDBSymbol>
314SymbolCache::findSymbolBySectOffset(uint32_t Sect,uint32_tOffset,
315PDB_SymTypeType) {
316switch (Type) {
317casePDB_SymType::Function:
318return findFunctionSymbolBySectOffset(Sect,Offset);
319casePDB_SymType::PublicSymbol:
320return findPublicSymbolBySectOffset(Sect,Offset);
321casePDB_SymType::Compiland: {
322uint16_t Modi;
323if (!Session.moduleIndexForSectOffset(Sect,Offset, Modi))
324returnnullptr;
325returngetOrCreateCompiland(Modi);
326 }
327casePDB_SymType::None: {
328// FIXME: Implement for PDB_SymType::Data. The symbolizer calls this but
329// only uses it to find the symbol length.
330if (autoSym = findFunctionSymbolBySectOffset(Sect,Offset))
331returnSym;
332returnnullptr;
333 }
334default:
335returnnullptr;
336 }
337}
338
339std::unique_ptr<PDBSymbol>
340SymbolCache::findFunctionSymbolBySectOffset(uint32_t Sect,uint32_tOffset) {
341auto Iter = AddressToSymbolId.find({Sect,Offset});
342if (Iter != AddressToSymbolId.end())
343returngetSymbolById(Iter->second);
344
345if (!Dbi)
346returnnullptr;
347
348uint16_t Modi;
349if (!Session.moduleIndexForSectOffset(Sect,Offset, Modi))
350returnnullptr;
351
352Expected<ModuleDebugStreamRef> ExpectedModS =
353 Session.getModuleDebugStream(Modi);
354if (!ExpectedModS) {
355consumeError(ExpectedModS.takeError());
356returnnullptr;
357 }
358CVSymbolArray Syms = ExpectedModS->getSymbolArray();
359
360// Search for the symbol in this module.
361for (autoI = Syms.begin(), E = Syms.end();I != E; ++I) {
362if (I->kind() != S_LPROC32 &&I->kind() != S_GPROC32)
363continue;
364auto PS =cantFail(SymbolDeserializer::deserializeAs<ProcSym>(*I));
365if (Sect == PS.Segment &&Offset >= PS.CodeOffset &&
366Offset < PS.CodeOffset + PS.CodeSize) {
367// Check if the symbol is already cached.
368auto Found = AddressToSymbolId.find({PS.Segment, PS.CodeOffset});
369if (Found != AddressToSymbolId.end())
370returngetSymbolById(Found->second);
371
372// Otherwise, create a new symbol.
373SymIndexIdId = createSymbol<NativeFunctionSymbol>(PS,I.offset());
374 AddressToSymbolId.insert({{PS.Segment, PS.CodeOffset},Id});
375returngetSymbolById(Id);
376 }
377
378// Jump to the end of this ProcSym.
379I = Syms.at(PS.End);
380 }
381returnnullptr;
382}
383
384std::unique_ptr<PDBSymbol>
385SymbolCache::findPublicSymbolBySectOffset(uint32_t Sect,uint32_tOffset) {
386auto Iter = AddressToPublicSymId.find({Sect,Offset});
387if (Iter != AddressToPublicSymId.end())
388returngetSymbolById(Iter->second);
389
390autoPublics = Session.getPDBFile().getPDBPublicsStream();
391if (!Publics) {
392consumeError(Publics.takeError());
393returnnullptr;
394 }
395
396auto ExpectedSyms = Session.getPDBFile().getPDBSymbolStream();
397if (!ExpectedSyms) {
398consumeError(ExpectedSyms.takeError());
399returnnullptr;
400 }
401BinaryStreamRef SymStream =
402 ExpectedSyms->getSymbolArray().getUnderlyingStream();
403
404// Use binary search to find the first public symbol with an address greater
405// than or equal to Sect, Offset.
406auto AddrMap =Publics->getAddressMap();
407autoFirst = AddrMap.begin();
408auto It = AddrMap.begin();
409size_t Count = AddrMap.size();
410size_t Half;
411while (Count > 0) {
412 It =First;
413 Half = Count / 2;
414 It += Half;
415Expected<CVSymbol>Sym =readSymbolFromStream(SymStream, *It);
416if (!Sym) {
417consumeError(Sym.takeError());
418returnnullptr;
419 }
420
421auto PS =
422cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(Sym.get()));
423if (PS.Segment < Sect || (PS.Segment == Sect && PS.Offset <=Offset)) {
424First = ++It;
425 Count -= Half + 1;
426 }else
427 Count = Half;
428 }
429if (It == AddrMap.begin())
430returnnullptr;
431 --It;
432
433Expected<CVSymbol>Sym =readSymbolFromStream(SymStream, *It);
434if (!Sym) {
435consumeError(Sym.takeError());
436returnnullptr;
437 }
438
439// Check if the symbol is already cached.
440auto PS =cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(Sym.get()));
441auto Found = AddressToPublicSymId.find({PS.Segment, PS.Offset});
442if (Found != AddressToPublicSymId.end())
443returngetSymbolById(Found->second);
444
445// Otherwise, create a new symbol.
446SymIndexIdId = createSymbol<NativePublicSymbol>(PS);
447 AddressToPublicSymId.insert({{PS.Segment, PS.Offset},Id});
448returngetSymbolById(Id);
449}
450
451std::vector<SymbolCache::LineTableEntry>
452SymbolCache::findLineTable(uint16_t Modi) const{
453// Check if this module has already been added.
454auto [LineTableIter,Inserted] = LineTable.try_emplace(Modi);
455if (!Inserted)
456return LineTableIter->second;
457
458 std::vector<LineTableEntry> &ModuleLineTable = LineTableIter->second;
459
460// If there is an error or there are no lines, just return the
461// empty vector.
462Expected<ModuleDebugStreamRef> ExpectedModS =
463 Session.getModuleDebugStream(Modi);
464if (!ExpectedModS) {
465consumeError(ExpectedModS.takeError());
466return ModuleLineTable;
467 }
468
469 std::vector<std::vector<LineTableEntry>> EntryList;
470for (constauto &SS : ExpectedModS->getSubsectionsArray()) {
471if (SS.kind() != DebugSubsectionKind::Lines)
472continue;
473
474DebugLinesSubsectionRefLines;
475BinaryStreamReader Reader(SS.getRecordData());
476if (autoEC =Lines.initialize(Reader)) {
477consumeError(std::move(EC));
478continue;
479 }
480
481uint32_t RelocSegment =Lines.header()->RelocSegment;
482uint32_t RelocOffset =Lines.header()->RelocOffset;
483for (constLineColumnEntry &Group :Lines) {
484if (Group.LineNumbers.empty())
485continue;
486
487 std::vector<LineTableEntry> Entries;
488
489// If there are column numbers, then they should be in a parallel stream
490// to the line numbers.
491auto ColIt = Group.Columns.begin();
492auto ColsEnd = Group.Columns.end();
493
494// Add a line to mark the beginning of this section.
495uint64_t StartAddr =
496 Session.getVAFromSectOffset(RelocSegment, RelocOffset);
497LineInfo FirstLine(Group.LineNumbers.front().Flags);
498uint32_t ColNum =
499 (Lines.hasColumnInfo()) ? Group.Columns.front().StartColumn : 0;
500 Entries.push_back({StartAddr, FirstLine, ColNum, Group.NameIndex,false});
501
502for (constLineNumberEntry &LN : Group.LineNumbers) {
503uint64_t VA =
504 Session.getVAFromSectOffset(RelocSegment, RelocOffset + LN.Offset);
505LineInfoLine(LN.Flags);
506 ColNum = 0;
507
508if (Lines.hasColumnInfo() && ColIt != ColsEnd) {
509 ColNum = ColIt->StartColumn;
510 ++ColIt;
511 }
512 Entries.push_back({VA,Line, ColNum, Group.NameIndex,false});
513 }
514
515// Add a terminal entry line to mark the end of this subsection.
516uint64_t EndAddr = StartAddr +Lines.header()->CodeSize;
517LineInfo LastLine(Group.LineNumbers.back().Flags);
518 ColNum = (Lines.hasColumnInfo()) ? Group.Columns.back().StartColumn : 0;
519 Entries.push_back({EndAddr, LastLine, ColNum, Group.NameIndex,true});
520
521 EntryList.push_back(Entries);
522 }
523 }
524
525// Sort EntryList, and add flattened contents to the line table.
526llvm::sort(EntryList, [](const std::vector<LineTableEntry> &LHS,
527const std::vector<LineTableEntry> &RHS) {
528returnLHS[0].Addr <RHS[0].Addr;
529 });
530for (std::vector<LineTableEntry> &I : EntryList)
531llvm::append_range(ModuleLineTable,I);
532
533return ModuleLineTable;
534}
535
536std::unique_ptr<IPDBEnumLineNumbers>
537SymbolCache::findLineNumbersByVA(uint64_t VA,uint32_tLength) const{
538uint16_t Modi;
539if (!Session.moduleIndexForVA(VA, Modi))
540returnnullptr;
541
542 std::vector<LineTableEntry>Lines = findLineTable(Modi);
543if (Lines.empty())
544returnnullptr;
545
546// Find the first line in the line table whose address is not greater than
547// the one we are searching for.
548auto LineIter =llvm::partition_point(Lines, [&](const LineTableEntry &E) {
549return (E.Addr < VA || (E.Addr == VA && E.IsTerminalEntry));
550 });
551
552// Try to back up if we've gone too far.
553if (LineIter ==Lines.end() || LineIter->Addr > VA) {
554if (LineIter ==Lines.begin() || std::prev(LineIter)->IsTerminalEntry)
555returnnullptr;
556 --LineIter;
557 }
558
559Expected<ModuleDebugStreamRef> ExpectedModS =
560 Session.getModuleDebugStream(Modi);
561if (!ExpectedModS) {
562consumeError(ExpectedModS.takeError());
563returnnullptr;
564 }
565Expected<DebugChecksumsSubsectionRef> ExpectedChecksums =
566 ExpectedModS->findChecksumsSubsection();
567if (!ExpectedChecksums) {
568consumeError(ExpectedChecksums.takeError());
569returnnullptr;
570 }
571
572// Populate a vector of NativeLineNumbers that have addresses in the given
573// address range.
574 std::vector<NativeLineNumber>LineNumbers;
575while (LineIter !=Lines.end()) {
576if (LineIter->IsTerminalEntry) {
577 ++LineIter;
578continue;
579 }
580
581// If the line is still within the address range, create a NativeLineNumber
582// and add to the list.
583if (LineIter->Addr > VA +Length)
584break;
585
586uint32_t LineSect, LineOff;
587 Session.addressForVA(LineIter->Addr, LineSect, LineOff);
588uint32_t LineLength = std::next(LineIter)->Addr - LineIter->Addr;
589auto ChecksumIter =
590 ExpectedChecksums->getArray().at(LineIter->FileNameIndex);
591uint32_t SrcFileId =getOrCreateSourceFile(*ChecksumIter);
592NativeLineNumber LineNum(Session, LineIter->Line, LineIter->ColumnNumber,
593 LineSect, LineOff, LineLength, SrcFileId, Modi);
594LineNumbers.push_back(LineNum);
595 ++LineIter;
596 }
597return std::make_unique<NativeEnumLineNumbers>(std::move(LineNumbers));
598}
599
600std::unique_ptr<PDBSymbolCompiland>
601SymbolCache::getOrCreateCompiland(uint32_t Index) {
602if (!Dbi)
603returnnullptr;
604
605if (Index >= Compilands.size())
606returnnullptr;
607
608if (Compilands[Index] == 0) {
609constDbiModuleList &Modules = Dbi->modules();
610 Compilands[Index] =
611 createSymbol<NativeCompilandSymbol>(Modules.getModuleDescriptor(Index));
612 }
613
614return Session.getConcreteSymbolById<PDBSymbolCompiland>(Compilands[Index]);
615}
616
617std::unique_ptr<IPDBSourceFile>
618SymbolCache::getSourceFileById(SymIndexId FileId) const{
619assert(FileId < SourceFiles.size());
620
621// Id 0 is reserved.
622if (FileId == 0)
623returnnullptr;
624
625return std::make_unique<NativeSourceFile>(*SourceFiles[FileId].get());
626}
627
628SymIndexId
629SymbolCache::getOrCreateSourceFile(constFileChecksumEntry &Checksums) const{
630auto Iter = FileNameOffsetToId.find(Checksums.FileNameOffset);
631if (Iter != FileNameOffsetToId.end())
632return Iter->second;
633
634SymIndexId Id = SourceFiles.size();
635auto SrcFile = std::make_unique<NativeSourceFile>(Session, Id, Checksums);
636 SourceFiles.push_back(std::move(SrcFile));
637 FileNameOffsetToId[Checksums.FileNameOffset] = Id;
638return Id;
639}
640
641
DbiModuleList.h
DbiStream.h
DebugChecksumsSubsection.h
DebugLinesSubsection.h
DebugSubsectionRecord.h
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
IPDBSourceFile.h
LazyRandomTypeCollection.h
I
#define I(x, y, z)
Definition:MD5.cpp:58
ModuleDebugStream.h
NativeCompilandSymbol.h
NativeEnumGlobals.h
NativeEnumLineNumbers.h
NativeEnumTypes.h
NativeFunctionSymbol.h
NativeInlineSiteSymbol.h
NativeLineNumber.h
NativePublicSymbol.h
NativeRawSymbol.h
NativeSession.h
NativeTypeArray.h
NativeTypeBuiltin.h
NativeTypeEnum.h
NativeTypeFunctionSig.h
NativeTypePointer.h
NativeTypeTypedef.h
NativeTypeUDT.h
NativeTypeVTShape.h
PDBFile.h
PDBSymbolCompiland.h
PDBSymbol.h
PublicsStream.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BuiltinTypes
static const struct BuiltinTypeEntry BuiltinTypes[]
SymbolCache.h
SymbolDeserializer.h
SymbolRecord.h
SymbolStream.h
TpiStream.h
TypeDeserializer.h
TypeRecordHelpers.h
TypeRecord.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition:BinaryStreamReader.h:29
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition:BinaryStreamRef.h:154
llvm::DenseMapBase::try_emplace
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition:DenseMap.h:226
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::Record
Definition:Record.h:1596
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::VarStreamArray< CVSymbol >
llvm::VarStreamArray::at
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
Definition:BinaryStreamArray.h:134
llvm::VarStreamArray::end
Iterator end() const
Definition:BinaryStreamArray.h:117
llvm::VarStreamArray::begin
Iterator begin(bool *HadError=nullptr) const
Definition:BinaryStreamArray.h:108
llvm::codeview::CVRecord< TypeLeafKind >
llvm::codeview::CVRecord::kind
Kind kind() const
Definition:CVRecord.h:42
llvm::codeview::DebugLinesSubsectionRef
Definition:DebugLinesSubsection.h:79
llvm::codeview::InlineSiteSym
Definition:SymbolRecord.h:353
llvm::codeview::LazyRandomTypeCollection
Provides amortized O(1) random access to a CodeView type stream.
Definition:LazyRandomTypeCollection.h:48
llvm::codeview::LineInfo
Definition:Line.h:20
llvm::codeview::Line
Definition:Line.h:90
llvm::codeview::ModifierRecord
Definition:TypeRecord.h:130
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition:TypeIndex.h:96
llvm::codeview::UDTSym
Definition:SymbolRecord.h:884
llvm::pdb::DbiModuleList
Definition:DbiModuleList.h:67
llvm::pdb::DbiModuleList::getModuleDescriptor
DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const
Definition:DbiModuleList.cpp:255
llvm::pdb::DbiModuleList::getModuleCount
uint32_t getModuleCount() const
Definition:DbiModuleList.cpp:241
llvm::pdb::DbiStream
Definition:DbiStream.h:39
llvm::pdb::DbiStream::modules
const DbiModuleList & modules() const
Definition:DbiStream.cpp:215
llvm::pdb::IPDBSession::getConcreteSymbolById
std::unique_ptr< T > getConcreteSymbolById(SymIndexId SymbolId) const
Definition:IPDBSession.h:41
llvm::pdb::NativeEnumGlobals
Definition:NativeEnumGlobals.h:23
llvm::pdb::NativeEnumTypes
Definition:NativeEnumTypes.h:27
llvm::pdb::NativeLineNumber
Definition:NativeLineNumber.h:20
llvm::pdb::NativeRawSymbol
Definition:NativeRawSymbol.h:21
llvm::pdb::NativeRawSymbol::getSymTag
PDB_SymType getSymTag() const override
Definition:NativeRawSymbol.cpp:363
llvm::pdb::NativeSession
Definition:NativeSession.h:32
llvm::pdb::NativeSession::addressForVA
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
Definition:NativeSession.cpp:219
llvm::pdb::NativeSession::moduleIndexForSectOffset
bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, uint16_t &ModuleIndex) const
Definition:NativeSession.cpp:410
llvm::pdb::NativeSession::getVAFromSectOffset
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition:NativeSession.cpp:396
llvm::pdb::NativeSession::getPDBFile
PDBFile & getPDBFile()
Definition:NativeSession.h:109
llvm::pdb::NativeSession::getModuleDebugStream
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition:NativeSession.cpp:452
llvm::pdb::NativeSession::moduleIndexForVA
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition:NativeSession.cpp:401
llvm::pdb::NativeTypeEnum
Definition:NativeTypeEnum.h:24
llvm::pdb::NativeTypeUDT
Definition:NativeTypeUDT.h:24
llvm::pdb::PDBFile::getPDBPublicsStream
Expected< PublicsStream & > getPDBPublicsStream()
Definition:PDBFile.cpp:329
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition:PDBFile.cpp:300
llvm::pdb::PDBFile::getPDBSymbolStream
Expected< SymbolStream & > getPDBSymbolStream()
Definition:PDBFile.cpp:347
llvm::pdb::PDBSymbolCompiland
Definition:PDBSymbolCompiland.h:21
llvm::pdb::PDBSymbol::create
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition:PDBSymbol.cpp:102
llvm::pdb::SymbolCache::createGlobalsEnumerator
std::unique_ptr< IPDBEnumSymbols > createGlobalsEnumerator(codeview::SymbolKind Kind)
Definition:SymbolCache.cpp:106
llvm::pdb::SymbolCache::getOrCreateInlineSymbol
SymIndexId getOrCreateInlineSymbol(codeview::InlineSiteSym Sym, uint64_t ParentAddr, uint16_t Modi, uint32_t RecordOffset) const
Definition:SymbolCache.cpp:300
llvm::pdb::SymbolCache::createTypeEnumerator
std::unique_ptr< IPDBEnumSymbols > createTypeEnumerator(codeview::TypeLeafKind Kind)
Definition:SymbolCache.cpp:89
llvm::pdb::SymbolCache::getSymbolById
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
Definition:SymbolCache.cpp:247
llvm::pdb::SymbolCache::SymbolCache
SymbolCache(NativeSession &Session, DbiStream *Dbi)
Definition:SymbolCache.cpp:78
llvm::pdb::SymbolCache::getOrCreateSourceFile
SymIndexId getOrCreateSourceFile(const codeview::FileChecksumEntry &Checksum) const
Definition:SymbolCache.cpp:629
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition:SymbolCache.cpp:158
llvm::pdb::SymbolCache::getNativeSymbolById
NativeRawSymbol & getNativeSymbolById(SymIndexId SymbolId) const
Definition:SymbolCache.cpp:263
llvm::pdb::SymbolCache::getOrCreateCompiland
std::unique_ptr< PDBSymbolCompiland > getOrCreateCompiland(uint32_t Index)
Definition:SymbolCache.cpp:601
llvm::pdb::SymbolCache::getNumCompilands
uint32_t getNumCompilands() const
Definition:SymbolCache.cpp:267
llvm::pdb::SymbolCache::getSourceFileById
std::unique_ptr< IPDBSourceFile > getSourceFileById(SymIndexId FileId) const
Definition:SymbolCache.cpp:618
llvm::pdb::SymbolCache::findLineNumbersByVA
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByVA(uint64_t VA, uint32_t Length) const
Definition:SymbolCache.cpp:537
llvm::pdb::SymbolCache::findSymbolBySectOffset
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type)
Definition:SymbolCache.cpp:314
llvm::pdb::SymbolCache::getOrCreateGlobalSymbolByOffset
SymIndexId getOrCreateGlobalSymbolByOffset(uint32_t Offset)
Definition:SymbolCache.cpp:274
llvm::pdb::SymbolStream
Definition:SymbolStream.h:22
uint16_t
uint32_t
uint64_t
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition:SIDefines.h:310
llvm::X86AS::SS
@ SS
Definition:X86.h:212
llvm::codeview
Definition:AppendingTypeTableBuilder.h:22
llvm::codeview::DebugSubsectionKind::Lines
@ Lines
llvm::codeview::isUdtForwardRef
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
Definition:TypeRecordHelpers.cpp:27
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::codeview::TypeLeafKind
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition:CodeView.h:34
llvm::codeview::SimpleTypeMode::Direct
@ Direct
llvm::codeview::SimpleTypeKind
SimpleTypeKind
Definition:TypeIndex.h:26
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition:CodeView.h:48
llvm::codeview::ModifierOptions
ModifierOptions
Equivalent to CV_modifier_t.
Definition:CodeView.h:311
llvm::codeview::readSymbolFromStream
Expected< CVSymbol > readSymbolFromStream(BinaryStreamRef Stream, uint32_t Offset)
Definition:RecordSerialization.cpp:151
llvm::logicalview::LVAttributeKind::Inserted
@ Inserted
llvm::logicalview::LVAttributeKind::Publics
@ Publics
llvm::pdb
Definition:LVCodeViewReader.h:44
llvm::pdb::SymIndexId
uint32_t SymIndexId
Definition:PDBTypes.h:26
llvm::pdb::PDB_TableType::LineNumbers
@ LineNumbers
llvm::pdb::PDB_BuiltinType
PDB_BuiltinType
These values correspond to the Basictype enumeration, and are documented here: https://msdn....
Definition:PDBTypes.h:335
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition:PDBTypes.h:243
llvm::pdb::PDB_SymType::PublicSymbol
@ PublicSymbol
llvm::pdb::PDB_SymType::Compiland
@ Compiland
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::PDB_SymType::None
@ None
llvm::pdb::PDB_SymType::Function
@ Function
llvm::pdb::PDB_SymType::Enum
@ Enum
llvm::pdb::PDB_ColorItem::Offset
@ Offset
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Length
@ Length
Definition:DWP.cpp:480
llvm::partition_point
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition:STLExtras.h:2050
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition:STLExtras.h:2115
llvm::get
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition:PointerIntPair.h:270
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::IRMemLocation::First
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1766
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
BuiltinTypeEntry
Definition:SymbolCache.cpp:47
BuiltinTypeEntry::Kind
codeview::SimpleTypeKind Kind
Definition:SymbolCache.cpp:48
BuiltinTypeEntry::Size
uint32_t Size
Definition:SymbolCache.cpp:50
BuiltinTypeEntry::Type
PDB_BuiltinType Type
Definition:SymbolCache.cpp:49
llvm::codeview::FileChecksumEntry
Definition:DebugChecksumsSubsection.h:33
llvm::codeview::FileChecksumEntry::FileNameOffset
uint32_t FileNameOffset
Definition:DebugChecksumsSubsection.h:34
llvm::codeview::LineColumnEntry
Definition:DebugLinesSubsection.h:65
llvm::codeview::LineNumberEntry
Definition:DebugLinesSubsection.h:54
llvm::codeview::LineNumberEntry::Offset
support::ulittle32_t Offset
Definition:DebugLinesSubsection.h:55
llvm::codeview::LineNumberEntry::Flags
support::ulittle32_t Flags
Definition:DebugLinesSubsection.h:56

Generated on Fri Jul 18 2025 11:17:06 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp