xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- TypeDumpVisitor.cpp - CodeView type info dumper ----------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
10 
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
13 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
14 #include "llvm/DebugInfo/CodeView/TypeCollection.h"
15 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
16 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
17 #include "llvm/Support/FormatVariadic.h"
18 #include "llvm/Support/ScopedPrinter.h"
19 #include "llvm/Support/raw_ostream.h"
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 
24 static const EnumEntry<TypeLeafKind> LeafTypeNames[] = {
25 #define CV_TYPE(enum, val) {#enum, enum},
26 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
27 };
28 
29 #define ENUM_ENTRY(enum_class, enum)                                           \
30   { #enum, std::underlying_type_t<enum_class>(enum_class::enum) }
31 
32 static const EnumEntry<uint16_t> ClassOptionNames[] = {
33     ENUM_ENTRY(ClassOptions, Packed),
34     ENUM_ENTRY(ClassOptions, HasConstructorOrDestructor),
35     ENUM_ENTRY(ClassOptions, HasOverloadedOperator),
36     ENUM_ENTRY(ClassOptions, Nested),
37     ENUM_ENTRY(ClassOptions, ContainsNestedClass),
38     ENUM_ENTRY(ClassOptions, HasOverloadedAssignmentOperator),
39     ENUM_ENTRY(ClassOptions, HasConversionOperator),
40     ENUM_ENTRY(ClassOptions, ForwardReference),
41     ENUM_ENTRY(ClassOptions, Scoped),
42     ENUM_ENTRY(ClassOptions, HasUniqueName),
43     ENUM_ENTRY(ClassOptions, Sealed),
44     ENUM_ENTRY(ClassOptions, Intrinsic),
45 };
46 
47 static const EnumEntry<uint8_t> MemberAccessNames[] = {
48     ENUM_ENTRY(MemberAccess, None), ENUM_ENTRY(MemberAccess, Private),
49     ENUM_ENTRY(MemberAccess, Protected), ENUM_ENTRY(MemberAccess, Public),
50 };
51 
52 static const EnumEntry<uint16_t> MethodOptionNames[] = {
53     ENUM_ENTRY(MethodOptions, Pseudo),
54     ENUM_ENTRY(MethodOptions, NoInherit),
55     ENUM_ENTRY(MethodOptions, NoConstruct),
56     ENUM_ENTRY(MethodOptions, CompilerGenerated),
57     ENUM_ENTRY(MethodOptions, Sealed),
58 };
59 
60 static const EnumEntry<uint16_t> MemberKindNames[] = {
61     ENUM_ENTRY(MethodKind, Vanilla),
62     ENUM_ENTRY(MethodKind, Virtual),
63     ENUM_ENTRY(MethodKind, Static),
64     ENUM_ENTRY(MethodKind, Friend),
65     ENUM_ENTRY(MethodKind, IntroducingVirtual),
66     ENUM_ENTRY(MethodKind, PureVirtual),
67     ENUM_ENTRY(MethodKind, PureIntroducingVirtual),
68 };
69 
70 static const EnumEntry<uint8_t> PtrKindNames[] = {
71     ENUM_ENTRY(PointerKind, Near16),
72     ENUM_ENTRY(PointerKind, Far16),
73     ENUM_ENTRY(PointerKind, Huge16),
74     ENUM_ENTRY(PointerKind, BasedOnSegment),
75     ENUM_ENTRY(PointerKind, BasedOnValue),
76     ENUM_ENTRY(PointerKind, BasedOnSegmentValue),
77     ENUM_ENTRY(PointerKind, BasedOnAddress),
78     ENUM_ENTRY(PointerKind, BasedOnSegmentAddress),
79     ENUM_ENTRY(PointerKind, BasedOnType),
80     ENUM_ENTRY(PointerKind, BasedOnSelf),
81     ENUM_ENTRY(PointerKind, Near32),
82     ENUM_ENTRY(PointerKind, Far32),
83     ENUM_ENTRY(PointerKind, Near64),
84 };
85 
86 static const EnumEntry<uint8_t> PtrModeNames[] = {
87     ENUM_ENTRY(PointerMode, Pointer),
88     ENUM_ENTRY(PointerMode, LValueReference),
89     ENUM_ENTRY(PointerMode, PointerToDataMember),
90     ENUM_ENTRY(PointerMode, PointerToMemberFunction),
91     ENUM_ENTRY(PointerMode, RValueReference),
92 };
93 
94 static const EnumEntry<uint16_t> PtrMemberRepNames[] = {
95     ENUM_ENTRY(PointerToMemberRepresentation, Unknown),
96     ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceData),
97     ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceData),
98     ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceData),
99     ENUM_ENTRY(PointerToMemberRepresentation, GeneralData),
100     ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceFunction),
101     ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceFunction),
102     ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceFunction),
103     ENUM_ENTRY(PointerToMemberRepresentation, GeneralFunction),
104 };
105 
106 static const EnumEntry<uint16_t> TypeModifierNames[] = {
107     ENUM_ENTRY(ModifierOptions, Const), ENUM_ENTRY(ModifierOptions, Volatile),
108     ENUM_ENTRY(ModifierOptions, Unaligned),
109 };
110 
111 static const EnumEntry<uint8_t> CallingConventions[] = {
112     ENUM_ENTRY(CallingConvention, NearC),
113     ENUM_ENTRY(CallingConvention, FarC),
114     ENUM_ENTRY(CallingConvention, NearPascal),
115     ENUM_ENTRY(CallingConvention, FarPascal),
116     ENUM_ENTRY(CallingConvention, NearFast),
117     ENUM_ENTRY(CallingConvention, FarFast),
118     ENUM_ENTRY(CallingConvention, NearStdCall),
119     ENUM_ENTRY(CallingConvention, FarStdCall),
120     ENUM_ENTRY(CallingConvention, NearSysCall),
121     ENUM_ENTRY(CallingConvention, FarSysCall),
122     ENUM_ENTRY(CallingConvention, ThisCall),
123     ENUM_ENTRY(CallingConvention, MipsCall),
124     ENUM_ENTRY(CallingConvention, Generic),
125     ENUM_ENTRY(CallingConvention, AlphaCall),
126     ENUM_ENTRY(CallingConvention, PpcCall),
127     ENUM_ENTRY(CallingConvention, SHCall),
128     ENUM_ENTRY(CallingConvention, ArmCall),
129     ENUM_ENTRY(CallingConvention, AM33Call),
130     ENUM_ENTRY(CallingConvention, TriCall),
131     ENUM_ENTRY(CallingConvention, SH5Call),
132     ENUM_ENTRY(CallingConvention, M32RCall),
133     ENUM_ENTRY(CallingConvention, ClrCall),
134     ENUM_ENTRY(CallingConvention, Inline),
135     ENUM_ENTRY(CallingConvention, NearVector),
136     ENUM_ENTRY(CallingConvention, Swift),
137 };
138 
139 static const EnumEntry<uint8_t> FunctionOptionEnum[] = {
140     ENUM_ENTRY(FunctionOptions, CxxReturnUdt),
141     ENUM_ENTRY(FunctionOptions, Constructor),
142     ENUM_ENTRY(FunctionOptions, ConstructorWithVirtualBases),
143 };
144 
145 static const EnumEntry<uint16_t> LabelTypeEnum[] = {
146     ENUM_ENTRY(LabelType, Near), ENUM_ENTRY(LabelType, Far),
147 };
148 
149 #undef ENUM_ENTRY
150 
getLeafTypeName(TypeLeafKind LT)151 static StringRef getLeafTypeName(TypeLeafKind LT) {
152   switch (LT) {
153 #define TYPE_RECORD(ename, value, name)                                        \
154   case ename:                                                                  \
155     return #name;
156 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
157   default:
158     break;
159   }
160   return "UnknownLeaf";
161 }
162 
printTypeIndex(StringRef FieldName,TypeIndex TI) const163 void TypeDumpVisitor::printTypeIndex(StringRef FieldName, TypeIndex TI) const {
164   codeview::printTypeIndex(*W, FieldName, TI, TpiTypes);
165 }
166 
printItemIndex(StringRef FieldName,TypeIndex TI) const167 void TypeDumpVisitor::printItemIndex(StringRef FieldName, TypeIndex TI) const {
168   codeview::printTypeIndex(*W, FieldName, TI, getSourceTypes());
169 }
170 
visitTypeBegin(CVType & Record)171 Error TypeDumpVisitor::visitTypeBegin(CVType &Record) {
172   return visitTypeBegin(Record, TypeIndex::fromArrayIndex(TpiTypes.size()));
173 }
174 
visitTypeBegin(CVType & Record,TypeIndex Index)175 Error TypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) {
176   W->startLine() << getLeafTypeName(Record.kind());
177   W->getOStream() << " (" << HexNumber(Index.getIndex()) << ")";
178   W->getOStream() << " {\n";
179   W->indent();
180   W->printEnum("TypeLeafKind", unsigned(Record.kind()),
181                ArrayRef(LeafTypeNames));
182   return Error::success();
183 }
184 
visitTypeEnd(CVType & Record)185 Error TypeDumpVisitor::visitTypeEnd(CVType &Record) {
186   if (PrintRecordBytes)
187     W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.content()));
188 
189   W->unindent();
190   W->startLine() << "}\n";
191   return Error::success();
192 }
193 
visitMemberBegin(CVMemberRecord & Record)194 Error TypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) {
195   W->startLine() << getLeafTypeName(Record.Kind);
196   W->getOStream() << " {\n";
197   W->indent();
198   W->printEnum("TypeLeafKind", unsigned(Record.Kind), ArrayRef(LeafTypeNames));
199   return Error::success();
200 }
201 
visitMemberEnd(CVMemberRecord & Record)202 Error TypeDumpVisitor::visitMemberEnd(CVMemberRecord &Record) {
203   if (PrintRecordBytes)
204     W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.Data));
205 
206   W->unindent();
207   W->startLine() << "}\n";
208   return Error::success();
209 }
210 
visitKnownRecord(CVType & CVR,FieldListRecord & FieldList)211 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
212                                         FieldListRecord &FieldList) {
213   if (auto EC = codeview::visitMemberRecordStream(FieldList.Data, *this))
214     return EC;
215 
216   return Error::success();
217 }
218 
visitKnownRecord(CVType & CVR,StringIdRecord & String)219 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringIdRecord &String) {
220   printItemIndex("Id", String.getId());
221   W->printString("StringData", String.getString());
222   return Error::success();
223 }
224 
visitKnownRecord(CVType & CVR,ArgListRecord & Args)225 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArgListRecord &Args) {
226   auto Indices = Args.getIndices();
227   uint32_t Size = Indices.size();
228   W->printNumber("NumArgs", Size);
229   ListScope Arguments(*W, "Arguments");
230   for (uint32_t I = 0; I < Size; ++I) {
231     printTypeIndex("ArgType", Indices[I]);
232   }
233   return Error::success();
234 }
235 
visitKnownRecord(CVType & CVR,StringListRecord & Strs)236 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringListRecord &Strs) {
237   auto Indices = Strs.getIndices();
238   uint32_t Size = Indices.size();
239   W->printNumber("NumStrings", Size);
240   ListScope Arguments(*W, "Strings");
241   for (uint32_t I = 0; I < Size; ++I) {
242     printItemIndex("String", Indices[I]);
243   }
244   return Error::success();
245 }
246 
visitKnownRecord(CVType & CVR,ClassRecord & Class)247 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) {
248   uint16_t Props = static_cast<uint16_t>(Class.getOptions());
249   W->printNumber("MemberCount", Class.getMemberCount());
250   W->printFlags("Properties", Props, ArrayRef(ClassOptionNames));
251   printTypeIndex("FieldList", Class.getFieldList());
252   printTypeIndex("DerivedFrom", Class.getDerivationList());
253   printTypeIndex("VShape", Class.getVTableShape());
254   W->printNumber("SizeOf", Class.getSize());
255   W->printString("Name", Class.getName());
256   if (Props & uint16_t(ClassOptions::HasUniqueName))
257     W->printString("LinkageName", Class.getUniqueName());
258   return Error::success();
259 }
260 
visitKnownRecord(CVType & CVR,UnionRecord & Union)261 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, UnionRecord &Union) {
262   uint16_t Props = static_cast<uint16_t>(Union.getOptions());
263   W->printNumber("MemberCount", Union.getMemberCount());
264   W->printFlags("Properties", Props, ArrayRef(ClassOptionNames));
265   printTypeIndex("FieldList", Union.getFieldList());
266   W->printNumber("SizeOf", Union.getSize());
267   W->printString("Name", Union.getName());
268   if (Props & uint16_t(ClassOptions::HasUniqueName))
269     W->printString("LinkageName", Union.getUniqueName());
270   return Error::success();
271 }
272 
visitKnownRecord(CVType & CVR,EnumRecord & Enum)273 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) {
274   uint16_t Props = static_cast<uint16_t>(Enum.getOptions());
275   W->printNumber("NumEnumerators", Enum.getMemberCount());
276   W->printFlags("Properties", uint16_t(Enum.getOptions()),
277                 ArrayRef(ClassOptionNames));
278   printTypeIndex("UnderlyingType", Enum.getUnderlyingType());
279   printTypeIndex("FieldListType", Enum.getFieldList());
280   W->printString("Name", Enum.getName());
281   if (Props & uint16_t(ClassOptions::HasUniqueName))
282     W->printString("LinkageName", Enum.getUniqueName());
283   return Error::success();
284 }
285 
visitKnownRecord(CVType & CVR,ArrayRecord & AT)286 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArrayRecord &AT) {
287   printTypeIndex("ElementType", AT.getElementType());
288   printTypeIndex("IndexType", AT.getIndexType());
289   W->printNumber("SizeOf", AT.getSize());
290   W->printString("Name", AT.getName());
291   return Error::success();
292 }
293 
visitKnownRecord(CVType & CVR,VFTableRecord & VFT)294 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) {
295   printTypeIndex("CompleteClass", VFT.getCompleteClass());
296   printTypeIndex("OverriddenVFTable", VFT.getOverriddenVTable());
297   W->printHex("VFPtrOffset", VFT.getVFPtrOffset());
298   W->printString("VFTableName", VFT.getName());
299   for (auto N : VFT.getMethodNames())
300     W->printString("MethodName", N);
301   return Error::success();
302 }
303 
visitKnownRecord(CVType & CVR,MemberFuncIdRecord & Id)304 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) {
305   printTypeIndex("ClassType", Id.getClassType());
306   printTypeIndex("FunctionType", Id.getFunctionType());
307   W->printString("Name", Id.getName());
308   return Error::success();
309 }
310 
visitKnownRecord(CVType & CVR,ProcedureRecord & Proc)311 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) {
312   printTypeIndex("ReturnType", Proc.getReturnType());
313   W->printEnum("CallingConvention", uint8_t(Proc.getCallConv()),
314                ArrayRef(CallingConventions));
315   W->printFlags("FunctionOptions", uint8_t(Proc.getOptions()),
316                 ArrayRef(FunctionOptionEnum));
317   W->printNumber("NumParameters", Proc.getParameterCount());
318   printTypeIndex("ArgListType", Proc.getArgumentList());
319   return Error::success();
320 }
321 
visitKnownRecord(CVType & CVR,MemberFunctionRecord & MF)322 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFunctionRecord &MF) {
323   printTypeIndex("ReturnType", MF.getReturnType());
324   printTypeIndex("ClassType", MF.getClassType());
325   printTypeIndex("ThisType", MF.getThisType());
326   W->printEnum("CallingConvention", uint8_t(MF.getCallConv()),
327                ArrayRef(CallingConventions));
328   W->printFlags("FunctionOptions", uint8_t(MF.getOptions()),
329                 ArrayRef(FunctionOptionEnum));
330   W->printNumber("NumParameters", MF.getParameterCount());
331   printTypeIndex("ArgListType", MF.getArgumentList());
332   W->printNumber("ThisAdjustment", MF.getThisPointerAdjustment());
333   return Error::success();
334 }
335 
visitKnownRecord(CVType & CVR,MethodOverloadListRecord & MethodList)336 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
337                                         MethodOverloadListRecord &MethodList) {
338   for (const auto &M : MethodList.getMethods()) {
339     ListScope S(*W, "Method");
340     printMemberAttributes(M.getAccess(), M.getMethodKind(), M.getOptions());
341     printTypeIndex("Type", M.getType());
342     if (M.isIntroducingVirtual())
343       W->printHex("VFTableOffset", M.getVFTableOffset());
344   }
345   return Error::success();
346 }
347 
visitKnownRecord(CVType & CVR,FuncIdRecord & Func)348 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) {
349   printItemIndex("ParentScope", Func.getParentScope());
350   printTypeIndex("FunctionType", Func.getFunctionType());
351   W->printString("Name", Func.getName());
352   return Error::success();
353 }
354 
visitKnownRecord(CVType & CVR,TypeServer2Record & TS)355 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) {
356   W->printString("Guid", formatv("{0}", TS.getGuid()).str());
357   W->printNumber("Age", TS.getAge());
358   W->printString("Name", TS.getName());
359   return Error::success();
360 }
361 
visitKnownRecord(CVType & CVR,PointerRecord & Ptr)362 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) {
363   printTypeIndex("PointeeType", Ptr.getReferentType());
364   W->printEnum("PtrType", unsigned(Ptr.getPointerKind()),
365                ArrayRef(PtrKindNames));
366   W->printEnum("PtrMode", unsigned(Ptr.getMode()), ArrayRef(PtrModeNames));
367 
368   W->printNumber("IsFlat", Ptr.isFlat());
369   W->printNumber("IsConst", Ptr.isConst());
370   W->printNumber("IsVolatile", Ptr.isVolatile());
371   W->printNumber("IsUnaligned", Ptr.isUnaligned());
372   W->printNumber("IsRestrict", Ptr.isRestrict());
373   W->printNumber("IsThisPtr&", Ptr.isLValueReferenceThisPtr());
374   W->printNumber("IsThisPtr&&", Ptr.isRValueReferenceThisPtr());
375   W->printNumber("SizeOf", Ptr.getSize());
376 
377   if (Ptr.isPointerToMember()) {
378     const MemberPointerInfo &MI = Ptr.getMemberInfo();
379 
380     printTypeIndex("ClassType", MI.getContainingType());
381     W->printEnum("Representation", uint16_t(MI.getRepresentation()),
382                  ArrayRef(PtrMemberRepNames));
383   }
384 
385   return Error::success();
386 }
387 
visitKnownRecord(CVType & CVR,ModifierRecord & Mod)388 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) {
389   uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers());
390   printTypeIndex("ModifiedType", Mod.getModifiedType());
391   W->printFlags("Modifiers", Mods, ArrayRef(TypeModifierNames));
392 
393   return Error::success();
394 }
395 
visitKnownRecord(CVType & CVR,BitFieldRecord & BitField)396 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BitFieldRecord &BitField) {
397   printTypeIndex("Type", BitField.getType());
398   W->printNumber("BitSize", BitField.getBitSize());
399   W->printNumber("BitOffset", BitField.getBitOffset());
400   return Error::success();
401 }
402 
visitKnownRecord(CVType & CVR,VFTableShapeRecord & Shape)403 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
404                                         VFTableShapeRecord &Shape) {
405   W->printNumber("VFEntryCount", Shape.getEntryCount());
406   return Error::success();
407 }
408 
visitKnownRecord(CVType & CVR,UdtSourceLineRecord & Line)409 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
410                                         UdtSourceLineRecord &Line) {
411   printTypeIndex("UDT", Line.getUDT());
412   printItemIndex("SourceFile", Line.getSourceFile());
413   W->printNumber("LineNumber", Line.getLineNumber());
414   return Error::success();
415 }
416 
visitKnownRecord(CVType & CVR,UdtModSourceLineRecord & Line)417 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
418                                         UdtModSourceLineRecord &Line) {
419   printTypeIndex("UDT", Line.getUDT());
420   printItemIndex("SourceFile", Line.getSourceFile());
421   W->printNumber("LineNumber", Line.getLineNumber());
422   W->printNumber("Module", Line.getModule());
423   return Error::success();
424 }
425 
visitKnownRecord(CVType & CVR,BuildInfoRecord & Args)426 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BuildInfoRecord &Args) {
427   W->printNumber("NumArgs", static_cast<uint32_t>(Args.getArgs().size()));
428 
429   ListScope Arguments(*W, "Arguments");
430   for (auto Arg : Args.getArgs()) {
431     printItemIndex("ArgType", Arg);
432   }
433   return Error::success();
434 }
435 
printMemberAttributes(MemberAttributes Attrs)436 void TypeDumpVisitor::printMemberAttributes(MemberAttributes Attrs) {
437   return printMemberAttributes(Attrs.getAccess(), Attrs.getMethodKind(),
438                                Attrs.getFlags());
439 }
440 
printMemberAttributes(MemberAccess Access,MethodKind Kind,MethodOptions Options)441 void TypeDumpVisitor::printMemberAttributes(MemberAccess Access,
442                                             MethodKind Kind,
443                                             MethodOptions Options) {
444   W->printEnum("AccessSpecifier", uint8_t(Access), ArrayRef(MemberAccessNames));
445   // Data members will be vanilla. Don't try to print a method kind for them.
446   if (Kind != MethodKind::Vanilla)
447     W->printEnum("MethodKind", unsigned(Kind), ArrayRef(MemberKindNames));
448   if (Options != MethodOptions::None) {
449     W->printFlags("MethodOptions", unsigned(Options),
450                   ArrayRef(MethodOptionNames));
451   }
452 }
453 
visitUnknownMember(CVMemberRecord & Record)454 Error TypeDumpVisitor::visitUnknownMember(CVMemberRecord &Record) {
455   W->printHex("UnknownMember", unsigned(Record.Kind));
456   return Error::success();
457 }
458 
visitUnknownType(CVType & Record)459 Error TypeDumpVisitor::visitUnknownType(CVType &Record) {
460   W->printEnum("Kind", uint16_t(Record.kind()), ArrayRef(LeafTypeNames));
461   W->printNumber("Length", uint32_t(Record.content().size()));
462   return Error::success();
463 }
464 
visitKnownMember(CVMemberRecord & CVR,NestedTypeRecord & Nested)465 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
466                                         NestedTypeRecord &Nested) {
467   printTypeIndex("Type", Nested.getNestedType());
468   W->printString("Name", Nested.getName());
469   return Error::success();
470 }
471 
visitKnownMember(CVMemberRecord & CVR,OneMethodRecord & Method)472 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
473                                         OneMethodRecord &Method) {
474   MethodKind K = Method.getMethodKind();
475   printMemberAttributes(Method.getAccess(), K, Method.getOptions());
476   printTypeIndex("Type", Method.getType());
477   // If virtual, then read the vftable offset.
478   if (Method.isIntroducingVirtual())
479     W->printHex("VFTableOffset", Method.getVFTableOffset());
480   W->printString("Name", Method.getName());
481   return Error::success();
482 }
483 
visitKnownMember(CVMemberRecord & CVR,OverloadedMethodRecord & Method)484 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
485                                         OverloadedMethodRecord &Method) {
486   W->printHex("MethodCount", Method.getNumOverloads());
487   printTypeIndex("MethodListIndex", Method.getMethodList());
488   W->printString("Name", Method.getName());
489   return Error::success();
490 }
491 
visitKnownMember(CVMemberRecord & CVR,DataMemberRecord & Field)492 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
493                                         DataMemberRecord &Field) {
494   printMemberAttributes(Field.getAccess(), MethodKind::Vanilla,
495                         MethodOptions::None);
496   printTypeIndex("Type", Field.getType());
497   W->printHex("FieldOffset", Field.getFieldOffset());
498   W->printString("Name", Field.getName());
499   return Error::success();
500 }
501 
visitKnownMember(CVMemberRecord & CVR,StaticDataMemberRecord & Field)502 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
503                                         StaticDataMemberRecord &Field) {
504   printMemberAttributes(Field.getAccess(), MethodKind::Vanilla,
505                         MethodOptions::None);
506   printTypeIndex("Type", Field.getType());
507   W->printString("Name", Field.getName());
508   return Error::success();
509 }
510 
visitKnownMember(CVMemberRecord & CVR,VFPtrRecord & VFTable)511 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
512                                         VFPtrRecord &VFTable) {
513   printTypeIndex("Type", VFTable.getType());
514   return Error::success();
515 }
516 
visitKnownMember(CVMemberRecord & CVR,EnumeratorRecord & Enum)517 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
518                                         EnumeratorRecord &Enum) {
519   printMemberAttributes(Enum.getAccess(), MethodKind::Vanilla,
520                         MethodOptions::None);
521   W->printNumber("EnumValue", Enum.getValue());
522   W->printString("Name", Enum.getName());
523   return Error::success();
524 }
525 
visitKnownMember(CVMemberRecord & CVR,BaseClassRecord & Base)526 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
527                                         BaseClassRecord &Base) {
528   printMemberAttributes(Base.getAccess(), MethodKind::Vanilla,
529                         MethodOptions::None);
530   printTypeIndex("BaseType", Base.getBaseType());
531   W->printHex("BaseOffset", Base.getBaseOffset());
532   return Error::success();
533 }
534 
visitKnownMember(CVMemberRecord & CVR,VirtualBaseClassRecord & Base)535 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
536                                         VirtualBaseClassRecord &Base) {
537   printMemberAttributes(Base.getAccess(), MethodKind::Vanilla,
538                         MethodOptions::None);
539   printTypeIndex("BaseType", Base.getBaseType());
540   printTypeIndex("VBPtrType", Base.getVBPtrType());
541   W->printHex("VBPtrOffset", Base.getVBPtrOffset());
542   W->printHex("VBTableIndex", Base.getVTableIndex());
543   return Error::success();
544 }
545 
visitKnownMember(CVMemberRecord & CVR,ListContinuationRecord & Cont)546 Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR,
547                                         ListContinuationRecord &Cont) {
548   printTypeIndex("ContinuationIndex", Cont.getContinuationIndex());
549   return Error::success();
550 }
551 
visitKnownRecord(CVType & CVR,LabelRecord & LR)552 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &LR) {
553   W->printEnum("Mode", uint16_t(LR.Mode), ArrayRef(LabelTypeEnum));
554   return Error::success();
555 }
556 
visitKnownRecord(CVType & CVR,PrecompRecord & Precomp)557 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
558                                         PrecompRecord &Precomp) {
559   W->printHex("StartIndex", Precomp.getStartTypeIndex());
560   W->printHex("Count", Precomp.getTypesCount());
561   W->printHex("Signature", Precomp.getSignature());
562   W->printString("PrecompFile", Precomp.getPrecompFilePath());
563   return Error::success();
564 }
565 
visitKnownRecord(CVType & CVR,EndPrecompRecord & EndPrecomp)566 Error TypeDumpVisitor::visitKnownRecord(CVType &CVR,
567                                         EndPrecompRecord &EndPrecomp) {
568   W->printHex("Signature", EndPrecomp.getSignature());
569   return Error::success();
570 }
571