LLVM 23.0.0git
LVCodeViewVisitor.cpp
Go to the documentation of this file.
1//===-- LVCodeViewVisitor.cpp ---------------------------------------------===//
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// This implements the LVCodeViewVisitor class.
10//
11//===----------------------------------------------------------------------===//
12
29#include "llvm/Object/COFF.h"
30#include "llvm/Support/Error.h"
33
34using namespace llvm;
35using namespace llvm::codeview;
36using namespace llvm::object;
37using namespace llvm::pdb;
38using namespace llvm::logicalview;
39
40#define DEBUG_TYPE "CodeViewUtilities"
41
42namespace llvm {
43namespace logicalview {
44
46 // Dealing with a MSVC generated PDB, we encountered a type index with the
47 // value of: 0x0280xxxx where xxxx=0000.
48 //
49 // There is some documentation about type indices:
50 // https://llvm.org/docs/PDB/TpiStream.html
51 //
52 // A type index is a 32-bit integer that uniquely identifies a type inside
53 // of an object file’s .debug$T section or a PDB file’s TPI or IPI stream.
54 // The value of the type index for the first type record from the TPI stream
55 // is given by the TypeIndexBegin member of the TPI Stream Header although
56 // in practice this value is always equal to 0x1000 (4096).
57 //
58 // Any type index with a high bit set is considered to come from the IPI
59 // stream, although this appears to be more of a hack, and LLVM does not
60 // generate type indices of this nature. They can, however, be observed in
61 // Microsoft PDBs occasionally, so one should be prepared to handle them.
62 // Note that having the high bit set is not a necessary condition to
63 // determine whether a type index comes from the IPI stream, it is only
64 // sufficient.
66 { dbgs() << "Index before: " << HexNumber(TI.getIndex()) << "\n"; });
67 TI.setIndex(TI.getIndex() & 0x0000ffff);
69 { dbgs() << "Index after: " << HexNumber(TI.getIndex()) << "\n"; });
70 return TI;
71}
72
74#define CV_TYPE(enum, val) {#enum, enum},
75#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
76};
77
78// Return the type name pointed by the type index. It uses the kind to query
79// the associated name for the record type.
81 if (TI.isSimple())
82 return {};
83
84 StringRef RecordName;
85 CVType CVReference = Types.getType(TI);
86 auto GetName = [&](auto Record) {
88 const_cast<CVType &>(CVReference), Record))
89 consumeError(std::move(Err));
90 else
91 RecordName = Record.getName();
92 };
93
94 TypeRecordKind RK = static_cast<TypeRecordKind>(CVReference.kind());
95 if (RK == TypeRecordKind::Class || RK == TypeRecordKind::Struct)
96 GetName(ClassRecord(RK));
97 else if (RK == TypeRecordKind::Union)
98 GetName(UnionRecord(RK));
99 else if (RK == TypeRecordKind::Enum)
100 GetName(EnumRecord(RK));
101
102 return RecordName;
103}
104
105} // namespace logicalview
106} // namespace llvm
107
108#undef DEBUG_TYPE
109#define DEBUG_TYPE "CodeViewDataVisitor"
110
111namespace llvm {
112namespace logicalview {
113
114// Keeps the type indexes with line information.
115using LVLineRecords = std::vector<TypeIndex>;
116
117namespace {
118
119class LVTypeRecords {
120 LVShared *Shared = nullptr;
121
122 // Logical elements associated to their CodeView Type Index.
123 using RecordEntry = std::pair<TypeLeafKind, LVElement *>;
124 using RecordTable = std::map<TypeIndex, RecordEntry>;
125 RecordTable RecordFromTypes;
126 RecordTable RecordFromIds;
127
128 using NameTable = std::map<StringRef, TypeIndex>;
129 NameTable NameFromTypes;
130 NameTable NameFromIds;
131
132public:
133 LVTypeRecords(LVShared *Shared) : Shared(Shared) {}
134
135 void add(uint32_t StreamIdx, TypeIndex TI, TypeLeafKind Kind,
136 LVElement *Element = nullptr);
137 void add(uint32_t StreamIdx, TypeIndex TI, StringRef Name);
138 LVElement *find(uint32_t StreamIdx, TypeIndex TI, bool Create = true);
140};
141
142class LVForwardReferences {
143 // Forward reference and its definitions (Name as key).
144 using ForwardEntry = std::pair<TypeIndex, TypeIndex>;
145 using ForwardTypeNames = std::map<StringRef, ForwardEntry>;
146 ForwardTypeNames ForwardTypesNames;
147
148 // Forward reference and its definition (TypeIndex as key).
149 using ForwardType = std::map<TypeIndex, TypeIndex>;
150 ForwardType ForwardTypes;
151
152 // Forward types and its references.
153 void add(TypeIndex TIForward, TypeIndex TIReference) {
154 ForwardTypes.emplace(TIForward, TIReference);
155 }
156
157 void add(StringRef Name, TypeIndex TIForward) {
158 auto [It, Inserted] =
159 ForwardTypesNames.try_emplace(Name, TIForward, TypeIndex::None());
160 if (!Inserted) {
161 // Update a recorded definition with its reference.
162 It->second.first = TIForward;
163 add(TIForward, It->second.second);
164 }
165 }
166
167 // Update a previously recorded forward reference with its definition.
168 void update(StringRef Name, TypeIndex TIReference) {
169 auto [It, Inserted] =
170 ForwardTypesNames.try_emplace(Name, TypeIndex::None(), TIReference);
171 if (!Inserted) {
172 // Update the recorded forward reference with its definition.
173 It->second.second = TIReference;
174 add(It->second.first, TIReference);
175 }
176 }
177
178public:
179 LVForwardReferences() = default;
180
181 void record(bool IsForwardRef, StringRef Name, TypeIndex TI) {
182 // We are expecting for the forward references to be first. But that
183 // is not always the case. A name must be recorded regardless of the
184 // order in which the forward reference appears.
185 (IsForwardRef) ? add(Name, TI) : update(Name, TI);
186 }
187
188 TypeIndex find(TypeIndex TIForward) {
189 auto It = ForwardTypes.find(TIForward);
190 return It != ForwardTypes.end() ? It->second : TypeIndex::None();
191 }
192
194 auto It = ForwardTypesNames.find(Name);
195 return It != ForwardTypesNames.end() ? It->second.second
196 : TypeIndex::None();
197 }
198
199 // If the given TI corresponds to a reference, return the reference.
200 // Otherwise return the given TI.
201 TypeIndex remap(TypeIndex TI) {
202 TypeIndex Forward = find(TI);
203 return Forward.isNoneType() ? TI : Forward;
204 }
205};
206
207// Namespace deduction.
208class LVNamespaceDeduction {
209 LVShared *Shared = nullptr;
210
211 using Names = std::map<StringRef, LVScope *>;
212 Names NamespaceNames;
213
214 using LookupSet = std::set<StringRef>;
215 LookupSet DeducedScopes;
216 LookupSet UnresolvedScopes;
217 LookupSet IdentifiedNamespaces;
218
219 void add(StringRef Name, LVScope *Namespace) {
220 if (NamespaceNames.find(Name) == NamespaceNames.end())
221 NamespaceNames.emplace(Name, Namespace);
222 }
223
224public:
225 LVNamespaceDeduction(LVShared *Shared) : Shared(Shared) {}
226
227 void init();
228 void add(StringRef String);
229 LVScope *get(LVStringRefs Components);
230 LVScope *get(StringRef Name, bool CheckScope = true);
231
232 // Find the logical namespace for the 'Name' component.
234 auto It = NamespaceNames.find(Name);
235 LVScope *Namespace = It != NamespaceNames.end() ? It->second : nullptr;
236 return Namespace;
237 }
238
239 // For the given lexical components, return a tuple with the first entry
240 // being the outermost namespace and the second entry being the first
241 // non-namespace.
242 LVLexicalIndex find(LVStringRefs Components) {
243 if (Components.empty())
244 return {};
245
246 LVStringRefs::size_type FirstNamespace = 0;
247 LVStringRefs::size_type FirstNonNamespace;
248 for (LVStringRefs::size_type Index = 0; Index < Components.size();
249 ++Index) {
250 FirstNonNamespace = Index;
251 LookupSet::iterator Iter = IdentifiedNamespaces.find(Components[Index]);
252 if (Iter == IdentifiedNamespaces.end())
253 // The component is not a namespace name.
254 break;
255 }
256 return std::make_tuple(FirstNamespace, FirstNonNamespace);
257 }
258};
259
260// Strings.
261class LVStringRecords {
262 using StringEntry = std::tuple<uint32_t, std::string, LVScopeCompileUnit *>;
263 using StringIds = std::map<TypeIndex, StringEntry>;
264 StringIds Strings;
265
266public:
267 LVStringRecords() = default;
268
269 void add(TypeIndex TI, StringRef String) {
270 static uint32_t Index = 0;
271 auto [It, Inserted] = Strings.try_emplace(TI);
272 if (Inserted)
273 It->second = std::make_tuple(++Index, std::string(String), nullptr);
274 }
275
277 StringIds::iterator Iter = Strings.find(TI);
278 return Iter != Strings.end() ? std::get<1>(Iter->second) : StringRef{};
279 }
280
281 uint32_t findIndex(TypeIndex TI) {
282 StringIds::iterator Iter = Strings.find(TI);
283 return Iter != Strings.end() ? std::get<0>(Iter->second) : 0;
284 }
285
286 // Move strings representing the filenames to the compile unit.
287 void addFilenames();
288 void addFilenames(LVScopeCompileUnit *Scope);
289};
290} // namespace
291
292using LVTypeKinds = std::set<TypeLeafKind>;
293using LVSymbolKinds = std::set<SymbolKind>;
294
295// The following data keeps forward information, type records, names for
296// namespace deduction, strings records, line records.
297// It is shared by the type visitor, symbol visitor and logical visitor and
298// it is independent from the CodeViewReader.
299struct LVShared {
302 LVForwardReferences ForwardReferences;
304 LVNamespaceDeduction NamespaceDeduction;
305 LVStringRecords StringRecords;
306 LVTypeRecords TypeRecords;
307
308 // In order to determine which types and/or symbols records should be handled
309 // by the reader, we record record kinds seen by the type and symbol visitors.
310 // At the end of the scopes creation, the '--internal=tag' option will allow
311 // to print the unique record ids collected.
314
318 ~LVShared() = default;
319};
320} // namespace logicalview
321} // namespace llvm
322
323void LVTypeRecords::add(uint32_t StreamIdx, TypeIndex TI, TypeLeafKind Kind,
324 LVElement *Element) {
325 RecordTable &Target =
326 (StreamIdx == StreamTPI) ? RecordFromTypes : RecordFromIds;
327 Target.emplace(std::piecewise_construct, std::forward_as_tuple(TI),
328 std::forward_as_tuple(Kind, Element));
329}
330
331void LVTypeRecords::add(uint32_t StreamIdx, TypeIndex TI, StringRef Name) {
332 NameTable &Target = (StreamIdx == StreamTPI) ? NameFromTypes : NameFromIds;
333 Target.emplace(Name, TI);
334}
335
336LVElement *LVTypeRecords::find(uint32_t StreamIdx, TypeIndex TI, bool Create) {
337 RecordTable &Target =
338 (StreamIdx == StreamTPI) ? RecordFromTypes : RecordFromIds;
339
340 LVElement *Element = nullptr;
341 RecordTable::iterator Iter = Target.find(TI);
342 if (Iter != Target.end()) {
343 Element = Iter->second.second;
344 if (Element || !Create)
345 return Element;
346
347 // Create the logical element if not found.
348 Element = Shared->Visitor->createElement(Iter->second.first);
349 if (Element) {
350 Element->setOffset(TI.getIndex());
351 Element->setOffsetFromTypeIndex();
352 Target[TI].second = Element;
353 }
354 }
355 return Element;
356}
357
358TypeIndex LVTypeRecords::find(uint32_t StreamIdx, StringRef Name) {
359 NameTable &Target = (StreamIdx == StreamTPI) ? NameFromTypes : NameFromIds;
360 NameTable::iterator Iter = Target.find(Name);
361 return Iter != Target.end() ? Iter->second : TypeIndex::None();
362}
363
364void LVStringRecords::addFilenames() {
365 for (StringIds::const_reference Entry : Strings) {
366 StringRef Name = std::get<1>(Entry.second);
367 LVScopeCompileUnit *Scope = std::get<2>(Entry.second);
368 Scope->addFilename(transformPath(Name));
369 }
370 Strings.clear();
371}
372
373void LVStringRecords::addFilenames(LVScopeCompileUnit *Scope) {
374 for (StringIds::reference Entry : Strings)
375 if (!std::get<2>(Entry.second))
376 std::get<2>(Entry.second) = Scope;
377}
378
379void LVNamespaceDeduction::add(StringRef String) {
380 StringRef InnerComponent;
381 StringRef OuterComponent;
382 std::tie(OuterComponent, InnerComponent) = getInnerComponent(String);
383 DeducedScopes.insert(InnerComponent);
384 if (OuterComponent.size())
385 UnresolvedScopes.insert(OuterComponent);
386}
387
388void LVNamespaceDeduction::init() {
389 // We have 2 sets of names:
390 // - deduced scopes (class, structure, union and enum) and
391 // - unresolved scopes, that can represent namespaces or any deduced.
392 // Before creating the namespaces, we have to traverse the unresolved
393 // and remove any references to already deduced scopes.
394 LVStringRefs Components;
395 for (const StringRef &Unresolved : UnresolvedScopes) {
396 Components = getAllLexicalComponents(Unresolved);
397 for (const StringRef &Component : Components) {
398 LookupSet::iterator Iter = DeducedScopes.find(Component);
399 if (Iter == DeducedScopes.end())
400 IdentifiedNamespaces.insert(Component);
401 }
402 }
403
404 LLVM_DEBUG({
405 auto Print = [&](LookupSet &Container, const char *Title) {
406 auto Header = [&]() {
407 dbgs() << formatv("\n{0}\n", fmt_repeat('=', 72));
408 dbgs() << formatv("{0}\n", Title);
409 dbgs() << formatv("{0}\n", fmt_repeat('=', 72));
410 };
411 Header();
412 for (const StringRef &Item : Container)
413 dbgs() << formatv("'{0}'\n", Item);
414 };
415
416 Print(DeducedScopes, "Deducted Scopes");
417 Print(UnresolvedScopes, "Unresolved Scopes");
418 Print(IdentifiedNamespaces, "Namespaces");
419 });
420}
421
422LVScope *LVNamespaceDeduction::get(LVStringRefs Components) {
423 LLVM_DEBUG({
424 for (const StringRef &Component : Components)
425 dbgs() << formatv("'{0}'\n", Component);
426 });
427
428 if (Components.empty())
429 return nullptr;
430
431 // Update the namespaces relationship.
432 LVScope *Namespace = nullptr;
433 LVScope *Parent = Shared->Reader->getCompileUnit();
434 for (const StringRef &Component : Components) {
435 // Check if we have seen the namespace.
436 Namespace = find(Component);
437 if (!Namespace) {
438 // We have identified namespaces that are generated by MSVC. Mark them
439 // as 'system' so they will be excluded from the logical view.
440 Namespace = Shared->Reader->createScopeNamespace();
441 Namespace->setTag(dwarf::DW_TAG_namespace);
442 Namespace->setName(Component);
443 Parent->addElement(Namespace);
444 getReader().isSystemEntry(Namespace);
445 add(Component, Namespace);
446 }
447 Parent = Namespace;
448 }
449 return Parent;
450}
451
452LVScope *LVNamespaceDeduction::get(StringRef ScopedName, bool CheckScope) {
453 LVStringRefs Components = getAllLexicalComponents(ScopedName);
454 if (CheckScope)
455 llvm::erase_if(Components, [&](StringRef Component) {
456 LookupSet::iterator Iter = IdentifiedNamespaces.find(Component);
457 return Iter == IdentifiedNamespaces.end();
458 });
459
460 LLVM_DEBUG({ dbgs() << formatv("ScopedName: '{0}'\n", ScopedName); });
461
462 return get(Components);
463}
464
465#undef DEBUG_TYPE
466#define DEBUG_TYPE "CodeViewTypeVisitor"
467
468//===----------------------------------------------------------------------===//
469// TypeRecord traversal.
470//===----------------------------------------------------------------------===//
471void LVTypeVisitor::printTypeIndex(StringRef FieldName, TypeIndex TI,
472 uint32_t StreamIdx) const {
473 codeview::printTypeIndex(W, FieldName, TI,
474 StreamIdx == StreamTPI ? Types : Ids);
475}
476
480
482 LLVM_DEBUG({
483 W.getOStream() << formatTypeLeafKind(Record.kind());
484 W.getOStream() << " (" << HexNumber(TI.getIndex()) << ")\n";
485 });
486
487 if (options().getInternalTag())
488 Shared->TypeKinds.insert(Record.kind());
489
490 // The collected type records, will be use to create the logical elements
491 // during the symbols traversal when a type is referenced.
492 CurrentTypeIndex = TI;
493 Shared->TypeRecords.add(StreamIdx, TI, Record.kind());
494 return Error::success();
495}
496
498 LLVM_DEBUG({ W.printNumber("Length", uint32_t(Record.content().size())); });
499 return Error::success();
500}
501
503 LLVM_DEBUG({
504 W.startLine() << formatTypeLeafKind(Record.Kind);
505 W.getOStream() << " {\n";
506 W.indent();
507 });
508 return Error::success();
509}
510
512 LLVM_DEBUG({
513 W.unindent();
514 W.startLine() << "}\n";
515 });
516 return Error::success();
517}
518
520 LLVM_DEBUG({ W.printHex("UnknownMember", unsigned(Record.Kind)); });
521 return Error::success();
522}
523
524// LF_BUILDINFO (TPI)/(IPI)
526 // All the args are references into the TPI/IPI stream.
527 LLVM_DEBUG({
528 W.printNumber("NumArgs", static_cast<uint32_t>(Args.getArgs().size()));
529 ListScope Arguments(W, "Arguments");
530 for (TypeIndex Arg : Args.getArgs())
531 printTypeIndex("ArgType", Arg, StreamIPI);
532 });
533
534 // Only add the strings that hold information about filenames. They will be
535 // used to complete the line/file information for the logical elements.
536 // There are other strings holding information about namespaces.
537 TypeIndex TI;
539
540 // Absolute CWD path
542 String = Ids.getTypeName(TI);
543 if (!String.empty())
544 Shared->StringRecords.add(TI, String);
545
546 // Get the compile unit name.
548 String = Ids.getTypeName(TI);
549 if (!String.empty())
550 Shared->StringRecords.add(TI, String);
551 LogicalVisitor->setCompileUnitName(std::string(String));
552
553 return Error::success();
554}
555
556// LF_CLASS, LF_STRUCTURE, LF_INTERFACE (TPI)
558 LLVM_DEBUG({
559 printTypeIndex("TypeIndex", CurrentTypeIndex, StreamTPI);
560 printTypeIndex("FieldListType", Class.getFieldList(), StreamTPI);
561 W.printString("Name", Class.getName());
562 });
563
564 // Collect class name for scope deduction.
565 Shared->NamespaceDeduction.add(Class.getName());
566 Shared->ForwardReferences.record(Class.isForwardRef(), Class.getName(),
567 CurrentTypeIndex);
568
569 // Collect class name for contained scopes deduction.
570 Shared->TypeRecords.add(StreamIdx, CurrentTypeIndex, Class.getName());
571 return Error::success();
572}
573
574// LF_ENUM (TPI)
576 LLVM_DEBUG({
577 printTypeIndex("TypeIndex", CurrentTypeIndex, StreamTPI);
578 printTypeIndex("FieldListType", Enum.getFieldList(), StreamTPI);
579 W.printString("Name", Enum.getName());
580 });
581
582 // Collect enum name for scope deduction.
583 Shared->NamespaceDeduction.add(Enum.getName());
584 return Error::success();
585}
586
587// LF_FUNC_ID (TPI)/(IPI)
589 LLVM_DEBUG({
590 printTypeIndex("TypeIndex", CurrentTypeIndex, StreamTPI);
591 printTypeIndex("Type", Func.getFunctionType(), StreamTPI);
592 printTypeIndex("Parent", Func.getParentScope(), StreamTPI);
593 W.printString("Name", Func.getName());
594 });
595
596 // Collect function name for scope deduction.
597 Shared->NamespaceDeduction.add(Func.getName());
598 return Error::success();
599}
600
601// LF_PROCEDURE (TPI)
603 LLVM_DEBUG({
604 printTypeIndex("TypeIndex", CurrentTypeIndex, StreamTPI);
605 printTypeIndex("ReturnType", Proc.getReturnType(), StreamTPI);
606 W.printNumber("NumParameters", Proc.getParameterCount());
607 printTypeIndex("ArgListType", Proc.getArgumentList(), StreamTPI);
608 });
609
610 // Collect procedure information as they can be referenced by typedefs.
611 Shared->TypeRecords.add(StreamTPI, CurrentTypeIndex, {});
612 return Error::success();
613}
614
615// LF_STRING_ID (TPI)/(IPI)
617 // No additional references are needed.
618 LLVM_DEBUG({
619 printTypeIndex("Id", String.getId(), StreamIPI);
620 W.printString("StringData", String.getString());
621 });
622 return Error::success();
623}
624
625// LF_UDT_SRC_LINE (TPI)/(IPI)
628 // UDT and SourceFile are references into the TPI/IPI stream.
629 LLVM_DEBUG({
630 printTypeIndex("UDT", Line.getUDT(), StreamIPI);
631 printTypeIndex("SourceFile", Line.getSourceFile(), StreamIPI);
632 W.printNumber("LineNumber", Line.getLineNumber());
633 });
634
635 Shared->LineRecords.push_back(CurrentTypeIndex);
636 return Error::success();
637}
638
639// LF_UNION (TPI)
641 LLVM_DEBUG({
642 W.printNumber("MemberCount", Union.getMemberCount());
643 printTypeIndex("FieldList", Union.getFieldList(), StreamTPI);
644 W.printNumber("SizeOf", Union.getSize());
645 W.printString("Name", Union.getName());
646 if (Union.hasUniqueName())
647 W.printString("UniqueName", Union.getUniqueName());
648 });
649
650 // Collect union name for scope deduction.
651 Shared->NamespaceDeduction.add(Union.getName());
652 Shared->ForwardReferences.record(Union.isForwardRef(), Union.getName(),
653 CurrentTypeIndex);
654
655 // Collect class name for contained scopes deduction.
656 Shared->TypeRecords.add(StreamIdx, CurrentTypeIndex, Union.getName());
657 return Error::success();
658}
659
660#undef DEBUG_TYPE
661#define DEBUG_TYPE "CodeViewSymbolVisitor"
662
663//===----------------------------------------------------------------------===//
664// SymbolRecord traversal.
665//===----------------------------------------------------------------------===//
667 uint32_t RelocOffset,
669 StringRef *RelocSym) {
670 Reader->printRelocatedField(Label, CoffSection, RelocOffset, Offset,
671 RelocSym);
672}
673
676 StringRef *RelocSym) {
677 Reader->getLinkageName(CoffSection, RelocOffset, Offset, RelocSym);
678}
679
682 Expected<StringRef> Name = Reader->getFileNameForFileOffset(FileOffset);
683 if (!Name) {
684 consumeError(Name.takeError());
685 return {};
686 }
687 return *Name;
688}
689
693
694void LVSymbolVisitor::printLocalVariableAddrRange(
695 const LocalVariableAddrRange &Range, uint32_t RelocationOffset) {
696 DictScope S(W, "LocalVariableAddrRange");
697 if (ObjDelegate)
698 ObjDelegate->printRelocatedField("OffsetStart", RelocationOffset,
699 Range.OffsetStart);
700 W.printHex("ISectStart", Range.ISectStart);
701 W.printHex("Range", Range.Range);
702}
703
704void LVSymbolVisitor::printLocalVariableAddrGap(
706 for (const LocalVariableAddrGap &Gap : Gaps) {
707 ListScope S(W, "LocalVariableAddrGap");
708 W.printHex("GapStartOffset", Gap.GapStartOffset);
709 W.printHex("Range", Gap.Range);
710 }
711}
712
713void LVSymbolVisitor::printTypeIndex(StringRef FieldName, TypeIndex TI) const {
714 codeview::printTypeIndex(W, FieldName, TI, Types);
715}
716
720
722 SymbolKind Kind = Record.kind();
723 LLVM_DEBUG({
724 W.printNumber("Offset", Offset);
725 W.printEnum("Begin Kind", unsigned(Kind), getSymbolTypeNames());
726 });
727
728 if (options().getInternalTag())
729 Shared->SymbolKinds.insert(Kind);
730
731 LogicalVisitor->CurrentElement = LogicalVisitor->createElement(Kind);
732 if (!LogicalVisitor->CurrentElement) {
733 LLVM_DEBUG({
734 // We have an unsupported Symbol or Type Record.
735 // W.printEnum("Kind ignored", unsigned(Kind), getSymbolTypeNames());
736 });
737 return Error::success();
738 }
739
740 // Offset carried by the traversal routines when dealing with streams.
741 CurrentOffset = Offset;
742 IsCompileUnit = false;
743 if (!LogicalVisitor->CurrentElement->getOffsetFromTypeIndex())
744 LogicalVisitor->CurrentElement->setOffset(Offset);
745 if (symbolOpensScope(Kind) || (IsCompileUnit = symbolIsCompileUnit(Kind))) {
746 assert(LogicalVisitor->CurrentScope && "Invalid scope!");
747 LogicalVisitor->addElement(LogicalVisitor->CurrentScope, IsCompileUnit);
748 } else {
749 if (LogicalVisitor->CurrentSymbol)
750 LogicalVisitor->addElement(LogicalVisitor->CurrentSymbol);
751 if (LogicalVisitor->CurrentType)
752 LogicalVisitor->addElement(LogicalVisitor->CurrentType);
753 }
754
755 return Error::success();
756}
757
759 SymbolKind Kind = Record.kind();
761 { W.printEnum("End Kind", unsigned(Kind), getSymbolTypeNames()); });
762
763 if (symbolEndsScope(Kind)) {
764 LogicalVisitor->popScope();
765 }
766
767 return Error::success();
768}
769
771 LLVM_DEBUG({ W.printNumber("Length", Record.length()); });
772 return Error::success();
773}
774
775// S_BLOCK32
777 LLVM_DEBUG({
778 W.printHex("CodeSize", Block.CodeSize);
779 W.printHex("Segment", Block.Segment);
780 W.printString("BlockName", Block.Name);
781 });
782
783 if (LVScope *Scope = LogicalVisitor->CurrentScope) {
785 if (ObjDelegate)
786 ObjDelegate->getLinkageName(Block.getRelocationOffset(), Block.CodeOffset,
787 &LinkageName);
788 Scope->setLinkageName(LinkageName);
789
790 if (options().getGeneralCollectRanges()) {
791 // Record converted segment::offset addressing for this scope.
792 LVAddress Addendum = Reader->getSymbolTableAddress(LinkageName);
793 LVAddress LowPC =
794 Reader->linearAddress(Block.Segment, Block.CodeOffset, Addendum);
795 LVAddress HighPC = LowPC + Block.CodeSize - 1;
796 Scope->addObject(LowPC, HighPC);
797 }
798 }
799
800 return Error::success();
801}
802
803// S_BPREL32
806 LLVM_DEBUG({
807 printTypeIndex("Type", Local.Type);
808 W.printNumber("Offset", Local.Offset);
809 W.printString("VarName", Local.Name);
810 });
811
812 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
813 Symbol->setName(Local.Name);
814 // From the MS_Symbol_Type.pdf documentation (S_BPREL32):
815 // This symbol specifies symbols that are allocated on the stack for a
816 // procedure. For C and C++, these include the actual function parameters
817 // and the local non-static variables of functions.
818 // However, the offset for 'this' comes as a negative value.
819
820 // Symbol was created as 'variable'; determine its real kind.
821 Symbol->resetIsVariable();
822
823 if (Local.Name == "this") {
824 Symbol->setIsParameter();
825 Symbol->setIsArtificial();
826 } else {
827 // Determine symbol kind.
828 bool(Local.Offset > 0) ? Symbol->setIsParameter()
829 : Symbol->setIsVariable();
830 }
831
832 // Update correct debug information tag.
833 if (Symbol->getIsParameter())
834 Symbol->setTag(dwarf::DW_TAG_formal_parameter);
835
836 setLocalVariableType(Symbol, Local.Type);
837 }
838
839 return Error::success();
840}
841
842// S_REGREL32
845 LLVM_DEBUG({
846 printTypeIndex("Type", Local.Type);
847 W.printNumber("Offset", Local.Offset);
848 W.printString("VarName", Local.Name);
849 });
850
851 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
852 Symbol->setName(Local.Name);
853
854 // Symbol was created as 'variable'; determine its real kind.
855 Symbol->resetIsVariable();
856
857 // Check for the 'this' symbol.
858 if (Local.Name == "this") {
859 Symbol->setIsArtificial();
860 Symbol->setIsParameter();
861 } else {
862 // Determine symbol kind.
863 determineSymbolKind(Symbol, Local.Register);
864 }
865
866 // Update correct debug information tag.
867 if (Symbol->getIsParameter())
868 Symbol->setTag(dwarf::DW_TAG_formal_parameter);
869
870 setLocalVariableType(Symbol, Local.Type);
871 }
872
873 return Error::success();
874}
875
876// S_REGREL32_INDIR
879 LLVM_DEBUG({
880 printTypeIndex("Type", Local.Type);
881 W.printNumber("Offset", Local.Offset);
882 W.printNumber("OffsetInUdt", Local.OffsetInUdt);
883 W.printString("VarName", Local.Name);
884 });
885
886 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
887 Symbol->setName(Local.Name);
888
889 // Symbol was created as 'variable'; determine its real kind.
890 Symbol->resetIsVariable();
891
892 // Check for the 'this' symbol.
893 if (Local.Name == "this") {
894 Symbol->setIsArtificial();
895 Symbol->setIsParameter();
896 } else {
897 // Determine symbol kind.
898 determineSymbolKind(Symbol, Local.Register);
899 }
900
901 // Update correct debug information tag.
902 if (Symbol->getIsParameter())
903 Symbol->setTag(dwarf::DW_TAG_formal_parameter);
904
905 setLocalVariableType(Symbol, Local.Type);
906 }
907
908 return Error::success();
909}
910
911// S_BUILDINFO
913 BuildInfoSym &BuildInfo) {
914 LLVM_DEBUG({ printTypeIndex("BuildId", BuildInfo.BuildId); });
915
916 CVType CVBuildType = Ids.getType(BuildInfo.BuildId);
917 if (Error Err = LogicalVisitor->finishVisitation(
918 CVBuildType, BuildInfo.BuildId, Reader->getCompileUnit()))
919 return Err;
920
921 return Error::success();
922}
923
924// S_COMPILE2
926 Compile2Sym &Compile2) {
927 LLVM_DEBUG({
928 W.printEnum("Language", uint8_t(Compile2.getLanguage()),
930 W.printFlags("Flags", uint32_t(Compile2.getFlags()),
932 W.printEnum("Machine", unsigned(Compile2.Machine), getCPUTypeNames());
933 W.printString("VersionName", Compile2.Version);
934 });
935
936 // MSVC generates the following sequence for a CodeView module:
937 // S_OBJNAME --> Set 'CurrentObjectName'.
938 // S_COMPILE2 --> Set the compile unit name using 'CurrentObjectName'.
939 // ...
940 // S_BUILDINFO --> Extract the source name.
941 //
942 // Clang generates the following sequence for a CodeView module:
943 // S_COMPILE2 --> Set the compile unit name to empty string.
944 // ...
945 // S_BUILDINFO --> Extract the source name.
946 //
947 // For both toolchains, update the compile unit name from S_BUILDINFO.
948 if (LVScope *Scope = LogicalVisitor->CurrentScope) {
949 // The name of the CU, was extracted from the 'BuildInfo' subsection.
950 Reader->setCompileUnitCPUType(Compile2.Machine);
951 Scope->setName(CurrentObjectName);
952 if (options().getAttributeProducer())
953 Scope->setProducer(Compile2.Version);
954 if (options().getAttributeLanguage())
955 Scope->setSourceLanguage(LVSourceLanguage{
956 static_cast<llvm::codeview::SourceLanguage>(Compile2.getLanguage())});
957 getReader().isSystemEntry(Scope, CurrentObjectName);
958
959 // The line records in CodeView are recorded per Module ID. Update
960 // the relationship between the current CU and the Module ID.
961 Reader->addModule(Scope);
962
963 // Updated the collected strings with their associated compile unit.
964 Shared->StringRecords.addFilenames(Reader->getCompileUnit());
965 }
966
967 // Clear any previous ObjectName.
968 CurrentObjectName = "";
969 return Error::success();
970}
971
972// S_COMPILE3
974 Compile3Sym &Compile3) {
975 LLVM_DEBUG({
976 W.printEnum("Language", uint8_t(Compile3.getLanguage()),
978 W.printFlags("Flags", uint32_t(Compile3.getFlags()),
980 W.printEnum("Machine", unsigned(Compile3.Machine), getCPUTypeNames());
981 W.printString("VersionName", Compile3.Version);
982 });
983
984 // MSVC generates the following sequence for a CodeView module:
985 // S_OBJNAME --> Set 'CurrentObjectName'.
986 // S_COMPILE3 --> Set the compile unit name using 'CurrentObjectName'.
987 // ...
988 // S_BUILDINFO --> Extract the source name.
989 //
990 // Clang generates the following sequence for a CodeView module:
991 // S_COMPILE3 --> Set the compile unit name to empty string.
992 // ...
993 // S_BUILDINFO --> Extract the source name.
994 //
995 // For both toolchains, update the compile unit name from S_BUILDINFO.
996 if (LVScope *Scope = LogicalVisitor->CurrentScope) {
997 // The name of the CU, was extracted from the 'BuildInfo' subsection.
998 Reader->setCompileUnitCPUType(Compile3.Machine);
999 Scope->setName(CurrentObjectName);
1000 if (options().getAttributeProducer())
1001 Scope->setProducer(Compile3.Version);
1002 if (options().getAttributeLanguage())
1003 Scope->setSourceLanguage(LVSourceLanguage{
1004 static_cast<llvm::codeview::SourceLanguage>(Compile3.getLanguage())});
1005 getReader().isSystemEntry(Scope, CurrentObjectName);
1006
1007 // The line records in CodeView are recorded per Module ID. Update
1008 // the relationship between the current CU and the Module ID.
1009 Reader->addModule(Scope);
1010
1011 // Updated the collected strings with their associated compile unit.
1012 Shared->StringRecords.addFilenames(Reader->getCompileUnit());
1013 }
1014
1015 // Clear any previous ObjectName.
1016 CurrentObjectName = "";
1017 return Error::success();
1018}
1019
1020// S_CONSTANT, S_MANCONSTANT
1023 LLVM_DEBUG({
1024 printTypeIndex("Type", Constant.Type);
1025 W.printNumber("Value", Constant.Value);
1026 W.printString("Name", Constant.Name);
1027 });
1028
1029 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
1030 Symbol->setName(Constant.Name);
1031 Symbol->setType(LogicalVisitor->getElement(StreamTPI, Constant.Type));
1032 Symbol->resetIncludeInPrint();
1033 }
1034
1035 return Error::success();
1036}
1037
1038// S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE
1041 DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
1042 // DefRanges don't have types, just registers and code offsets.
1043 LLVM_DEBUG({
1044 if (LocalSymbol)
1045 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1046
1047 W.printNumber("Offset", DefRangeFramePointerRelFullScope.Offset);
1048 });
1049
1050 if (LVSymbol *Symbol = LocalSymbol) {
1051 Symbol->setHasCodeViewLocation();
1052 LocalSymbol = nullptr;
1053
1054 // Add location debug location. Operands: [Offset, 0].
1055 dwarf::Attribute Attr =
1056 dwarf::Attribute(SymbolKind::S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE);
1057
1058 uint64_t Operand1 = DefRangeFramePointerRelFullScope.Offset;
1059 Symbol->addLocation(Attr, 0, 0, 0, 0);
1060 Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
1061 }
1062
1063 return Error::success();
1064}
1065
1066// S_DEFRANGE_FRAMEPOINTER_REL
1068 CVSymbol &Record, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
1069 // DefRanges don't have types, just registers and code offsets.
1070 LLVM_DEBUG({
1071 if (LocalSymbol)
1072 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1073
1074 W.printNumber("Offset", DefRangeFramePointerRel.Hdr.Offset);
1075 printLocalVariableAddrRange(DefRangeFramePointerRel.Range,
1076 DefRangeFramePointerRel.getRelocationOffset());
1077 printLocalVariableAddrGap(DefRangeFramePointerRel.Gaps);
1078 });
1079
1080 // We are expecting the following sequence:
1081 // 128 | S_LOCAL [size = 20] `ParamBar`
1082 // ...
1083 // 148 | S_DEFRANGE_FRAMEPOINTER_REL [size = 16]
1084 if (LVSymbol *Symbol = LocalSymbol) {
1085 Symbol->setHasCodeViewLocation();
1086 LocalSymbol = nullptr;
1087
1088 // Add location debug location. Operands: [Offset, 0].
1089 dwarf::Attribute Attr =
1090 dwarf::Attribute(SymbolKind::S_DEFRANGE_FRAMEPOINTER_REL);
1091 uint64_t Operand1 = DefRangeFramePointerRel.Hdr.Offset;
1092
1093 LocalVariableAddrRange Range = DefRangeFramePointerRel.Range;
1095 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1096
1097 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1098 Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
1099 }
1100
1101 return Error::success();
1102}
1103
1104// S_DEFRANGE_REGISTER_REL
1106 CVSymbol &Record, DefRangeRegisterRelSym &DefRangeRegisterRel) {
1107 // DefRanges don't have types, just registers and code offsets.
1108 LLVM_DEBUG({
1109 if (LocalSymbol)
1110 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1111
1112 W.printBoolean("HasSpilledUDTMember",
1113 DefRangeRegisterRel.hasSpilledUDTMember());
1114 W.printNumber("OffsetInParent", DefRangeRegisterRel.offsetInParent());
1115 W.printNumber("BasePointerOffset",
1116 DefRangeRegisterRel.Hdr.BasePointerOffset);
1117 printLocalVariableAddrRange(DefRangeRegisterRel.Range,
1118 DefRangeRegisterRel.getRelocationOffset());
1119 printLocalVariableAddrGap(DefRangeRegisterRel.Gaps);
1120 });
1121
1122 if (LVSymbol *Symbol = LocalSymbol) {
1123 Symbol->setHasCodeViewLocation();
1124 LocalSymbol = nullptr;
1125
1126 // Add location debug location. Operands: [Register, Offset].
1127 dwarf::Attribute Attr =
1128 dwarf::Attribute(SymbolKind::S_DEFRANGE_REGISTER_REL);
1129 uint64_t Operand1 = DefRangeRegisterRel.Hdr.Register;
1130 uint64_t Operand2 = DefRangeRegisterRel.Hdr.BasePointerOffset;
1131
1132 LocalVariableAddrRange Range = DefRangeRegisterRel.Range;
1134 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1135
1136 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1137 Symbol->addLocationOperands(LVSmall(Attr), {Operand1, Operand2});
1138 }
1139
1140 return Error::success();
1141}
1142
1143// S_DEFRANGE_REGISTER_REL_INDIR
1145 CVSymbol &Record, DefRangeRegisterRelIndirSym &DefRangeRegisterRelIndir) {
1146 // DefRanges don't have types, just registers and code offsets.
1147 LLVM_DEBUG({
1148 if (LocalSymbol)
1149 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1150
1151 W.printBoolean("HasSpilledUDTMember",
1152 DefRangeRegisterRelIndir.hasSpilledUDTMember());
1153 W.printNumber("OffsetInParent", DefRangeRegisterRelIndir.offsetInParent());
1154 W.printNumber("BasePointerOffset",
1155 DefRangeRegisterRelIndir.Hdr.BasePointerOffset);
1156 W.printNumber("OffsetInUdt", DefRangeRegisterRelIndir.Hdr.OffsetInUdt);
1157 printLocalVariableAddrRange(DefRangeRegisterRelIndir.Range,
1158 DefRangeRegisterRelIndir.getRelocationOffset());
1159 printLocalVariableAddrGap(DefRangeRegisterRelIndir.Gaps);
1160 });
1161
1162 if (LVSymbol *Symbol = LocalSymbol) {
1163 Symbol->setHasCodeViewLocation();
1164 LocalSymbol = nullptr;
1165
1166 // Add location debug location. Operands: [Register, Offset, OffsetInUdt].
1167 dwarf::Attribute Attr =
1168 dwarf::Attribute(SymbolKind::S_DEFRANGE_REGISTER_REL_INDIR);
1169 const uint64_t Operand1 = DefRangeRegisterRelIndir.Hdr.Register;
1170 const uint64_t Operand2 = DefRangeRegisterRelIndir.Hdr.BasePointerOffset;
1171 const uint64_t Operand3 = DefRangeRegisterRelIndir.Hdr.OffsetInUdt;
1172
1173 const LocalVariableAddrRange Range = DefRangeRegisterRelIndir.Range;
1174 const LVAddress Address =
1175 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1176
1177 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1178 Symbol->addLocationOperands(LVSmall(Attr), {Operand1, Operand2, Operand3});
1179 }
1180
1181 return Error::success();
1182}
1183
1184// S_DEFRANGE_REGISTER
1186 DefRangeRegisterSym &DefRangeRegister) {
1187 // DefRanges don't have types, just registers and code offsets.
1188 LLVM_DEBUG({
1189 if (LocalSymbol)
1190 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1191
1192 W.printEnum("Register", uint16_t(DefRangeRegister.Hdr.Register),
1193 getRegisterNames(Reader->getCompileUnitCPUType()));
1194 W.printNumber("MayHaveNoName", DefRangeRegister.Hdr.MayHaveNoName);
1195 printLocalVariableAddrRange(DefRangeRegister.Range,
1196 DefRangeRegister.getRelocationOffset());
1197 printLocalVariableAddrGap(DefRangeRegister.Gaps);
1198 });
1199
1200 if (LVSymbol *Symbol = LocalSymbol) {
1201 Symbol->setHasCodeViewLocation();
1202 LocalSymbol = nullptr;
1203
1204 // Add location debug location. Operands: [Register, 0].
1205 dwarf::Attribute Attr = dwarf::Attribute(SymbolKind::S_DEFRANGE_REGISTER);
1206 uint64_t Operand1 = DefRangeRegister.Hdr.Register;
1207
1208 LocalVariableAddrRange Range = DefRangeRegister.Range;
1210 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1211
1212 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1213 Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
1214 }
1215
1216 return Error::success();
1217}
1218
1219// S_DEFRANGE_SUBFIELD_REGISTER
1221 CVSymbol &Record, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
1222 // DefRanges don't have types, just registers and code offsets.
1223 LLVM_DEBUG({
1224 if (LocalSymbol)
1225 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1226
1227 W.printEnum("Register", uint16_t(DefRangeSubfieldRegister.Hdr.Register),
1228 getRegisterNames(Reader->getCompileUnitCPUType()));
1229 W.printNumber("MayHaveNoName", DefRangeSubfieldRegister.Hdr.MayHaveNoName);
1230 W.printNumber("OffsetInParent",
1231 DefRangeSubfieldRegister.Hdr.OffsetInParent);
1232 printLocalVariableAddrRange(DefRangeSubfieldRegister.Range,
1233 DefRangeSubfieldRegister.getRelocationOffset());
1234 printLocalVariableAddrGap(DefRangeSubfieldRegister.Gaps);
1235 });
1236
1237 if (LVSymbol *Symbol = LocalSymbol) {
1238 Symbol->setHasCodeViewLocation();
1239 LocalSymbol = nullptr;
1240
1241 // Add location debug location. Operands: [Register, 0].
1242 dwarf::Attribute Attr =
1243 dwarf::Attribute(SymbolKind::S_DEFRANGE_SUBFIELD_REGISTER);
1244 uint64_t Operand1 = DefRangeSubfieldRegister.Hdr.Register;
1245
1246 LocalVariableAddrRange Range = DefRangeSubfieldRegister.Range;
1248 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1249
1250 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1251 Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
1252 }
1253
1254 return Error::success();
1255}
1256
1257// S_DEFRANGE_SUBFIELD
1259 DefRangeSubfieldSym &DefRangeSubfield) {
1260 // DefRanges don't have types, just registers and code offsets.
1261 LLVM_DEBUG({
1262 if (LocalSymbol)
1263 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1264
1265 if (ObjDelegate) {
1266 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
1267 auto ExpectedProgram = Strings.getString(DefRangeSubfield.Program);
1268 if (!ExpectedProgram) {
1269 consumeError(ExpectedProgram.takeError());
1271 "String table offset outside of bounds of String Table!");
1272 }
1273 W.printString("Program", *ExpectedProgram);
1274 }
1275 W.printNumber("OffsetInParent", DefRangeSubfield.OffsetInParent);
1276 printLocalVariableAddrRange(DefRangeSubfield.Range,
1277 DefRangeSubfield.getRelocationOffset());
1278 printLocalVariableAddrGap(DefRangeSubfield.Gaps);
1279 });
1280
1281 if (LVSymbol *Symbol = LocalSymbol) {
1282 Symbol->setHasCodeViewLocation();
1283 LocalSymbol = nullptr;
1284
1285 // Add location debug location. Operands: [Program, 0].
1286 dwarf::Attribute Attr = dwarf::Attribute(SymbolKind::S_DEFRANGE_SUBFIELD);
1287 uint64_t Operand1 = DefRangeSubfield.Program;
1288
1289 LocalVariableAddrRange Range = DefRangeSubfield.Range;
1291 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1292
1293 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1294 Symbol->addLocationOperands(LVSmall(Attr), {Operand1, /*Operand2=*/0});
1295 }
1296
1297 return Error::success();
1298}
1299
1300// S_DEFRANGE
1302 DefRangeSym &DefRange) {
1303 // DefRanges don't have types, just registers and code offsets.
1304 LLVM_DEBUG({
1305 if (LocalSymbol)
1306 W.getOStream() << formatv("Symbol: {0}, ", LocalSymbol->getName());
1307
1308 if (ObjDelegate) {
1309 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
1310 auto ExpectedProgram = Strings.getString(DefRange.Program);
1311 if (!ExpectedProgram) {
1312 consumeError(ExpectedProgram.takeError());
1314 "String table offset outside of bounds of String Table!");
1315 }
1316 W.printString("Program", *ExpectedProgram);
1317 }
1318 printLocalVariableAddrRange(DefRange.Range, DefRange.getRelocationOffset());
1319 printLocalVariableAddrGap(DefRange.Gaps);
1320 });
1321
1322 if (LVSymbol *Symbol = LocalSymbol) {
1323 Symbol->setHasCodeViewLocation();
1324 LocalSymbol = nullptr;
1325
1326 // Add location debug location. Operands: [Program, 0].
1327 dwarf::Attribute Attr = dwarf::Attribute(SymbolKind::S_DEFRANGE);
1328 uint64_t Operand1 = DefRange.Program;
1329
1332 Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
1333
1334 Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
1335 Symbol->addLocationOperands(LVSmall(Attr), {Operand1, /*Operand2=*/0});
1336 }
1337
1338 return Error::success();
1339}
1340
1341// S_FRAMEPROC
1343 FrameProcSym &FrameProc) {
1344 if (LVScope *Function = LogicalVisitor->getReaderScope()) {
1345 // S_FRAMEPROC contains extra information for the function described
1346 // by any of the previous generated records:
1347 // S_GPROC32, S_LPROC32, S_LPROC32_ID, S_GPROC32_ID.
1348
1349 // The generated sequence is:
1350 // S_GPROC32_ID ...
1351 // S_FRAMEPROC ...
1352
1353 // Collect additional inline flags for the current scope function.
1354 FrameProcedureOptions Flags = FrameProc.Flags;
1360 Function->setInlineCode(dwarf::DW_INL_inlined);
1361
1362 // To determine the symbol kind for any symbol declared in that function,
1363 // we can access the S_FRAMEPROC for the parent scope function. It contains
1364 // information about the local fp and param fp registers and compare with
1365 // the register in the S_REGREL32 to get a match.
1366 codeview::CPUType CPU = Reader->getCompileUnitCPUType();
1367 LocalFrameRegister = FrameProc.getLocalFramePtrReg(CPU);
1368 ParamFrameRegister = FrameProc.getParamFramePtrReg(CPU);
1369 }
1370
1371 return Error::success();
1372}
1373
1374// S_GDATA32, S_LDATA32, S_LMANDATA, S_GMANDATA
1376 LLVM_DEBUG({
1377 printTypeIndex("Type", Data.Type);
1378 W.printString("DisplayName", Data.Name);
1379 });
1380
1381 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
1383 if (ObjDelegate)
1384 ObjDelegate->getLinkageName(Data.getRelocationOffset(), Data.DataOffset,
1385 &LinkageName);
1386
1387 Symbol->setName(Data.Name);
1388 Symbol->setLinkageName(LinkageName);
1389
1390 // The MSVC generates local data as initialization for aggregates. It
1391 // contains the address for an initialization function.
1392 // The symbols contains the '$initializer$' pattern. Allow them only if
1393 // the '--internal=system' option is given.
1394 // 0 | S_LDATA32 `Struct$initializer$`
1395 // type = 0x1040 (void ()*)
1396 if (getReader().isSystemEntry(Symbol) && !options().getAttributeSystem()) {
1397 Symbol->resetIncludeInPrint();
1398 return Error::success();
1399 }
1400
1401 if (LVScope *Namespace = Shared->NamespaceDeduction.get(Data.Name)) {
1402 // The variable is already at different scope. In order to reflect
1403 // the correct parent, move it to the namespace.
1404 if (Symbol->getParentScope()->removeElement(Symbol))
1405 Namespace->addElement(Symbol);
1406 }
1407
1408 Symbol->setType(LogicalVisitor->getElement(StreamTPI, Data.Type));
1409 if (Record.kind() == SymbolKind::S_GDATA32)
1410 Symbol->setIsExternal();
1411 }
1412
1413 return Error::success();
1414}
1415
1416// S_INLINESITE
1419 LLVM_DEBUG({ printTypeIndex("Inlinee", InlineSite.Inlinee); });
1420
1421 if (LVScope *InlinedFunction = LogicalVisitor->CurrentScope) {
1422 LVScope *AbstractFunction = Reader->createScopeFunction();
1423 AbstractFunction->setIsSubprogram();
1424 AbstractFunction->setTag(dwarf::DW_TAG_subprogram);
1425 AbstractFunction->setInlineCode(dwarf::DW_INL_inlined);
1426 AbstractFunction->setIsInlinedAbstract();
1427 InlinedFunction->setReference(AbstractFunction);
1428
1429 LogicalVisitor->startProcessArgumentList();
1430 // 'Inlinee' is a Type ID.
1431 CVType CVFunctionType = Ids.getType(InlineSite.Inlinee);
1432 if (Error Err = LogicalVisitor->finishVisitation(
1433 CVFunctionType, InlineSite.Inlinee, AbstractFunction))
1434 return Err;
1435 LogicalVisitor->stopProcessArgumentList();
1436
1437 // For inlined functions set the linkage name to be the same as
1438 // the name. It used to find their lines and ranges.
1439 StringRef Name = AbstractFunction->getName();
1440 InlinedFunction->setName(Name);
1441 InlinedFunction->setLinkageName(Name);
1442
1443 // Process annotation bytes to calculate code and line offsets.
1444 if (Error Err = LogicalVisitor->inlineSiteAnnotation(
1445 AbstractFunction, InlinedFunction, InlineSite))
1446 return Err;
1447 }
1448
1449 return Error::success();
1450}
1451
1452// S_LOCAL
1454 LLVM_DEBUG({
1455 printTypeIndex("Type", Local.Type);
1456 W.printFlags("Flags", uint16_t(Local.Flags), getLocalFlagNames());
1457 W.printString("VarName", Local.Name);
1458 });
1459
1460 if (LVSymbol *Symbol = LogicalVisitor->CurrentSymbol) {
1461 Symbol->setName(Local.Name);
1462
1463 // Symbol was created as 'variable'; determine its real kind.
1464 Symbol->resetIsVariable();
1465
1466 // Be sure the 'this' symbol is marked as 'compiler generated'.
1467 if (bool(Local.Flags & LocalSymFlags::IsCompilerGenerated) ||
1468 Local.Name == "this") {
1469 Symbol->setIsArtificial();
1470 Symbol->setIsParameter();
1471 } else {
1472 bool(Local.Flags & LocalSymFlags::IsParameter) ? Symbol->setIsParameter()
1473 : Symbol->setIsVariable();
1474 }
1475
1476 // Update correct debug information tag.
1477 if (Symbol->getIsParameter())
1478 Symbol->setTag(dwarf::DW_TAG_formal_parameter);
1479
1480 setLocalVariableType(Symbol, Local.Type);
1481
1482 // The CodeView records (S_DEFFRAME_*) describing debug location for
1483 // this symbol, do not have any direct reference to it. Those records
1484 // are emitted after this symbol. Record the current symbol.
1485 LocalSymbol = Symbol;
1486 }
1487
1488 return Error::success();
1489}
1490
1491// S_OBJNAME
1493 LLVM_DEBUG({
1494 W.printHex("Signature", ObjName.Signature);
1495 W.printString("ObjectName", ObjName.Name);
1496 });
1497
1498 CurrentObjectName = ObjName.Name;
1499 return Error::success();
1500}
1501
1502// S_GPROC32, S_LPROC32, S_LPROC32_ID, S_GPROC32_ID
1504 if (InFunctionScope)
1505 return llvm::make_error<CodeViewError>("Visiting a ProcSym while inside "
1506 "function scope!");
1507
1508 InFunctionScope = true;
1509
1510 LLVM_DEBUG({
1511 printTypeIndex("FunctionType", Proc.FunctionType);
1512 W.printHex("Segment", Proc.Segment);
1513 W.printFlags("Flags", static_cast<uint8_t>(Proc.Flags),
1515 W.printString("DisplayName", Proc.Name);
1516 });
1517
1518 // Clang and Microsoft generated different debug information records:
1519 // For functions definitions:
1520 // Clang: S_GPROC32 -> LF_FUNC_ID -> LF_PROCEDURE
1521 // Microsoft: S_GPROC32 -> LF_PROCEDURE
1522
1523 // For member function definition:
1524 // Clang: S_GPROC32 -> LF_MFUNC_ID -> LF_MFUNCTION
1525 // Microsoft: S_GPROC32 -> LF_MFUNCTION
1526 // In order to support both sequences, if we found LF_FUNCTION_ID, just
1527 // get the TypeIndex for LF_PROCEDURE.
1528
1529 // For the given test case, we have the sequence:
1530 // namespace NSP_local {
1531 // void foo_local() {
1532 // }
1533 // }
1534 //
1535 // 0x1000 | LF_STRING_ID String: NSP_local
1536 // 0x1002 | LF_PROCEDURE
1537 // return type = 0x0003 (void), # args = 0, param list = 0x1001
1538 // calling conv = cdecl, options = None
1539 // 0x1003 | LF_FUNC_ID
1540 // name = foo_local, type = 0x1002, parent scope = 0x1000
1541 // 0 | S_GPROC32_ID `NSP_local::foo_local`
1542 // type = `0x1003 (foo_local)`
1543 // 0x1004 | LF_STRING_ID String: suite
1544 // 0x1005 | LF_STRING_ID String: suite_local.cpp
1545 //
1546 // The LF_STRING_ID can hold different information:
1547 // 0x1000 - The enclosing namespace.
1548 // 0x1004 - The compile unit directory name.
1549 // 0x1005 - The compile unit name.
1550 //
1551 // Before deducting its scope, we need to evaluate its type and create any
1552 // associated namespaces.
1553 if (LVScope *Function = LogicalVisitor->CurrentScope) {
1555 if (ObjDelegate)
1556 ObjDelegate->getLinkageName(Proc.getRelocationOffset(), Proc.CodeOffset,
1557 &LinkageName);
1558
1559 // The line table can be accessed using the linkage name.
1560 Reader->addToSymbolTable(LinkageName, Function);
1561 Function->setName(Proc.Name);
1562 Function->setLinkageName(LinkageName);
1563
1564 if (options().getGeneralCollectRanges()) {
1565 // Record converted segment::offset addressing for this scope.
1566 LVAddress Addendum = Reader->getSymbolTableAddress(LinkageName);
1567 LVAddress LowPC =
1568 Reader->linearAddress(Proc.Segment, Proc.CodeOffset, Addendum);
1569 LVAddress HighPC = LowPC + Proc.CodeSize - 1;
1570 Function->addObject(LowPC, HighPC);
1571
1572 // If the scope is a function, add it to the public names.
1573 if ((options().getAttributePublics() || options().getPrintAnyLine()) &&
1574 !Function->getIsInlinedFunction())
1575 Reader->getCompileUnit()->addPublicName(Function, LowPC, HighPC);
1576 }
1577
1578 if (Function->getIsSystem() && !options().getAttributeSystem()) {
1579 Function->resetIncludeInPrint();
1580 return Error::success();
1581 }
1582
1583 TypeIndex TIFunctionType = Proc.FunctionType;
1584 if (TIFunctionType.isSimple())
1585 Function->setType(LogicalVisitor->getElement(StreamTPI, TIFunctionType));
1586 else {
1587 // We have to detect the correct stream, using the lexical parent
1588 // name, as there is not other obvious way to get the stream.
1589 // Normal function: LF_FUNC_ID (TPI)/(IPI)
1590 // LF_PROCEDURE (TPI)
1591 // Lambda function: LF_MFUNCTION (TPI)
1592 // Member function: LF_MFUNC_ID (TPI)/(IPI)
1593
1594 StringRef OuterComponent;
1595 std::tie(OuterComponent, std::ignore) = getInnerComponent(Proc.Name);
1596 TypeIndex TI = Shared->ForwardReferences.find(OuterComponent);
1597
1598 std::optional<CVType> CVFunctionType;
1599 auto GetRecordType = [&]() -> bool {
1600 CVFunctionType = Ids.tryGetType(TIFunctionType);
1601 if (!CVFunctionType)
1602 return false;
1603
1604 if (TI.isNoneType())
1605 // Normal function.
1606 if (CVFunctionType->kind() == LF_FUNC_ID)
1607 return true;
1608
1609 // Member function.
1610 return (CVFunctionType->kind() == LF_MFUNC_ID);
1611 };
1612
1613 // We can have a LF_FUNC_ID, LF_PROCEDURE or LF_MFUNCTION.
1614 if (!GetRecordType()) {
1615 CVFunctionType = Types.tryGetType(TIFunctionType);
1616 if (!CVFunctionType)
1617 return llvm::make_error<CodeViewError>("Invalid type index");
1618 }
1619
1620 if (Error Err = LogicalVisitor->finishVisitation(
1621 *CVFunctionType, TIFunctionType, Function))
1622 return Err;
1623 }
1624
1625 if (Record.kind() == SymbolKind::S_GPROC32 ||
1626 Record.kind() == SymbolKind::S_GPROC32_ID)
1627 Function->setIsExternal();
1628
1629 // We don't have a way to see if the symbol is compiler generated. Use
1630 // the linkage name, to detect `scalar deleting destructor' functions.
1631 std::string DemangledSymbol = demangle(LinkageName);
1632 if (DemangledSymbol.find("scalar deleting dtor") != std::string::npos) {
1633 Function->setIsArtificial();
1634 } else {
1635 // Clang generates global ctor and dtor names containing the substrings:
1636 // 'dynamic initializer for' and 'dynamic atexit destructor for'.
1637 if (DemangledSymbol.find("dynamic atexit destructor for") !=
1638 std::string::npos)
1639 Function->setIsArtificial();
1640 }
1641 }
1642
1643 return Error::success();
1644}
1645
1646// S_END
1648 ScopeEndSym &ScopeEnd) {
1649 InFunctionScope = false;
1650 return Error::success();
1651}
1652
1653// S_THUNK32
1655 if (InFunctionScope)
1656 return llvm::make_error<CodeViewError>("Visiting a Thunk32Sym while inside "
1657 "function scope!");
1658
1659 InFunctionScope = true;
1660
1661 LLVM_DEBUG({
1662 W.printHex("Segment", Thunk.Segment);
1663 W.printString("Name", Thunk.Name);
1664 });
1665
1666 if (LVScope *Function = LogicalVisitor->CurrentScope)
1667 Function->setName(Thunk.Name);
1668
1669 return Error::success();
1670}
1671
1672// S_UDT, S_COBOLUDT
1674 LLVM_DEBUG({
1675 printTypeIndex("Type", UDT.Type);
1676 W.printString("UDTName", UDT.Name);
1677 });
1678
1679 if (LVType *Type = LogicalVisitor->CurrentType) {
1680 if (LVScope *Namespace = Shared->NamespaceDeduction.get(UDT.Name)) {
1681 if (Type->getParentScope()->removeElement(Type))
1682 Namespace->addElement(Type);
1683 }
1684
1685 Type->setName(UDT.Name);
1686
1687 // We have to determine if the typedef is a real C/C++ definition or is
1688 // the S_UDT record that describe all the user defined types.
1689 // 0 | S_UDT `Name` original type = 0x1009
1690 // 0x1009 | LF_STRUCTURE `Name`
1691 // Ignore type definitions for RTTI types:
1692 // _s__RTTIBaseClassArray, _s__RTTIBaseClassDescriptor,
1693 // _s__RTTICompleteObjectLocator, _s__RTTIClassHierarchyDescriptor.
1694 if (getReader().isSystemEntry(Type))
1695 Type->resetIncludeInPrint();
1696 else {
1697 StringRef RecordName = getRecordName(Types, UDT.Type);
1698 if (UDT.Name == RecordName)
1699 Type->resetIncludeInPrint();
1700 Type->setType(LogicalVisitor->getElement(StreamTPI, UDT.Type));
1701 }
1702 }
1703
1704 return Error::success();
1705}
1706
1707// S_UNAMESPACE
1709 UsingNamespaceSym &UN) {
1710 LLVM_DEBUG({ W.printString("Namespace", UN.Name); });
1711 return Error::success();
1712}
1713
1714// S_ARMSWITCHTABLE
1717 LLVM_DEBUG({
1718 W.printHex("BaseOffset", JumpTable.BaseOffset);
1719 W.printNumber("BaseSegment", JumpTable.BaseSegment);
1720 W.printFlags("SwitchType", static_cast<uint16_t>(JumpTable.SwitchType),
1722 W.printHex("BranchOffset", JumpTable.BranchOffset);
1723 W.printHex("TableOffset", JumpTable.TableOffset);
1724 W.printNumber("BranchSegment", JumpTable.BranchSegment);
1725 W.printNumber("TableSegment", JumpTable.TableSegment);
1726 W.printNumber("EntriesCount", JumpTable.EntriesCount);
1727 });
1728 return Error::success();
1729}
1730
1731// S_CALLERS, S_CALLEES, S_INLINEES
1733 LLVM_DEBUG({
1734 llvm::StringRef FieldName;
1735 switch (Caller.getKind()) {
1736 case SymbolRecordKind::CallerSym:
1737 FieldName = "Callee";
1738 break;
1739 case SymbolRecordKind::CalleeSym:
1740 FieldName = "Caller";
1741 break;
1742 case SymbolRecordKind::InlineesSym:
1743 FieldName = "Inlinee";
1744 break;
1745 default:
1747 "Unknown CV Record type for a CallerSym object!");
1748 }
1749 for (auto FuncID : Caller.Indices) {
1750 printTypeIndex(FieldName, FuncID);
1751 }
1752 });
1753 return Error::success();
1754}
1755
1756void LVSymbolVisitor::setLocalVariableType(LVSymbol *Symbol, TypeIndex TI) {
1757 LVElement *Element = LogicalVisitor->getElement(StreamTPI, TI);
1758 if (Element && Element->getIsScoped()) {
1759 // We have a local type. Find its parent function.
1760 LVScope *Parent = Symbol->getFunctionParent();
1761 // The element representing the type has been already finalized. If
1762 // the type is an aggregate type, its members have been already added.
1763 // As the type is local, its level will be changed.
1764
1765 // FIXME: Currently the algorithm used to scope lambda functions is
1766 // incorrect. Before we allocate the type at this scope, check if is
1767 // already allocated in other scope.
1768 if (!Element->getParentScope()) {
1769 Parent->addElement(Element);
1770 Element->updateLevel(Parent);
1771 }
1772 }
1773 Symbol->setType(Element);
1774}
1775
1776#undef DEBUG_TYPE
1777#define DEBUG_TYPE "CodeViewLogicalVisitor"
1778
1779//===----------------------------------------------------------------------===//
1780// Logical visitor.
1781//===----------------------------------------------------------------------===//
1783 InputFile &Input)
1784 : Reader(Reader), W(W), Input(Input) {
1785 // The LogicalVisitor connects the CodeViewReader with the visitors that
1786 // traverse the types, symbols, etc. Do any initialization that is needed.
1787 Shared = std::make_shared<LVShared>(Reader, this);
1788}
1789
1791 uint32_t StreamIdx) {
1792 codeview::printTypeIndex(W, FieldName, TI,
1793 StreamIdx == StreamTPI ? types() : ids());
1794}
1795
1797 LVElement *Element, uint32_t StreamIdx) {
1798 W.getOStream() << "\n";
1799 W.startLine() << formatTypeLeafKind(Record.kind());
1800 W.getOStream() << " (" << HexNumber(TI.getIndex()) << ")";
1801 W.getOStream() << " {\n";
1802 W.indent();
1803 W.printEnum("TypeLeafKind", unsigned(Record.kind()), ArrayRef(LeafTypeNames));
1804 printTypeIndex("TI", TI, StreamIdx);
1805 W.startLine() << "Element: " << HexNumber(Element->getOffset()) << " "
1806 << Element->getName() << "\n";
1807}
1808
1810 W.unindent();
1811 W.startLine() << "}\n";
1812}
1813
1815 LVElement *Element,
1816 uint32_t StreamIdx) {
1817 W.getOStream() << "\n";
1818 W.startLine() << formatTypeLeafKind(Record.Kind);
1819 W.getOStream() << " (" << HexNumber(TI.getIndex()) << ")";
1820 W.getOStream() << " {\n";
1821 W.indent();
1822 W.printEnum("TypeLeafKind", unsigned(Record.Kind), ArrayRef(LeafTypeNames));
1823 printTypeIndex("TI", TI, StreamIdx);
1824 W.startLine() << "Element: " << HexNumber(Element->getOffset()) << " "
1825 << Element->getName() << "\n";
1826}
1827
1829 W.unindent();
1830 W.startLine() << "}\n";
1831}
1832
1834 LLVM_DEBUG({
1835 printTypeIndex("\nTI", TI, StreamTPI);
1836 W.printNumber("Length", uint32_t(Record.content().size()));
1837 });
1838 return Error::success();
1839}
1840
1841// LF_ARGLIST (TPI)
1843 TypeIndex TI, LVElement *Element) {
1844 ArrayRef<TypeIndex> Indices = Args.getIndices();
1845 uint32_t Size = Indices.size();
1846 LLVM_DEBUG({
1847 printTypeBegin(Record, TI, Element, StreamTPI);
1848 W.printNumber("NumArgs", Size);
1849 ListScope Arguments(W, "Arguments");
1850 for (uint32_t I = 0; I < Size; ++I)
1851 printTypeIndex("ArgType", Indices[I], StreamTPI);
1853 });
1854
1855 LVScope *Function = static_cast<LVScope *>(Element);
1856 for (uint32_t Index = 0; Index < Size; ++Index) {
1857 TypeIndex ParameterType = Indices[Index];
1858 createParameter(ParameterType, StringRef(), Function);
1859 }
1860
1861 return Error::success();
1862}
1863
1864// LF_ARRAY (TPI)
1866 TypeIndex TI, LVElement *Element) {
1867 LLVM_DEBUG({
1868 printTypeBegin(Record, TI, Element, StreamTPI);
1869 printTypeIndex("ElementType", AT.getElementType(), StreamTPI);
1870 printTypeIndex("IndexType", AT.getIndexType(), StreamTPI);
1871 W.printNumber("SizeOf", AT.getSize());
1872 W.printString("Name", AT.getName());
1874 });
1875
1876 if (Element->getIsFinalized())
1877 return Error::success();
1878 Element->setIsFinalized();
1879
1880 LVScopeArray *Array = static_cast<LVScopeArray *>(Element);
1881 if (!Array)
1882 return Error::success();
1883
1884 Reader->getCompileUnit()->addElement(Array);
1885 TypeIndex TIElementType = AT.getElementType();
1886
1887 LVType *PrevSubrange = nullptr;
1889
1890 // As the logical view is modeled on DWARF, for each dimension we have to
1891 // create a DW_TAG_subrange_type, with dimension size.
1892 // The subrange type can be: unsigned __int32 or unsigned __int64.
1893 auto AddSubrangeType = [&](ArrayRecord &AR) {
1894 LVType *Subrange = Reader->createTypeSubrange();
1895 Subrange->setTag(dwarf::DW_TAG_subrange_type);
1896 Subrange->setType(getElement(StreamTPI, AR.getIndexType()));
1897 Subrange->setCount(AR.getSize());
1898 Subrange->setOffset(
1899 TIElementType.isSimple()
1900 ? (uint32_t)(TypeLeafKind)TIElementType.getSimpleKind()
1901 : TIElementType.getIndex());
1902 Array->addElement(Subrange);
1903
1904 if (PrevSubrange)
1905 if (int64_t Count = Subrange->getCount())
1906 PrevSubrange->setCount(PrevSubrange->getCount() / Count);
1907 PrevSubrange = Subrange;
1908 };
1909
1910 // Preserve the original TypeIndex; it would be updated in the case of:
1911 // - The array type contains qualifiers.
1912 // - In multidimensional arrays, the last LF_ARRAY entry contains the type.
1913 TypeIndex TIArrayType;
1914
1915 // For each dimension in the array, there is a LF_ARRAY entry. The last
1916 // entry contains the array type, which can be a LF_MODIFIER in the case
1917 // of the type being modified by a qualifier (const, etc).
1918 ArrayRecord AR(AT);
1919 CVType CVEntry = Record;
1920 while (CVEntry.kind() == LF_ARRAY) {
1921 // Create the subrange information, required by the logical view. Once
1922 // the array has been processed, the dimension sizes will updated, as
1923 // the sizes are a progression. For instance:
1924 // sizeof(int) = 4
1925 // int Array[2]; Sizes: 8 Dim: 8 / 4 -> [2]
1926 // int Array[2][3]; Sizes: 24, 12 Dim: 24 / 12 -> [2]
1927 // Dim: 12 / 4 -> [3]
1928 // int Array[2][3][4]; sizes: 96, 48, 16 Dim: 96 / 48 -> [2]
1929 // Dim: 48 / 16 -> [3]
1930 // Dim: 16 / 4 -> [4]
1931 AddSubrangeType(AR);
1932 TIArrayType = TIElementType;
1933
1934 // The current ElementType can be a modifier, in which case we need to
1935 // get the type being modified.
1936 // If TypeIndex is not a simple type, check if we have a qualified type.
1937 if (!TIElementType.isSimple()) {
1938 CVType CVElementType = Types.getType(TIElementType);
1939 if (CVElementType.kind() == LF_MODIFIER) {
1940 LVElement *QualifiedType =
1941 Shared->TypeRecords.find(StreamTPI, TIElementType);
1942 if (Error Err =
1943 finishVisitation(CVElementType, TIElementType, QualifiedType))
1944 return Err;
1945 // Get the TypeIndex of the type that the LF_MODIFIER modifies.
1946 TIElementType = getModifiedType(CVElementType);
1947 }
1948 }
1949 // Ends the traversal, as we have reached a simple type (int, char, etc).
1950 if (TIElementType.isSimple())
1951 break;
1952
1953 // Read next dimension linked entry, if any.
1954 CVEntry = Types.getType(TIElementType);
1956 const_cast<CVType &>(CVEntry), AR)) {
1957 consumeError(std::move(Err));
1958 break;
1959 }
1960 TIElementType = AR.getElementType();
1961 // NOTE: The typeindex has a value of: 0x0280.0000
1962 getTrueType(TIElementType);
1963 }
1964
1965 Array->setName(AT.getName());
1966 TIArrayType = Shared->ForwardReferences.remap(TIArrayType);
1967 Array->setType(getElement(StreamTPI, TIArrayType));
1968
1969 if (PrevSubrange)
1970 // In the case of an aggregate type (class, struct, union, interface),
1971 // get the aggregate size. As the original record is pointing to its
1972 // reference, we have to update it.
1973 if (uint64_t Size =
1974 isAggregate(CVEntry)
1975 ? getSizeInBytesForTypeRecord(Types.getType(TIArrayType))
1976 : getSizeInBytesForTypeIndex(TIElementType))
1977 PrevSubrange->setCount(PrevSubrange->getCount() / Size);
1978
1979 return Error::success();
1980}
1981
1982// LF_BITFIELD (TPI)
1984 TypeIndex TI, LVElement *Element) {
1985 LLVM_DEBUG({
1986 printTypeBegin(Record, TI, Element, StreamTPI);
1987 printTypeIndex("Type", TI, StreamTPI);
1988 W.printNumber("BitSize", BF.getBitSize());
1989 W.printNumber("BitOffset", BF.getBitOffset());
1991 });
1992
1993 Element->setType(getElement(StreamTPI, BF.getType()));
1994 Element->setBitSize(BF.getBitSize());
1995 return Error::success();
1996}
1997
1998// LF_BUILDINFO (TPI)/(IPI)
2000 TypeIndex TI, LVElement *Element) {
2001 LLVM_DEBUG({
2002 printTypeBegin(Record, TI, Element, StreamIPI);
2003 W.printNumber("NumArgs", static_cast<uint32_t>(BI.getArgs().size()));
2004 ListScope Arguments(W, "Arguments");
2005 for (TypeIndex Arg : BI.getArgs())
2006 printTypeIndex("ArgType", Arg, StreamIPI);
2008 });
2009
2010 // The given 'Element' refers to the current compilation unit.
2011 // All the args are references into the TPI/IPI stream.
2013 std::string Name = std::string(ids().getTypeName(TIName));
2014
2015 // There are cases where LF_BUILDINFO fields are empty.
2016 if (!Name.empty())
2017 Element->setName(Name);
2018
2019 return Error::success();
2020}
2021
2022// LF_CLASS, LF_STRUCTURE, LF_INTERFACE (TPI)
2024 TypeIndex TI, LVElement *Element) {
2025 LLVM_DEBUG({
2026 printTypeBegin(Record, TI, Element, StreamTPI);
2027 W.printNumber("MemberCount", Class.getMemberCount());
2028 printTypeIndex("FieldList", Class.getFieldList(), StreamTPI);
2029 printTypeIndex("DerivedFrom", Class.getDerivationList(), StreamTPI);
2030 printTypeIndex("VShape", Class.getVTableShape(), StreamTPI);
2031 W.printNumber("SizeOf", Class.getSize());
2032 W.printString("Name", Class.getName());
2033 if (Class.hasUniqueName())
2034 W.printString("UniqueName", Class.getUniqueName());
2036 });
2037
2038 if (Element->getIsFinalized())
2039 return Error::success();
2040 Element->setIsFinalized();
2041
2042 LVScopeAggregate *Scope = static_cast<LVScopeAggregate *>(Element);
2043 if (!Scope)
2044 return Error::success();
2045
2046 Scope->setName(Class.getName());
2047 if (Class.hasUniqueName())
2048 Scope->setLinkageName(Class.getUniqueName());
2049 Scope->setBitSize(Class.getSize() * DWARF_CHAR_BIT);
2050
2051 if (Class.isNested()) {
2052 Scope->setIsNested();
2053 createParents(Class.getName(), Scope);
2054 }
2055
2056 if (Class.isScoped())
2057 Scope->setIsScoped();
2058
2059 // Nested types will be added to their parents at creation. The forward
2060 // references are only processed to finish the referenced element creation.
2061 if (!(Class.isNested() || Class.isScoped())) {
2062 if (LVScope *Namespace = Shared->NamespaceDeduction.get(Class.getName()))
2063 Namespace->addElement(Scope);
2064 else
2065 Reader->getCompileUnit()->addElement(Scope);
2066 }
2067
2069 TypeIndex TIFieldList = Class.getFieldList();
2070 if (TIFieldList.isNoneType()) {
2071 TypeIndex ForwardType = Shared->ForwardReferences.find(Class.getName());
2072 if (!ForwardType.isNoneType()) {
2073 CVType CVReference = Types.getType(ForwardType);
2074 TypeRecordKind RK = static_cast<TypeRecordKind>(CVReference.kind());
2075 ClassRecord ReferenceRecord(RK);
2077 const_cast<CVType &>(CVReference), ReferenceRecord))
2078 return Err;
2079 TIFieldList = ReferenceRecord.getFieldList();
2080 }
2081 }
2082
2083 if (!TIFieldList.isNoneType()) {
2084 // Pass down the TypeIndex 'TI' for the aggregate containing the field list.
2085 CVType CVFieldList = Types.getType(TIFieldList);
2086 if (Error Err = finishVisitation(CVFieldList, TI, Scope))
2087 return Err;
2088 }
2089
2090 return Error::success();
2091}
2092
2093// LF_ENUM (TPI)
2095 TypeIndex TI, LVElement *Element) {
2096 LLVM_DEBUG({
2097 printTypeBegin(Record, TI, Element, StreamTPI);
2098 W.printNumber("NumEnumerators", Enum.getMemberCount());
2099 printTypeIndex("UnderlyingType", Enum.getUnderlyingType(), StreamTPI);
2100 printTypeIndex("FieldListType", Enum.getFieldList(), StreamTPI);
2101 W.printString("Name", Enum.getName());
2103 });
2104
2105 LVScopeEnumeration *Scope = static_cast<LVScopeEnumeration *>(Element);
2106 if (!Scope)
2107 return Error::success();
2108
2109 if (Scope->getIsFinalized())
2110 return Error::success();
2111 Scope->setIsFinalized();
2112
2113 // Set the name, as in the case of nested, it would determine the relation
2114 // to any potential parent, via the LF_NESTTYPE record.
2115 Scope->setName(Enum.getName());
2116 if (Enum.hasUniqueName())
2117 Scope->setLinkageName(Enum.getUniqueName());
2118
2119 Scope->setType(getElement(StreamTPI, Enum.getUnderlyingType()));
2120
2121 if (Enum.isNested()) {
2122 Scope->setIsNested();
2123 createParents(Enum.getName(), Scope);
2124 }
2125
2126 if (Enum.isScoped()) {
2127 Scope->setIsScoped();
2128 Scope->setIsEnumClass();
2129 }
2130
2131 // Nested types will be added to their parents at creation.
2132 if (!(Enum.isNested() || Enum.isScoped())) {
2133 if (LVScope *Namespace = Shared->NamespaceDeduction.get(Enum.getName()))
2134 Namespace->addElement(Scope);
2135 else
2136 Reader->getCompileUnit()->addElement(Scope);
2137 }
2138
2139 TypeIndex TIFieldList = Enum.getFieldList();
2140 if (!TIFieldList.isNoneType()) {
2142 CVType CVFieldList = Types.getType(TIFieldList);
2143 if (Error Err = finishVisitation(CVFieldList, TIFieldList, Scope))
2144 return Err;
2145 }
2146
2147 return Error::success();
2148}
2149
2150// LF_FIELDLIST (TPI)
2153 TypeIndex TI, LVElement *Element) {
2154 LLVM_DEBUG({
2155 printTypeBegin(Record, TI, Element, StreamTPI);
2157 });
2158
2159 if (Error Err = visitFieldListMemberStream(TI, Element, FieldList.Data))
2160 return Err;
2161
2162 return Error::success();
2163}
2164
2165// LF_FUNC_ID (TPI)/(IPI)
2167 TypeIndex TI, LVElement *Element) {
2168 // ParentScope and FunctionType are references into the TPI stream.
2169 LLVM_DEBUG({
2170 printTypeBegin(Record, TI, Element, StreamIPI);
2171 printTypeIndex("ParentScope", Func.getParentScope(), StreamTPI);
2172 printTypeIndex("FunctionType", Func.getFunctionType(), StreamTPI);
2173 W.printString("Name", Func.getName());
2175 });
2176
2177 // The TypeIndex (LF_PROCEDURE) returned by 'getFunctionType' is the
2178 // function propotype, we need to use the function definition.
2179 if (LVScope *FunctionDcl = static_cast<LVScope *>(Element)) {
2180 // For inlined functions, the inlined instance has been already processed
2181 // (all its information is contained in the Symbols section).
2182 // 'Element' points to the created 'abstract' (out-of-line) function.
2183 // Use the parent scope information to allocate it to the correct scope.
2185 TypeIndex TIParent = Func.getParentScope();
2186 if (FunctionDcl->getIsInlinedAbstract()) {
2187 FunctionDcl->setName(Func.getName());
2188 if (TIParent.isNoneType())
2189 Reader->getCompileUnit()->addElement(FunctionDcl);
2190 }
2191
2192 if (!TIParent.isNoneType()) {
2193 CVType CVParentScope = ids().getType(TIParent);
2194 if (Error Err = finishVisitation(CVParentScope, TIParent, FunctionDcl))
2195 return Err;
2196 }
2197
2198 TypeIndex TIFunctionType = Func.getFunctionType();
2199 CVType CVFunctionType = Types.getType(TIFunctionType);
2200 if (Error Err =
2201 finishVisitation(CVFunctionType, TIFunctionType, FunctionDcl))
2202 return Err;
2203
2204 FunctionDcl->setIsFinalized();
2205 }
2206
2207 return Error::success();
2208}
2209
2210// LF_LABEL (TPI)
2212 TypeIndex TI, LVElement *Element) {
2213 LLVM_DEBUG({
2214 printTypeBegin(Record, TI, Element, StreamTPI);
2216 });
2217 return Error::success();
2218}
2219
2220// LF_MFUNC_ID (TPI)/(IPI)
2222 TypeIndex TI, LVElement *Element) {
2223 // ClassType and FunctionType are references into the TPI stream.
2224 LLVM_DEBUG({
2225 printTypeBegin(Record, TI, Element, StreamIPI);
2226 printTypeIndex("ClassType", Id.getClassType(), StreamTPI);
2227 printTypeIndex("FunctionType", Id.getFunctionType(), StreamTPI);
2228 W.printString("Name", Id.getName());
2230 });
2231
2232 LVScope *FunctionDcl = static_cast<LVScope *>(Element);
2233 if (FunctionDcl->getIsInlinedAbstract()) {
2234 // For inlined functions, the inlined instance has been already processed
2235 // (all its information is contained in the Symbols section).
2236 // 'Element' points to the created 'abstract' (out-of-line) function.
2237 // Use the parent scope information to allocate it to the correct scope.
2238 if (LVScope *Class = static_cast<LVScope *>(
2239 Shared->TypeRecords.find(StreamTPI, Id.getClassType())))
2240 Class->addElement(FunctionDcl);
2241 }
2242
2243 TypeIndex TIFunctionType = Id.getFunctionType();
2244 CVType CVFunction = types().getType(TIFunctionType);
2245 if (Error Err = finishVisitation(CVFunction, TIFunctionType, Element))
2246 return Err;
2247
2248 return Error::success();
2249}
2250
2251// LF_MFUNCTION (TPI)
2254 LVElement *Element) {
2255 LLVM_DEBUG({
2256 printTypeBegin(Record, TI, Element, StreamTPI);
2257 printTypeIndex("ReturnType", MF.getReturnType(), StreamTPI);
2258 printTypeIndex("ClassType", MF.getClassType(), StreamTPI);
2259 printTypeIndex("ThisType", MF.getThisType(), StreamTPI);
2260 W.printNumber("NumParameters", MF.getParameterCount());
2261 printTypeIndex("ArgListType", MF.getArgumentList(), StreamTPI);
2262 W.printNumber("ThisAdjustment", MF.getThisPointerAdjustment());
2264 });
2265
2266 if (LVScope *MemberFunction = static_cast<LVScope *>(Element)) {
2268
2269 MemberFunction->setIsFinalized();
2270 MemberFunction->setType(getElement(StreamTPI, MF.getReturnType()));
2271 MemberFunction->setOffset(TI.getIndex());
2272 MemberFunction->setOffsetFromTypeIndex();
2273
2274 if (ProcessArgumentList) {
2275 ProcessArgumentList = false;
2276
2277 if (!MemberFunction->getIsStatic()) {
2278 LVElement *ThisPointer = getElement(StreamTPI, MF.getThisType());
2279 // When creating the 'this' pointer, check if it points to a reference.
2280 ThisPointer->setType(Class);
2281 LVSymbol *This =
2282 createParameter(ThisPointer, StringRef(), MemberFunction);
2283 This->setIsArtificial();
2284 }
2285
2286 // Create formal parameters.
2288 CVType CVArguments = Types.getType(MF.getArgumentList());
2289 if (Error Err = finishVisitation(CVArguments, MF.getArgumentList(),
2290 MemberFunction))
2291 return Err;
2292 }
2293 }
2294
2295 return Error::success();
2296}
2297
2298// LF_METHODLIST (TPI)
2300 MethodOverloadListRecord &Overloads,
2301 TypeIndex TI, LVElement *Element) {
2302 LLVM_DEBUG({
2303 printTypeBegin(Record, TI, Element, StreamTPI);
2305 });
2306
2307 for (OneMethodRecord &Method : Overloads.Methods) {
2309 Record.Kind = LF_METHOD;
2310 Method.Name = OverloadedMethodName;
2311 if (Error Err = visitKnownMember(Record, Method, TI, Element))
2312 return Err;
2313 }
2314
2315 return Error::success();
2316}
2317
2318// LF_MODIFIER (TPI)
2320 TypeIndex TI, LVElement *Element) {
2321 LLVM_DEBUG({
2322 printTypeBegin(Record, TI, Element, StreamTPI);
2323 printTypeIndex("ModifiedType", Mod.getModifiedType(), StreamTPI);
2325 });
2326
2327 // Create the modified type, which will be attached to the type(s) that
2328 // contains the modifiers.
2329 LVElement *ModifiedType = getElement(StreamTPI, Mod.getModifiedType());
2330
2331 // At this point the types recording the qualifiers do not have a
2332 // scope parent. They must be assigned to the current compile unit.
2333 LVScopeCompileUnit *CompileUnit = Reader->getCompileUnit();
2334
2335 // The incoming element does not have a defined kind. Use the given
2336 // modifiers to complete its type. A type can have more than one modifier;
2337 // in that case, we have to create an extra type to have the other modifier.
2338 LVType *LastLink = static_cast<LVType *>(Element);
2339 if (!LastLink->getParentScope())
2340 CompileUnit->addElement(LastLink);
2341
2342 bool SeenModifier = false;
2343 uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers());
2344 if (Mods & uint16_t(ModifierOptions::Const)) {
2345 SeenModifier = true;
2346 LastLink->setTag(dwarf::DW_TAG_const_type);
2347 LastLink->setIsConst();
2348 LastLink->setName("const");
2349 }
2350 if (Mods & uint16_t(ModifierOptions::Volatile)) {
2351 if (SeenModifier) {
2352 LVType *Volatile = Reader->createType();
2353 Volatile->setIsModifier();
2354 LastLink->setType(Volatile);
2355 LastLink = Volatile;
2356 CompileUnit->addElement(LastLink);
2357 }
2358 LastLink->setTag(dwarf::DW_TAG_volatile_type);
2359 LastLink->setIsVolatile();
2360 LastLink->setName("volatile");
2361 }
2363 if (SeenModifier) {
2364 LVType *Unaligned = Reader->createType();
2365 Unaligned->setIsModifier();
2366 LastLink->setType(Unaligned);
2367 LastLink = Unaligned;
2368 CompileUnit->addElement(LastLink);
2369 }
2371 LastLink->setIsUnaligned();
2372 LastLink->setName("unaligned");
2373 }
2374
2375 LastLink->setType(ModifiedType);
2376 return Error::success();
2377}
2378
2379// LF_POINTER (TPI)
2381 TypeIndex TI, LVElement *Element) {
2382 LLVM_DEBUG({
2383 printTypeBegin(Record, TI, Element, StreamTPI);
2384 printTypeIndex("PointeeType", Ptr.getReferentType(), StreamTPI);
2385 W.printNumber("IsFlat", Ptr.isFlat());
2386 W.printNumber("IsConst", Ptr.isConst());
2387 W.printNumber("IsVolatile", Ptr.isVolatile());
2388 W.printNumber("IsUnaligned", Ptr.isUnaligned());
2389 W.printNumber("IsRestrict", Ptr.isRestrict());
2390 W.printNumber("IsThisPtr&", Ptr.isLValueReferenceThisPtr());
2391 W.printNumber("IsThisPtr&&", Ptr.isRValueReferenceThisPtr());
2392 W.printNumber("SizeOf", Ptr.getSize());
2393
2394 if (Ptr.isPointerToMember()) {
2395 const MemberPointerInfo &MI = Ptr.getMemberInfo();
2396 printTypeIndex("ClassType", MI.getContainingType(), StreamTPI);
2397 }
2399 });
2400
2401 // Find the pointed-to type.
2402 LVType *Pointer = static_cast<LVType *>(Element);
2403 LVElement *Pointee = nullptr;
2404
2405 PointerMode Mode = Ptr.getMode();
2406 Pointee = Ptr.isPointerToMember()
2407 ? Shared->TypeRecords.find(StreamTPI, Ptr.getReferentType())
2409
2410 // At this point the types recording the qualifiers do not have a
2411 // scope parent. They must be assigned to the current compile unit.
2412 LVScopeCompileUnit *CompileUnit = Reader->getCompileUnit();
2413
2414 // Order for the different modifiers:
2415 // <restrict> <pointer, Reference, ValueReference> <const, volatile>
2416 // Const and volatile already processed.
2417 bool SeenModifier = false;
2418 LVType *LastLink = Pointer;
2419 if (!LastLink->getParentScope())
2420 CompileUnit->addElement(LastLink);
2421
2422 if (Ptr.isRestrict()) {
2423 SeenModifier = true;
2424 LVType *Restrict = Reader->createType();
2425 Restrict->setTag(dwarf::DW_TAG_restrict_type);
2426 Restrict->setIsRestrict();
2427 Restrict->setName("restrict");
2428 LastLink->setType(Restrict);
2429 LastLink = Restrict;
2430 CompileUnit->addElement(LastLink);
2431 }
2432 if (Mode == PointerMode::LValueReference) {
2433 if (SeenModifier) {
2434 LVType *LReference = Reader->createType();
2435 LReference->setIsModifier();
2436 LastLink->setType(LReference);
2437 LastLink = LReference;
2438 CompileUnit->addElement(LastLink);
2439 }
2440 LastLink->setTag(dwarf::DW_TAG_reference_type);
2441 LastLink->setIsReference();
2442 LastLink->setName("&");
2443 }
2444 if (Mode == PointerMode::RValueReference) {
2445 if (SeenModifier) {
2446 LVType *RReference = Reader->createType();
2447 RReference->setIsModifier();
2448 LastLink->setType(RReference);
2449 LastLink = RReference;
2450 CompileUnit->addElement(LastLink);
2451 }
2452 LastLink->setTag(dwarf::DW_TAG_rvalue_reference_type);
2453 LastLink->setIsRvalueReference();
2454 LastLink->setName("&&");
2455 }
2456
2457 // When creating the pointer, check if it points to a reference.
2458 LastLink->setType(Pointee);
2459 return Error::success();
2460}
2461
2462// LF_PROCEDURE (TPI)
2464 TypeIndex TI, LVElement *Element) {
2465 LLVM_DEBUG({
2466 printTypeBegin(Record, TI, Element, StreamTPI);
2467 printTypeIndex("ReturnType", Proc.getReturnType(), StreamTPI);
2468 W.printNumber("NumParameters", Proc.getParameterCount());
2469 printTypeIndex("ArgListType", Proc.getArgumentList(), StreamTPI);
2471 });
2472
2473 // There is no need to traverse the argument list, as the CodeView format
2474 // declares the parameters as a 'S_LOCAL' symbol tagged as parameter.
2475 // Only process parameters when dealing with inline functions.
2476 if (LVScope *FunctionDcl = static_cast<LVScope *>(Element)) {
2477 FunctionDcl->setType(getElement(StreamTPI, Proc.getReturnType()));
2478
2479 if (ProcessArgumentList) {
2480 ProcessArgumentList = false;
2481 // Create formal parameters.
2483 CVType CVArguments = Types.getType(Proc.getArgumentList());
2484 if (Error Err = finishVisitation(CVArguments, Proc.getArgumentList(),
2485 FunctionDcl))
2486 return Err;
2487 }
2488 }
2489
2490 return Error::success();
2491}
2492
2493// LF_UNION (TPI)
2495 TypeIndex TI, LVElement *Element) {
2496 LLVM_DEBUG({
2497 printTypeBegin(Record, TI, Element, StreamTPI);
2498 W.printNumber("MemberCount", Union.getMemberCount());
2499 printTypeIndex("FieldList", Union.getFieldList(), StreamTPI);
2500 W.printNumber("SizeOf", Union.getSize());
2501 W.printString("Name", Union.getName());
2502 if (Union.hasUniqueName())
2503 W.printString("UniqueName", Union.getUniqueName());
2505 });
2506
2507 LVScopeAggregate *Scope = static_cast<LVScopeAggregate *>(Element);
2508 if (!Scope)
2509 return Error::success();
2510
2511 if (Scope->getIsFinalized())
2512 return Error::success();
2513 Scope->setIsFinalized();
2514
2515 Scope->setName(Union.getName());
2516 if (Union.hasUniqueName())
2517 Scope->setLinkageName(Union.getUniqueName());
2518 Scope->setBitSize(Union.getSize() * DWARF_CHAR_BIT);
2519
2520 if (Union.isNested()) {
2521 Scope->setIsNested();
2522 createParents(Union.getName(), Scope);
2523 } else {
2524 if (LVScope *Namespace = Shared->NamespaceDeduction.get(Union.getName()))
2525 Namespace->addElement(Scope);
2526 else
2527 Reader->getCompileUnit()->addElement(Scope);
2528 }
2529
2530 if (!Union.getFieldList().isNoneType()) {
2532 // Pass down the TypeIndex 'TI' for the aggregate containing the field list.
2533 CVType CVFieldList = Types.getType(Union.getFieldList());
2534 if (Error Err = finishVisitation(CVFieldList, TI, Scope))
2535 return Err;
2536 }
2537
2538 return Error::success();
2539}
2540
2541// LF_TYPESERVER2 (TPI)
2543 TypeIndex TI, LVElement *Element) {
2544 LLVM_DEBUG({
2545 printTypeBegin(Record, TI, Element, StreamTPI);
2546 W.printString("Guid", formatv("{0}", TS.getGuid()).str());
2547 W.printNumber("Age", TS.getAge());
2548 W.printString("Name", TS.getName());
2550 });
2551 return Error::success();
2552}
2553
2554// LF_VFTABLE (TPI)
2556 TypeIndex TI, LVElement *Element) {
2557 LLVM_DEBUG({
2558 printTypeBegin(Record, TI, Element, StreamTPI);
2559 printTypeIndex("CompleteClass", VFT.getCompleteClass(), StreamTPI);
2560 printTypeIndex("OverriddenVFTable", VFT.getOverriddenVTable(), StreamTPI);
2561 W.printHex("VFPtrOffset", VFT.getVFPtrOffset());
2562 W.printString("VFTableName", VFT.getName());
2563 for (const StringRef &N : VFT.getMethodNames())
2564 W.printString("MethodName", N);
2566 });
2567 return Error::success();
2568}
2569
2570// LF_VTSHAPE (TPI)
2572 VFTableShapeRecord &Shape,
2573 TypeIndex TI, LVElement *Element) {
2574 LLVM_DEBUG({
2575 printTypeBegin(Record, TI, Element, StreamTPI);
2576 W.printNumber("VFEntryCount", Shape.getEntryCount());
2578 });
2579 return Error::success();
2580}
2581
2582// LF_SUBSTR_LIST (TPI)/(IPI)
2584 StringListRecord &Strings,
2585 TypeIndex TI, LVElement *Element) {
2586 // All the indices are references into the TPI/IPI stream.
2587 LLVM_DEBUG({
2588 printTypeBegin(Record, TI, Element, StreamIPI);
2589 ArrayRef<TypeIndex> Indices = Strings.getIndices();
2590 uint32_t Size = Indices.size();
2591 W.printNumber("NumStrings", Size);
2592 ListScope Arguments(W, "Strings");
2593 for (uint32_t I = 0; I < Size; ++I)
2594 printTypeIndex("String", Indices[I], StreamIPI);
2596 });
2597 return Error::success();
2598}
2599
2600// LF_STRING_ID (TPI)/(IPI)
2602 TypeIndex TI, LVElement *Element) {
2603 // All args are references into the TPI/IPI stream.
2604 LLVM_DEBUG({
2605 printTypeIndex("\nTI", TI, StreamIPI);
2606 printTypeIndex("Id", String.getId(), StreamIPI);
2607 W.printString("StringData", String.getString());
2608 });
2609
2610 if (LVScope *Namespace = Shared->NamespaceDeduction.get(
2611 String.getString(), /*CheckScope=*/false)) {
2612 // The function is already at different scope. In order to reflect
2613 // the correct parent, move it to the namespace.
2614 if (LVScope *Scope = Element->getParentScope())
2615 Scope->removeElement(Element);
2616 Namespace->addElement(Element);
2617 }
2618
2619 return Error::success();
2620}
2621
2622// LF_UDT_SRC_LINE (TPI)/(IPI)
2624 UdtSourceLineRecord &SourceLine,
2625 TypeIndex TI, LVElement *Element) {
2626 // All args are references into the TPI/IPI stream.
2627 LLVM_DEBUG({
2628 printTypeIndex("\nTI", TI, StreamIPI);
2629 printTypeIndex("UDT", SourceLine.getUDT(), StreamIPI);
2630 printTypeIndex("SourceFile", SourceLine.getSourceFile(), StreamIPI);
2631 W.printNumber("LineNumber", SourceLine.getLineNumber());
2632 });
2633 return Error::success();
2634}
2635
2636// LF_UDT_MOD_SRC_LINE (TPI)/(IPI)
2638 UdtModSourceLineRecord &ModSourceLine,
2639 TypeIndex TI, LVElement *Element) {
2640 // All args are references into the TPI/IPI stream.
2641 LLVM_DEBUG({
2642 printTypeBegin(Record, TI, Element, StreamIPI);
2643 printTypeIndex("\nTI", TI, StreamIPI);
2644 printTypeIndex("UDT", ModSourceLine.getUDT(), StreamIPI);
2645 printTypeIndex("SourceFile", ModSourceLine.getSourceFile(), StreamIPI);
2646 W.printNumber("LineNumber", ModSourceLine.getLineNumber());
2647 W.printNumber("Module", ModSourceLine.getModule());
2649 });
2650 return Error::success();
2651}
2652
2653// LF_PRECOMP (TPI)
2655 TypeIndex TI, LVElement *Element) {
2656 LLVM_DEBUG({
2657 printTypeBegin(Record, TI, Element, StreamTPI);
2658 W.printHex("StartIndex", Precomp.getStartTypeIndex());
2659 W.printHex("Count", Precomp.getTypesCount());
2660 W.printHex("Signature", Precomp.getSignature());
2661 W.printString("PrecompFile", Precomp.getPrecompFilePath());
2663 });
2664 return Error::success();
2665}
2666
2667// LF_ENDPRECOMP (TPI)
2669 EndPrecompRecord &EndPrecomp,
2670 TypeIndex TI, LVElement *Element) {
2671 LLVM_DEBUG({
2672 printTypeBegin(Record, TI, Element, StreamTPI);
2673 W.printHex("Signature", EndPrecomp.getSignature());
2675 });
2676 return Error::success();
2677}
2678
2680 TypeIndex TI) {
2681 LLVM_DEBUG({ W.printHex("UnknownMember", unsigned(Record.Kind)); });
2682 return Error::success();
2683}
2684
2685// LF_BCLASS, LF_BINTERFACE
2688 LVElement *Element) {
2689 LLVM_DEBUG({
2690 printMemberBegin(Record, TI, Element, StreamTPI);
2691 printTypeIndex("BaseType", Base.getBaseType(), StreamTPI);
2692 W.printHex("BaseOffset", Base.getBaseOffset());
2694 });
2695
2696 createElement(Record.Kind);
2697 if (LVSymbol *Symbol = CurrentSymbol) {
2698 LVElement *BaseClass = getElement(StreamTPI, Base.getBaseType());
2699 Symbol->setName(BaseClass->getName());
2700 Symbol->setType(BaseClass);
2701 Symbol->setAccessibilityCode(Base.getAccess());
2702 static_cast<LVScope *>(Element)->addElement(Symbol);
2703 }
2704
2705 return Error::success();
2706}
2707
2708// LF_MEMBER
2711 LVElement *Element) {
2712 LLVM_DEBUG({
2713 printMemberBegin(Record, TI, Element, StreamTPI);
2714 printTypeIndex("Type", Field.getType(), StreamTPI);
2715 W.printHex("FieldOffset", Field.getFieldOffset());
2716 W.printString("Name", Field.getName());
2718 });
2719
2720 // Create the data member.
2721 createDataMember(Record, static_cast<LVScope *>(Element), Field.getName(),
2722 Field.getType(), Field.getAccess());
2723 return Error::success();
2724}
2725
2726// LF_ENUMERATE
2729 LVElement *Element) {
2730 LLVM_DEBUG({
2731 printMemberBegin(Record, TI, Element, StreamTPI);
2732 W.printNumber("EnumValue", Enum.getValue());
2733 W.printString("Name", Enum.getName());
2735 });
2736
2737 createElement(Record.Kind);
2738 if (LVType *Type = CurrentType) {
2739 Type->setName(Enum.getName());
2741 Enum.getValue().toString(Value, 16, true, true);
2742 Type->setValue(Value);
2743 static_cast<LVScope *>(Element)->addElement(CurrentType);
2744 }
2745
2746 return Error::success();
2747}
2748
2749// LF_INDEX
2752 TypeIndex TI, LVElement *Element) {
2753 LLVM_DEBUG({
2754 printMemberBegin(Record, TI, Element, StreamTPI);
2755 printTypeIndex("ContinuationIndex", Cont.getContinuationIndex(), StreamTPI);
2757 });
2758 return Error::success();
2759}
2760
2761// LF_NESTTYPE
2764 LVElement *Element) {
2765 LLVM_DEBUG({
2766 printMemberBegin(Record, TI, Element, StreamTPI);
2767 printTypeIndex("Type", Nested.getNestedType(), StreamTPI);
2768 W.printString("Name", Nested.getName());
2770 });
2771
2772 if (LVElement *Typedef = createElement(SymbolKind::S_UDT)) {
2773 Typedef->setName(Nested.getName());
2774 LVElement *NestedType = getElement(StreamTPI, Nested.getNestedType());
2775 Typedef->setType(NestedType);
2776 LVScope *Scope = static_cast<LVScope *>(Element);
2777 Scope->addElement(Typedef);
2778
2779 if (NestedType && NestedType->getIsNested()) {
2780 // 'Element' is an aggregate type that may contains this nested type
2781 // definition. Used their scoped names, to decide on their relationship.
2782 StringRef RecordName = getRecordName(types(), TI);
2783
2784 StringRef NestedTypeName = NestedType->getName();
2785 if (NestedTypeName.size() && RecordName.size()) {
2786 StringRef OuterComponent;
2787 std::tie(OuterComponent, std::ignore) =
2788 getInnerComponent(NestedTypeName);
2789 // We have an already created nested type. Add it to the current scope
2790 // and update all its children if any.
2791 if (OuterComponent.size() && OuterComponent == RecordName) {
2792 if (!NestedType->getIsScopedAlready()) {
2793 Scope->addElement(NestedType);
2794 NestedType->setIsScopedAlready();
2795 NestedType->updateLevel(Scope);
2796 }
2797 Typedef->resetIncludeInPrint();
2798 }
2799 }
2800 }
2801 }
2802
2803 return Error::success();
2804}
2805
2806// LF_ONEMETHOD
2808 OneMethodRecord &Method, TypeIndex TI,
2809 LVElement *Element) {
2810 LLVM_DEBUG({
2811 printMemberBegin(Record, TI, Element, StreamTPI);
2812 printTypeIndex("Type", Method.getType(), StreamTPI);
2813 // If virtual, then read the vftable offset.
2814 if (Method.isIntroducingVirtual())
2815 W.printHex("VFTableOffset", Method.getVFTableOffset());
2816 W.printString("Name", Method.getName());
2818 });
2819
2820 // All the LF_ONEMETHOD objects share the same type description.
2821 // We have to create a scope object for each one and get the required
2822 // information from the LF_MFUNCTION object.
2823 ProcessArgumentList = true;
2824 if (LVElement *MemberFunction = createElement(TypeLeafKind::LF_ONEMETHOD)) {
2825 MemberFunction->setIsFinalized();
2826 static_cast<LVScope *>(Element)->addElement(MemberFunction);
2827
2828 MemberFunction->setName(Method.getName());
2829 MemberFunction->setAccessibilityCode(Method.getAccess());
2830
2831 MethodKind Kind = Method.getMethodKind();
2832 if (Kind == MethodKind::Static)
2833 MemberFunction->setIsStatic();
2834 MemberFunction->setVirtualityCode(Kind);
2835
2836 MethodOptions Flags = Method.Attrs.getFlags();
2839 MemberFunction->setIsArtificial();
2840
2842 CVType CVMethodType = Types.getType(Method.getType());
2843 if (Error Err =
2844 finishVisitation(CVMethodType, Method.getType(), MemberFunction))
2845 return Err;
2846 }
2847 ProcessArgumentList = false;
2848
2849 return Error::success();
2850}
2851
2852// LF_METHOD
2854 OverloadedMethodRecord &Method,
2855 TypeIndex TI, LVElement *Element) {
2856 LLVM_DEBUG({
2857 printMemberBegin(Record, TI, Element, StreamTPI);
2858 W.printHex("MethodCount", Method.getNumOverloads());
2859 printTypeIndex("MethodListIndex", Method.getMethodList(), StreamTPI);
2860 W.printString("Name", Method.getName());
2862 });
2863
2864 // Record the overloaded method name, which will be used during the
2865 // traversal of the method list.
2867 OverloadedMethodName = Method.getName();
2868 CVType CVMethods = Types.getType(Method.getMethodList());
2869 if (Error Err = finishVisitation(CVMethods, Method.getMethodList(), Element))
2870 return Err;
2871
2872 return Error::success();
2873}
2874
2875// LF_STMEMBER
2878 TypeIndex TI, LVElement *Element) {
2879 LLVM_DEBUG({
2880 printMemberBegin(Record, TI, Element, StreamTPI);
2881 printTypeIndex("Type", Field.getType(), StreamTPI);
2882 W.printString("Name", Field.getName());
2884 });
2885
2886 // Create the data member.
2887 createDataMember(Record, static_cast<LVScope *>(Element), Field.getName(),
2888 Field.getType(), Field.getAccess());
2889 return Error::success();
2890}
2891
2892// LF_VFUNCTAB
2894 VFPtrRecord &VFTable, TypeIndex TI,
2895 LVElement *Element) {
2896 LLVM_DEBUG({
2897 printMemberBegin(Record, TI, Element, StreamTPI);
2898 printTypeIndex("Type", VFTable.getType(), StreamTPI);
2900 });
2901 return Error::success();
2902}
2903
2904// LF_VBCLASS, LF_IVBCLASS
2907 TypeIndex TI, LVElement *Element) {
2908 LLVM_DEBUG({
2909 printMemberBegin(Record, TI, Element, StreamTPI);
2910 printTypeIndex("BaseType", Base.getBaseType(), StreamTPI);
2911 printTypeIndex("VBPtrType", Base.getVBPtrType(), StreamTPI);
2912 W.printHex("VBPtrOffset", Base.getVBPtrOffset());
2913 W.printHex("VBTableIndex", Base.getVTableIndex());
2915 });
2916
2917 createElement(Record.Kind);
2918 if (LVSymbol *Symbol = CurrentSymbol) {
2919 LVElement *BaseClass = getElement(StreamTPI, Base.getBaseType());
2920 Symbol->setName(BaseClass->getName());
2921 Symbol->setType(BaseClass);
2922 Symbol->setAccessibilityCode(Base.getAccess());
2923 Symbol->setVirtualityCode(MethodKind::Virtual);
2924 static_cast<LVScope *>(Element)->addElement(Symbol);
2925 }
2926
2927 return Error::success();
2928}
2929
2931 TypeVisitorCallbacks &Callbacks,
2932 TypeIndex TI, LVElement *Element) {
2933 if (Error Err = Callbacks.visitMemberBegin(Record))
2934 return Err;
2935
2936 switch (Record.Kind) {
2937 default:
2938 if (Error Err = Callbacks.visitUnknownMember(Record))
2939 return Err;
2940 break;
2941#define MEMBER_RECORD(EnumName, EnumVal, Name) \
2942 case EnumName: { \
2943 if (Error Err = \
2944 visitKnownMember<Name##Record>(Record, Callbacks, TI, Element)) \
2945 return Err; \
2946 break; \
2947 }
2948#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
2949 MEMBER_RECORD(EnumVal, EnumVal, AliasName)
2950#define TYPE_RECORD(EnumName, EnumVal, Name)
2951#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
2952#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
2953 }
2954
2955 if (Error Err = Callbacks.visitMemberEnd(Record))
2956 return Err;
2957
2958 return Error::success();
2959}
2960
2962 LVElement *Element) {
2963 switch (Record.kind()) {
2964 default:
2965 if (Error Err = visitUnknownType(Record, TI))
2966 return Err;
2967 break;
2968#define TYPE_RECORD(EnumName, EnumVal, Name) \
2969 case EnumName: { \
2970 if (Error Err = visitKnownRecord<Name##Record>(Record, TI, Element)) \
2971 return Err; \
2972 break; \
2973 }
2974#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
2975 TYPE_RECORD(EnumVal, EnumVal, AliasName)
2976#define MEMBER_RECORD(EnumName, EnumVal, Name)
2977#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
2978#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
2979 }
2980
2981 return Error::success();
2982}
2983
2984// Customized version of 'FieldListVisitHelper'.
2985Error LVLogicalVisitor::visitFieldListMemberStream(
2988 BinaryStreamReader Reader(Stream);
2989 FieldListDeserializer Deserializer(Reader);
2991 Pipeline.addCallbackToPipeline(Deserializer);
2992
2993 TypeLeafKind Leaf;
2994 while (!Reader.empty()) {
2995 if (Error Err = Reader.readEnum(Leaf))
2996 return Err;
2997
2999 Record.Kind = Leaf;
3000 if (Error Err = visitMemberRecord(Record, Pipeline, TI, Element))
3001 return Err;
3002 }
3003
3004 return Error::success();
3005}
3006
3008 // The CodeView specifications does not treat S_COMPILE2 and S_COMPILE3
3009 // as symbols that open a scope. The CodeView reader, treat them in a
3010 // similar way as DWARF. As there is no a symbole S_END to close the
3011 // compile unit, we need to check for the next compile unit.
3012 if (IsCompileUnit) {
3013 if (!ScopeStack.empty())
3014 popScope();
3015 InCompileUnitScope = true;
3016 }
3017
3018 pushScope(Scope);
3019 ReaderParent->addElement(Scope);
3020}
3021
3023 ReaderScope->addElement(Symbol);
3024}
3025
3027 ReaderScope->addElement(Type);
3028}
3029
3031 CurrentScope = nullptr;
3032 CurrentSymbol = nullptr;
3033 CurrentType = nullptr;
3034
3036 CurrentType = Reader->createType();
3037 CurrentType->setIsBase();
3038 CurrentType->setTag(dwarf::DW_TAG_base_type);
3039 if (options().getAttributeBase())
3040 CurrentType->setIncludeInPrint();
3041 return CurrentType;
3042 }
3043
3044 switch (Kind) {
3045 // Types.
3046 case TypeLeafKind::LF_ENUMERATE:
3047 CurrentType = Reader->createTypeEnumerator();
3048 CurrentType->setTag(dwarf::DW_TAG_enumerator);
3049 return CurrentType;
3050 case TypeLeafKind::LF_MODIFIER:
3051 CurrentType = Reader->createType();
3052 CurrentType->setIsModifier();
3053 return CurrentType;
3054 case TypeLeafKind::LF_POINTER:
3055 CurrentType = Reader->createType();
3056 CurrentType->setIsPointer();
3057 CurrentType->setName("*");
3058 CurrentType->setTag(dwarf::DW_TAG_pointer_type);
3059 return CurrentType;
3060
3061 // Symbols.
3062 case TypeLeafKind::LF_BCLASS:
3063 case TypeLeafKind::LF_IVBCLASS:
3064 case TypeLeafKind::LF_VBCLASS:
3065 CurrentSymbol = Reader->createSymbol();
3066 CurrentSymbol->setTag(dwarf::DW_TAG_inheritance);
3067 CurrentSymbol->setIsInheritance();
3068 return CurrentSymbol;
3069 case TypeLeafKind::LF_MEMBER:
3070 case TypeLeafKind::LF_STMEMBER:
3071 CurrentSymbol = Reader->createSymbol();
3072 CurrentSymbol->setIsMember();
3073 CurrentSymbol->setTag(dwarf::DW_TAG_member);
3074 return CurrentSymbol;
3075
3076 // Scopes.
3077 case TypeLeafKind::LF_ARRAY:
3078 CurrentScope = Reader->createScopeArray();
3079 CurrentScope->setTag(dwarf::DW_TAG_array_type);
3080 return CurrentScope;
3081 case TypeLeafKind::LF_CLASS:
3082 CurrentScope = Reader->createScopeAggregate();
3083 CurrentScope->setTag(dwarf::DW_TAG_class_type);
3084 CurrentScope->setIsClass();
3085 return CurrentScope;
3086 case TypeLeafKind::LF_ENUM:
3087 CurrentScope = Reader->createScopeEnumeration();
3088 CurrentScope->setTag(dwarf::DW_TAG_enumeration_type);
3089 return CurrentScope;
3090 case TypeLeafKind::LF_METHOD:
3091 case TypeLeafKind::LF_ONEMETHOD:
3092 case TypeLeafKind::LF_PROCEDURE:
3093 CurrentScope = Reader->createScopeFunction();
3094 CurrentScope->setIsSubprogram();
3095 CurrentScope->setTag(dwarf::DW_TAG_subprogram);
3096 return CurrentScope;
3097 case TypeLeafKind::LF_STRUCTURE:
3098 CurrentScope = Reader->createScopeAggregate();
3099 CurrentScope->setIsStructure();
3100 CurrentScope->setTag(dwarf::DW_TAG_structure_type);
3101 return CurrentScope;
3102 case TypeLeafKind::LF_UNION:
3103 CurrentScope = Reader->createScopeAggregate();
3104 CurrentScope->setIsUnion();
3105 CurrentScope->setTag(dwarf::DW_TAG_union_type);
3106 return CurrentScope;
3107 default:
3108 // If '--internal=tag' and '--print=warning' are specified in the command
3109 // line, we record and print each seen 'TypeLeafKind'.
3110 break;
3111 }
3112 return nullptr;
3113}
3114
3116 CurrentScope = nullptr;
3117 CurrentSymbol = nullptr;
3118 CurrentType = nullptr;
3119 switch (Kind) {
3120 // Types.
3121 case SymbolKind::S_UDT:
3122 CurrentType = Reader->createTypeDefinition();
3123 CurrentType->setTag(dwarf::DW_TAG_typedef);
3124 return CurrentType;
3125
3126 // Symbols.
3127 case SymbolKind::S_CONSTANT:
3128 CurrentSymbol = Reader->createSymbol();
3129 CurrentSymbol->setIsConstant();
3130 CurrentSymbol->setTag(dwarf::DW_TAG_constant);
3131 return CurrentSymbol;
3132
3133 case SymbolKind::S_BPREL32:
3134 case SymbolKind::S_REGREL32:
3135 case SymbolKind::S_REGREL32_INDIR:
3136 case SymbolKind::S_GDATA32:
3137 case SymbolKind::S_LDATA32:
3138 case SymbolKind::S_LOCAL:
3139 // During the symbol traversal more information is available to
3140 // determine if the symbol is a parameter or a variable. At this
3141 // stage mark it as variable.
3142 CurrentSymbol = Reader->createSymbol();
3143 CurrentSymbol->setIsVariable();
3144 CurrentSymbol->setTag(dwarf::DW_TAG_variable);
3145 return CurrentSymbol;
3146
3147 // Scopes.
3148 case SymbolKind::S_BLOCK32:
3149 CurrentScope = Reader->createScope();
3150 CurrentScope->setIsLexicalBlock();
3151 CurrentScope->setTag(dwarf::DW_TAG_lexical_block);
3152 return CurrentScope;
3153 case SymbolKind::S_COMPILE2:
3154 case SymbolKind::S_COMPILE3:
3155 CurrentScope = Reader->createScopeCompileUnit();
3156 CurrentScope->setTag(dwarf::DW_TAG_compile_unit);
3157 Reader->setCompileUnit(static_cast<LVScopeCompileUnit *>(CurrentScope));
3158 return CurrentScope;
3159 case SymbolKind::S_INLINESITE:
3160 case SymbolKind::S_INLINESITE2:
3161 CurrentScope = Reader->createScopeFunctionInlined();
3162 CurrentScope->setIsInlinedFunction();
3163 CurrentScope->setTag(dwarf::DW_TAG_inlined_subroutine);
3164 return CurrentScope;
3165 case SymbolKind::S_LPROC32:
3166 case SymbolKind::S_GPROC32:
3167 case SymbolKind::S_LPROC32_ID:
3168 case SymbolKind::S_GPROC32_ID:
3169 case SymbolKind::S_SEPCODE:
3170 case SymbolKind::S_THUNK32:
3171 CurrentScope = Reader->createScopeFunction();
3172 CurrentScope->setIsSubprogram();
3173 CurrentScope->setTag(dwarf::DW_TAG_subprogram);
3174 return CurrentScope;
3175 default:
3176 // If '--internal=tag' and '--print=warning' are specified in the command
3177 // line, we record and print each seen 'SymbolKind'.
3178 break;
3179 }
3180 return nullptr;
3181}
3182
3184 LVElement *Element = Shared->TypeRecords.find(StreamTPI, TI);
3185 if (!Element) {
3186 // We are dealing with a base type or pointer to a base type, which are
3187 // not included explicitly in the CodeView format.
3189 Element = createElement(Kind);
3190 Element->setIsFinalized();
3191 Shared->TypeRecords.add(StreamTPI, (TypeIndex)Kind, Kind, Element);
3192 Element->setOffset(Kind);
3193 return Element;
3194 }
3195 // We are dealing with a pointer to a base type.
3197 Element = createElement(Kind);
3198 Shared->TypeRecords.add(StreamTPI, TI, Kind, Element);
3199 Element->setOffset(TI.getIndex());
3200 Element->setOffsetFromTypeIndex();
3201 return Element;
3202 }
3203
3204 W.printString("** Not implemented. **");
3205 printTypeIndex("TypeIndex", TI, StreamTPI);
3206 W.printString("TypeLeafKind", formatTypeLeafKind(Kind));
3207 return nullptr;
3208 }
3209
3210 Element->setOffset(TI.getIndex());
3211 Element->setOffsetFromTypeIndex();
3212 return Element;
3213}
3214
3215void LVLogicalVisitor::createDataMember(CVMemberRecord &Record, LVScope *Parent,
3218 LLVM_DEBUG({
3219 printTypeIndex("TypeIndex", TI, StreamTPI);
3220 W.printString("TypeName", Name);
3221 });
3222
3223 createElement(Record.Kind);
3224 if (LVSymbol *Symbol = CurrentSymbol) {
3225 Symbol->setName(Name);
3226 if (TI.isNoneType() || TI.isSimple())
3227 Symbol->setType(getElement(StreamTPI, TI));
3228 else {
3229 LazyRandomTypeCollection &Types = types();
3230 CVType CVMemberType = Types.getType(TI);
3231 if (CVMemberType.kind() == LF_BITFIELD) {
3232 if (Error Err = finishVisitation(CVMemberType, TI, Symbol)) {
3233 consumeError(std::move(Err));
3234 return;
3235 }
3236 } else
3237 Symbol->setType(getElement(StreamTPI, TI));
3238 }
3239 Symbol->setAccessibilityCode(Access);
3240 Parent->addElement(Symbol);
3241 }
3242}
3243
3244LVSymbol *LVLogicalVisitor::createParameter(LVElement *Element, StringRef Name,
3245 LVScope *Parent) {
3246 LVSymbol *Parameter = Reader->createSymbol();
3247 Parent->addElement(Parameter);
3248 Parameter->setIsParameter();
3249 Parameter->setTag(dwarf::DW_TAG_formal_parameter);
3250 Parameter->setName(Name);
3251 Parameter->setType(Element);
3252 return Parameter;
3253}
3254
3255LVSymbol *LVLogicalVisitor::createParameter(TypeIndex TI, StringRef Name,
3256 LVScope *Parent) {
3257 return createParameter(getElement(StreamTPI, TI), Name, Parent);
3258}
3259
3260LVType *LVLogicalVisitor::createBaseType(TypeIndex TI, StringRef TypeName) {
3261 TypeLeafKind SimpleKind = (TypeLeafKind)TI.getSimpleKind();
3262 TypeIndex TIR = (TypeIndex)SimpleKind;
3263 LLVM_DEBUG({
3264 printTypeIndex("TypeIndex", TIR, StreamTPI);
3265 W.printString("TypeName", TypeName);
3266 });
3267
3268 if (LVElement *Element = Shared->TypeRecords.find(StreamTPI, TIR))
3269 return static_cast<LVType *>(Element);
3270
3271 if (createElement(TIR, SimpleKind)) {
3272 CurrentType->setName(TypeName);
3274 Reader->getCompileUnit()->addElement(CurrentType);
3275 }
3276 return CurrentType;
3277}
3278
3279LVType *LVLogicalVisitor::createPointerType(TypeIndex TI, StringRef TypeName) {
3280 LLVM_DEBUG({
3281 printTypeIndex("TypeIndex", TI, StreamTPI);
3282 W.printString("TypeName", TypeName);
3283 });
3284
3285 if (LVElement *Element = Shared->TypeRecords.find(StreamTPI, TI))
3286 return static_cast<LVType *>(Element);
3287
3288 LVType *Pointee = createBaseType(TI, TypeName.drop_back(1));
3289 if (createElement(TI, TypeLeafKind::LF_POINTER)) {
3290 CurrentType->setIsFinalized();
3291 CurrentType->setType(Pointee);
3292 Reader->getCompileUnit()->addElement(CurrentType);
3293 }
3294 return CurrentType;
3295}
3296
3297void LVLogicalVisitor::createParents(StringRef ScopedName, LVElement *Element) {
3298 // For the given test case:
3299 //
3300 // struct S { enum E { ... }; };
3301 // S::E V;
3302 //
3303 // 0 | S_LOCAL `V`
3304 // type=0x1004 (S::E), flags = none
3305 // 0x1004 | LF_ENUM `S::E`
3306 // options: has unique name | is nested
3307 // 0x1009 | LF_STRUCTURE `S`
3308 // options: contains nested class
3309 //
3310 // When the local 'V' is processed, its type 'E' is created. But There is
3311 // no direct reference to its parent 'S'. We use the scoped name for 'E',
3312 // to create its parents.
3313
3314 // The input scoped name must have at least parent and nested names.
3315 // Drop the last element name, as it corresponds to the nested type.
3316 LVStringRefs Components = getAllLexicalComponents(ScopedName);
3317 if (Components.size() < 2)
3318 return;
3319 Components.pop_back();
3320
3321 LVStringRefs::size_type FirstNamespace;
3322 LVStringRefs::size_type FirstAggregate;
3323 std::tie(FirstNamespace, FirstAggregate) =
3324 Shared->NamespaceDeduction.find(Components);
3325
3326 LLVM_DEBUG({
3327 W.printString("First Namespace", Components[FirstNamespace]);
3328 W.printString("First NonNamespace", Components[FirstAggregate]);
3329 });
3330
3331 // Create any referenced namespaces.
3332 if (FirstNamespace < FirstAggregate) {
3333 Shared->NamespaceDeduction.get(
3334 LVStringRefs(Components.begin() + FirstNamespace,
3335 Components.begin() + FirstAggregate));
3336 }
3337
3338 // Traverse the enclosing scopes (aggregates) and create them. In the
3339 // case of nested empty aggregates, MSVC does not emit a full record
3340 // description. It emits only the reference record.
3341 LVScope *Aggregate = nullptr;
3342 TypeIndex TIAggregate;
3343 std::string AggregateName = getScopedName(
3344 LVStringRefs(Components.begin(), Components.begin() + FirstAggregate));
3345
3346 // This traversal is executed at least once.
3347 for (LVStringRefs::size_type Index = FirstAggregate;
3348 Index < Components.size(); ++Index) {
3349 AggregateName = getScopedName(LVStringRefs(Components.begin() + Index,
3350 Components.begin() + Index + 1),
3351 AggregateName);
3352 TIAggregate = Shared->ForwardReferences.remap(
3353 Shared->TypeRecords.find(StreamTPI, AggregateName));
3354 Aggregate =
3355 TIAggregate.isNoneType()
3356 ? nullptr
3357 : static_cast<LVScope *>(getElement(StreamTPI, TIAggregate));
3358 }
3359
3360 // Workaround for cases where LF_NESTTYPE is missing for nested templates.
3361 // If we manage to get parent information from the scoped name, we can add
3362 // the nested type without relying on the LF_NESTTYPE.
3363 if (Aggregate && !Element->getIsScopedAlready()) {
3364 Aggregate->addElement(Element);
3365 Element->setIsScopedAlready();
3366 }
3367}
3368
3370 LVScope *Parent) {
3371 LLVM_DEBUG({ printTypeIndex("TypeIndex", TI, StreamTPI); });
3372 TI = Shared->ForwardReferences.remap(TI);
3373 LLVM_DEBUG({ printTypeIndex("TypeIndex Remap", TI, StreamTPI); });
3374
3375 LVElement *Element = Shared->TypeRecords.find(StreamIdx, TI);
3376 if (!Element) {
3377 if (TI.isNoneType() || TI.isSimple()) {
3378 StringRef TypeName = TypeIndex::simpleTypeName(TI);
3379 // If the name ends with "*", create 2 logical types: a pointer and a
3380 // pointee type. TypeIndex is composed of a SympleTypeMode byte followed
3381 // by a SimpleTypeKind byte. The logical pointer will be identified by
3382 // the full TypeIndex value and the pointee by the SimpleTypeKind.
3383 return (TypeName.back() == '*') ? createPointerType(TI, TypeName)
3384 : createBaseType(TI, TypeName);
3385 }
3386
3387 LLVM_DEBUG({ W.printHex("TypeIndex not implemented: ", TI.getIndex()); });
3388 return nullptr;
3389 }
3390
3391 // The element has been finalized.
3392 if (Element->getIsFinalized())
3393 return Element;
3394
3395 // Add the element in case of a given parent.
3396 if (Parent)
3397 Parent->addElement(Element);
3398
3399 // Check for a composite type.
3401 CVType CVRecord = Types.getType(TI);
3402 if (Error Err = finishVisitation(CVRecord, TI, Element)) {
3403 consumeError(std::move(Err));
3404 return nullptr;
3405 }
3406 Element->setIsFinalized();
3407 return Element;
3408}
3409
3411 // Traverse the collected LF_UDT_SRC_LINE records and add the source line
3412 // information to the logical elements.
3413 for (const TypeIndex &Entry : Shared->LineRecords) {
3414 CVType CVRecord = ids().getType(Entry);
3417 const_cast<CVType &>(CVRecord), Line))
3418 consumeError(std::move(Err));
3419 else {
3420 LLVM_DEBUG({
3421 printTypeIndex("UDT", Line.getUDT(), StreamIPI);
3422 printTypeIndex("SourceFile", Line.getSourceFile(), StreamIPI);
3423 W.printNumber("LineNumber", Line.getLineNumber());
3424 });
3425
3426 // The TypeIndex returned by 'getUDT()' must point to an already
3427 // created logical element. If no logical element is found, it means
3428 // the LF_UDT_SRC_LINE is associated with a system TypeIndex.
3429 if (LVElement *Element = Shared->TypeRecords.find(
3430 StreamTPI, Line.getUDT(), /*Create=*/false)) {
3431 Element->setLineNumber(Line.getLineNumber());
3432 Element->setFilenameIndex(
3433 Shared->StringRecords.findIndex(Line.getSourceFile()));
3434 }
3435 }
3436 }
3437}
3438
3440 // Create namespaces.
3441 Shared->NamespaceDeduction.init();
3442}
3443
3444void LVLogicalVisitor::processFiles() { Shared->StringRecords.addFilenames(); }
3445
3447 if (!options().getInternalTag())
3448 return;
3449
3450 unsigned Count = 0;
3451 auto PrintItem = [&](StringRef Name) {
3452 auto NewLine = [&]() {
3453 if (++Count == 4) {
3454 Count = 0;
3455 OS << "\n";
3456 }
3457 };
3458 OS << formatv("{0,20}", Name);
3459 NewLine();
3460 };
3461
3462 OS << "\nTypes:\n";
3463 for (const TypeLeafKind &Kind : Shared->TypeKinds)
3464 PrintItem(formatTypeLeafKind(Kind));
3465 Shared->TypeKinds.clear();
3466
3467 Count = 0;
3468 OS << "\nSymbols:\n";
3469 for (const SymbolKind &Kind : Shared->SymbolKinds)
3471 Shared->SymbolKinds.clear();
3472
3473 OS << "\n";
3474}
3475
3477 LVScope *InlinedFunction,
3479 // Get the parent scope to update the address ranges of the nested
3480 // scope representing the inlined function.
3481 LVAddress ParentLowPC = 0;
3482 LVScope *Parent = InlinedFunction->getParentScope();
3483 if (const LVLocations *Locations = Parent->getRanges()) {
3484 if (!Locations->empty())
3485 ParentLowPC = (*Locations->begin())->getLowerAddress();
3486 }
3487
3488 // For the given inlinesite, get the initial line number and its
3489 // source filename. Update the logical scope representing it.
3490 uint32_t LineNumber = 0;
3492 LVInlineeInfo::iterator Iter = InlineeInfo.find(InlineSite.Inlinee);
3493 if (Iter != InlineeInfo.end()) {
3494 LineNumber = Iter->second.first;
3495 Filename = Iter->second.second;
3496 AbstractFunction->setLineNumber(LineNumber);
3497 // TODO: This part needs additional work in order to set properly the
3498 // correct filename in order to detect changes between filenames.
3499 // AbstractFunction->setFilename(Filename);
3500 }
3501
3502 LLVM_DEBUG({
3503 dbgs() << "inlineSiteAnnotation\n"
3504 << "Abstract: " << AbstractFunction->getName() << "\n"
3505 << "Inlined: " << InlinedFunction->getName() << "\n"
3506 << "Parent: " << Parent->getName() << "\n"
3507 << "Low PC: " << hexValue(ParentLowPC) << "\n";
3508 });
3509
3510 // Get the source lines if requested by command line option.
3511 if (!options().getPrintLines())
3512 return Error::success();
3513
3514 // Limitation: Currently we don't track changes in the FileOffset. The
3515 // side effects are the caller that it is unable to differentiate the
3516 // source filename for the inlined code.
3517 uint64_t CodeOffset = ParentLowPC;
3518 int32_t LineOffset = LineNumber;
3519 uint32_t FileOffset = 0;
3520
3521 auto UpdateClose = [&]() { LLVM_DEBUG({ dbgs() << ("\n"); }); };
3522 auto UpdateCodeOffset = [&](uint32_t Delta) {
3523 CodeOffset += Delta;
3524 LLVM_DEBUG({
3525 dbgs() << formatv(" code 0x{0} (+0x{1})", utohexstr(CodeOffset),
3526 utohexstr(Delta));
3527 });
3528 };
3529 auto UpdateLineOffset = [&](int32_t Delta) {
3530 LineOffset += Delta;
3531 LLVM_DEBUG({
3532 char Sign = Delta > 0 ? '+' : '-';
3533 dbgs() << formatv(" line {0} ({1}{2})", LineOffset, Sign,
3534 std::abs(Delta));
3535 });
3536 };
3537 auto UpdateFileOffset = [&](int32_t Offset) {
3538 FileOffset = Offset;
3539 LLVM_DEBUG({ dbgs() << formatv(" file {0}", FileOffset); });
3540 };
3541
3543 auto CreateLine = [&]() {
3544 // Create the logical line record.
3545 LVLineDebug *Line = Reader->createLineDebug();
3546 Line->setAddress(CodeOffset);
3547 Line->setLineNumber(LineOffset);
3548 // TODO: This part needs additional work in order to set properly the
3549 // correct filename in order to detect changes between filenames.
3550 // Line->setFilename(Filename);
3551 InlineeLines.push_back(Line);
3552 };
3553
3554 bool SeenLowAddress = false;
3555 bool SeenHighAddress = false;
3556 uint64_t LowPC = 0;
3557 uint64_t HighPC = 0;
3558
3559 for (auto &Annot : InlineSite.annotations()) {
3560 LLVM_DEBUG({
3561 dbgs() << formatv(" {0}",
3562 fmt_align(toHex(Annot.Bytes), AlignStyle::Left, 9));
3563 });
3564
3565 // Use the opcode to interpret the integer values.
3566 switch (Annot.OpCode) {
3570 UpdateCodeOffset(Annot.U1);
3571 UpdateClose();
3572 if (Annot.OpCode == BinaryAnnotationsOpCode::ChangeCodeOffset) {
3573 CreateLine();
3574 LowPC = CodeOffset;
3575 SeenLowAddress = true;
3576 break;
3577 }
3578 if (Annot.OpCode == BinaryAnnotationsOpCode::ChangeCodeLength) {
3579 HighPC = CodeOffset - 1;
3580 SeenHighAddress = true;
3581 }
3582 break;
3584 UpdateCodeOffset(Annot.U2);
3585 UpdateClose();
3586 break;
3589 UpdateCodeOffset(Annot.U1);
3590 UpdateLineOffset(Annot.S1);
3591 UpdateClose();
3592 if (Annot.OpCode ==
3594 CreateLine();
3595 break;
3597 UpdateFileOffset(Annot.U1);
3598 UpdateClose();
3599 break;
3600 default:
3601 break;
3602 }
3603 if (SeenLowAddress && SeenHighAddress) {
3604 SeenLowAddress = false;
3605 SeenHighAddress = false;
3606 InlinedFunction->addObject(LowPC, HighPC);
3607 }
3608 }
3609
3610 Reader->addInlineeLines(InlinedFunction, InlineeLines);
3611 UpdateClose();
3612
3613 return Error::success();
3614}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Lower Kernel Arguments
DXIL Resource Access
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
OptimizedStructLayoutField Field
#define LLVM_DEBUG(...)
Definition Debug.h:114
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Provides read only access to a subclass of BinaryStream.
This is an important base class in LLVM.
Definition Constant.h:43
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
StringRef getName() const
Definition Record.h:1710
void setName(const Init *Name)
Definition Record.cpp:2967
virtual void printString(StringRef Value)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI Value(Type *Ty, unsigned scid)
Definition Value.cpp:53
TypeIndex getElementType() const
Definition TypeRecord.h:405
TypeIndex getIndexType() const
Definition TypeRecord.h:406
uint64_t getSize() const
Definition TypeRecord.h:407
StringRef getName() const
Definition TypeRecord.h:408
@ CurrentDirectory
Absolute CWD path.
Definition TypeRecord.h:678
@ SourceFile
Path to main source file, relative or absolute.
Definition TypeRecord.h:680
ArrayRef< TypeIndex > getArgs() const
Definition TypeRecord.h:674
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition CVRecord.h:29
CompileSym3Flags getFlags() const
SourceLanguage getLanguage() const
Represents a read-only view of a CodeView string table.
LLVM_ABI Expected< StringRef > getString(uint32_t Offset) const
DefRangeFramePointerRelHeader Hdr
std::vector< LocalVariableAddrGap > Gaps
S_DEFRANGE_REGISTER_REL_INDIR.
std::vector< LocalVariableAddrGap > Gaps
DefRangeRegisterRelIndirHeader Hdr
std::vector< LocalVariableAddrGap > Gaps
std::vector< LocalVariableAddrGap > Gaps
std::vector< LocalVariableAddrGap > Gaps
DefRangeSubfieldRegisterHeader Hdr
std::vector< LocalVariableAddrGap > Gaps
std::vector< LocalVariableAddrGap > Gaps
uint32_t getRelocationOffset() const
LocalVariableAddrRange Range
RegisterId getLocalFramePtrReg(CPUType CPU) const
Extract the register this frame uses to refer to local variables.
RegisterId getParamFramePtrReg(CPUType CPU) const
Extract the register this frame uses to refer to parameters.
FrameProcedureOptions Flags
Provides amortized O(1) random access to a CodeView type stream.
LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records together.
Definition TypeRecord.h:914
std::vector< OneMethodRecord > Methods
Definition TypeRecord.h:760
For method overload sets. LF_METHOD.
Definition TypeRecord.h:764
bool isRValueReferenceThisPtr() const
Definition TypeRecord.h:344
TypeIndex getReferentType() const
Definition TypeRecord.h:298
MemberPointerInfo getMemberInfo() const
Definition TypeRecord.h:318
bool isLValueReferenceThisPtr() const
Definition TypeRecord.h:340
PointerMode getMode() const
Definition TypeRecord.h:305
uint32_t getSignature() const
Definition TypeRecord.h:935
StringRef getPrecompFilePath() const
Definition TypeRecord.h:936
uint32_t getTypesCount() const
Definition TypeRecord.h:934
uint32_t getStartTypeIndex() const
Definition TypeRecord.h:933
uint32_t getRelocationOffset() const
TypeIndex getReturnType() const
Definition TypeRecord.h:157
TypeIndex getArgumentList() const
Definition TypeRecord.h:161
uint16_t getParameterCount() const
Definition TypeRecord.h:160
ArrayRef< TypeIndex > getIndices() const
Definition TypeRecord.h:258
TypeIndex getFieldList() const
Definition TypeRecord.h:453
static Error deserializeAs(CVType &CVT, T &Record)
A 32-bit type reference.
Definition TypeIndex.h:97
static TypeIndex fromArrayIndex(uint32_t Index)
Definition TypeIndex.h:124
SimpleTypeKind getSimpleKind() const
Definition TypeIndex.h:137
static TypeIndex None()
Definition TypeIndex.h:149
void setIndex(uint32_t I)
Definition TypeIndex.h:113
static const uint32_t FirstNonSimpleIndex
Definition TypeIndex.h:99
static LLVM_ABI StringRef simpleTypeName(TypeIndex TI)
Definition TypeIndex.cpp:71
uint32_t getIndex() const
Definition TypeIndex.h:112
const GUID & getGuid() const
Definition TypeRecord.h:585
void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks)
virtual Error visitUnknownMember(CVMemberRecord &Record)
virtual Error visitMemberEnd(CVMemberRecord &Record)
virtual Error visitMemberBegin(CVMemberRecord &Record)
TypeIndex getType() const
Definition TypeRecord.h:857
uint32_t getVFPtrOffset() const
Definition TypeRecord.h:705
TypeIndex getOverriddenVTable() const
Definition TypeRecord.h:704
ArrayRef< StringRef > getMethodNames() const
Definition TypeRecord.h:708
StringRef getName() const
Definition TypeRecord.h:706
TypeIndex getCompleteClass() const
Definition TypeRecord.h:703
Stores all information relating to a compile unit, be it in its original instance in the object file ...
static StringRef getSymbolKindName(SymbolKind Kind)
virtual void setCount(int64_t Value)
Definition LVElement.h:260
virtual void setBitSize(uint32_t Size)
Definition LVElement.h:257
LVScope * getFunctionParent() const
virtual void updateLevel(LVScope *Parent, bool Moved=false)
virtual int64_t getCount() const
Definition LVElement.h:259
void setInlineCode(uint32_t Code)
Definition LVElement.h:292
virtual void setReference(LVElement *Element)
Definition LVElement.h:231
void setName(StringRef ElementName) override
Definition LVElement.cpp:95
StringRef getName() const override
Definition LVElement.h:192
void setType(LVElement *Element=nullptr)
Definition LVElement.h:315
void setFilenameIndex(size_t Index)
Definition LVElement.h:245
Error visitKnownRecord(CVType &Record, ArgListRecord &Args, TypeIndex TI, LVElement *Element)
void printRecords(raw_ostream &OS) const
Error visitMemberRecord(CVMemberRecord &Record, TypeVisitorCallbacks &Callbacks, TypeIndex TI, LVElement *Element)
Error visitKnownMember(CVMemberRecord &Record, BaseClassRecord &Base, TypeIndex TI, LVElement *Element)
void printMemberEnd(CVMemberRecord &Record)
Error inlineSiteAnnotation(LVScope *AbstractFunction, LVScope *InlinedFunction, InlineSiteSym &InlineSite)
LVLogicalVisitor(LVCodeViewReader *Reader, ScopedPrinter &W, llvm::pdb::InputFile &Input)
void printTypeIndex(StringRef FieldName, TypeIndex TI, uint32_t StreamIdx)
Error visitUnknownMember(CVMemberRecord &Record, TypeIndex TI)
Error visitUnknownType(CVType &Record, TypeIndex TI)
void addElement(LVScope *Scope, bool IsCompileUnit)
void printTypeBegin(CVType &Record, TypeIndex TI, LVElement *Element, uint32_t StreamIdx)
LVElement * getElement(uint32_t StreamIdx, TypeIndex TI, LVScope *Parent=nullptr)
void printMemberBegin(CVMemberRecord &Record, TypeIndex TI, LVElement *Element, uint32_t StreamIdx)
Error finishVisitation(CVType &Record, TypeIndex TI, LVElement *Element)
LVElement * createElement(TypeLeafKind Kind)
LVScope * getParentScope() const
Definition LVObject.h:255
void setOffset(LVOffset DieOffset)
Definition LVObject.h:241
LVOffset getOffset() const
Definition LVObject.h:240
void setLineNumber(uint32_t Number)
Definition LVObject.h:275
void setTag(dwarf::Tag Tag)
Definition LVObject.h:233
virtual bool isSystemEntry(LVElement *Element, StringRef Name={}) const
Definition LVReader.h:302
LVScopeCompileUnit * getCompileUnit() const
Definition LVReader.h:273
void addElement(LVElement *Element)
Definition LVScope.cpp:122
void addObject(LVLocation *Location)
Definition LVScope.cpp:161
const LVLocations * getRanges() const
Definition LVScope.h:209
void getLinkageName(uint32_t RelocOffset, uint32_t Offset, StringRef *RelocSym=nullptr)
void printRelocatedField(StringRef Label, uint32_t RelocOffset, uint32_t Offset, StringRef *RelocSym=nullptr)
DebugStringTableSubsectionRef getStringTable() override
StringRef getFileNameForFileOffset(uint32_t FileOffset) override
Error visitSymbolEnd(CVSymbol &Record) override
Error visitKnownRecord(CVSymbol &Record, BlockSym &Block) override
Error visitSymbolBegin(CVSymbol &Record) override
Error visitUnknownSymbol(CVSymbol &Record) override
Action to take on unknown symbols. By default, they are ignored.
Error visitMemberEnd(CVMemberRecord &Record) override
Error visitUnknownMember(CVMemberRecord &Record) override
Error visitTypeBegin(CVType &Record) override
Paired begin/end actions for all types.
Error visitMemberBegin(CVMemberRecord &Record) override
Error visitKnownRecord(CVType &Record, BuildInfoRecord &Args) override
Error visitUnknownType(CVType &Record) override
Action to take on unknown types. By default, they are ignored.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
@ Entry
Definition COFF.h:862
PointerMode
Equivalent to CV_ptrmode_e.
Definition CodeView.h:335
MethodKind
Part of member attribute flags. (CV_methodprop_e)
Definition CodeView.h:252
CVRecord< TypeLeafKind > CVType
Definition CVRecord.h:64
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn....
Definition CodeView.h:76
CVRecord< SymbolKind > CVSymbol
Definition CVRecord.h:65
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getJumpTableEntrySizeNames()
bool symbolEndsScope(SymbolKind Kind)
Return true if this ssymbol ends a scope.
MethodOptions
Equivalent to CV_fldattr_t bitfield.
Definition CodeView.h:263
LLVM_ABI ArrayRef< EnumEntry< SymbolKind > > getSymbolTypeNames()
MemberAccess
Source-level access specifier. (CV_access_e)
Definition CodeView.h:244
bool symbolOpensScope(SymbolKind Kind)
Return true if this symbol opens a scope.
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition CodeView.h:34
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getLocalFlagNames()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getRegisterNames(CPUType Cpu)
bool isAggregate(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getProcSymFlagNames()
TypeRecordKind
Distinguishes individual records in .debug$T or .debug$P section or PDB type stream.
Definition CodeView.h:27
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition CodeView.h:48
LLVM_ABI uint64_t getSizeInBytesForTypeRecord(CVType CVT)
Given an arbitrary codeview type, return the type's size in the case of aggregate (LF_STRUCTURE,...
LLVM_ABI ArrayRef< EnumEntry< unsigned > > getCPUTypeNames()
LLVM_ABI ArrayRef< EnumEntry< SourceLanguage > > getSourceLanguageNames()
LLVM_ABI uint64_t getSizeInBytesForTypeIndex(TypeIndex TI)
Given an arbitrary codeview type index, determine its size.
LLVM_ABI TypeIndex getModifiedType(const CVType &CVT)
Given a CVType which is assumed to be an LF_MODIFIER, return the TypeIndex of the type that the LF_MO...
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration in the Microsoft Debug Interface Access SDK,...
Definition CodeView.h:146
LLVM_ABI ArrayRef< EnumEntry< uint32_t > > getCompileSym3FlagNames()
LLVM_ABI void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, TypeIndex TI, TypeCollection &Types)
Definition TypeIndex.cpp:93
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
Definition StringPool.h:23
@ DW_INL_inlined
Definition Dwarf.h:777
@ DW_INL_declared_inlined
Definition Dwarf.h:779
Attribute
Attributes.
Definition Dwarf.h:125
constexpr Tag DW_TAG_unaligned
Definition LVObject.h:28
FormattedNumber hexValue(uint64_t N, unsigned Width=HEX_WIDTH, bool Upper=false)
Definition LVSupport.h:123
LVReader & getReader()
Definition LVReader.h:360
static TypeIndex getTrueType(TypeIndex &TI)
std::vector< TypeIndex > LVLineRecords
std::set< SymbolKind > LVSymbolKinds
static StringRef getRecordName(LazyRandomTypeCollection &Types, TypeIndex TI)
constexpr unsigned int DWARF_CHAR_BIT
Definition LVElement.h:73
LLVM_ABI LVStringRefs getAllLexicalComponents(StringRef Name)
std::vector< StringRef > LVStringRefs
Definition LVSupport.h:35
LLVM_ABI std::string transformPath(StringRef Path)
Definition LVSupport.cpp:31
LLVM_ABI LVLexicalComponent getInnerComponent(StringRef Name)
static const EnumEntry< TypeLeafKind > LeafTypeNames[]
std::tuple< LVStringRefs::size_type, LVStringRefs::size_type > LVLexicalIndex
Definition LVSupport.h:37
uint8_t LVSmall
Definition LVObject.h:42
std::set< TypeLeafKind > LVTypeKinds
SmallVector< LVLine *, 8 > LVLines
Definition LVObject.h:77
uint64_t LVAddress
Definition LVObject.h:36
LVOptions & options()
Definition LVOptions.h:448
LLVM_ABI std::string getScopedName(const LVStringRefs &Components, StringRef BaseName={})
SmallVector< LVLocation *, 8 > LVLocations
Definition LVObject.h:78
@ Parameter
An inlay hint that is for a parameter.
Definition Protocol.h:1147
LLVM_ABI std::string formatTypeLeafKind(codeview::TypeLeafKind K)
Print(const T &, const DataFlowGraph &) -> Print< T >
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1765
std::tuple< uint64_t, uint32_t > InlineSite
LLVM_GET_TYPE_NAME_CONSTEXPR StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
Definition TypeName.h:40
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
support::detail::RepeatAdapter< T > fmt_repeat(T &&Item, size_t Count)
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
support::detail::AlignAdapter< T > fmt_align(T &&Item, AlignStyle Where, size_t Amount, char Fill=' ')
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2192
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
DEMANGLE_ABI std::string demangle(std::string_view MangledName)
Attempt to demangle a string using different demangling schemes.
Definition Demangle.cpp:20
#define N
little32_t OffsetInUdt
Offset to add after dereferencing Register + BasePointerOffset.
LVShared(LVCodeViewReader *Reader, LVLogicalVisitor *Visitor)
LVNamespaceDeduction NamespaceDeduction
LVForwardReferences ForwardReferences
A source language supported by any of the debug info representations.