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