]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
MFV r324198: 8081 Compiler warnings in zdb
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / MinimalSymbolDumper.cpp
1 //===- MinimalSymbolDumper.cpp -------------------------------- *- C++ --*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MinimalSymbolDumper.h"
11
12 #include "FormatUtil.h"
13 #include "LinePrinter.h"
14
15 #include "llvm/DebugInfo/CodeView/CVRecord.h"
16 #include "llvm/DebugInfo/CodeView/CodeView.h"
17 #include "llvm/DebugInfo/CodeView/Formatters.h"
18 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
19 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
20 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
21 #include "llvm/Support/FormatVariadic.h"
22
23 using namespace llvm;
24 using namespace llvm::codeview;
25 using namespace llvm::pdb;
26
27 static std::string formatLocalSymFlags(uint32_t IndentLevel,
28                                        LocalSymFlags Flags) {
29   std::vector<std::string> Opts;
30   if (Flags == LocalSymFlags::None)
31     return "none";
32
33   PUSH_FLAG(LocalSymFlags, IsParameter, Flags, "param");
34   PUSH_FLAG(LocalSymFlags, IsAddressTaken, Flags, "address is taken");
35   PUSH_FLAG(LocalSymFlags, IsCompilerGenerated, Flags, "compiler generated");
36   PUSH_FLAG(LocalSymFlags, IsAggregate, Flags, "aggregate");
37   PUSH_FLAG(LocalSymFlags, IsAggregated, Flags, "aggregated");
38   PUSH_FLAG(LocalSymFlags, IsAliased, Flags, "aliased");
39   PUSH_FLAG(LocalSymFlags, IsAlias, Flags, "alias");
40   PUSH_FLAG(LocalSymFlags, IsReturnValue, Flags, "return val");
41   PUSH_FLAG(LocalSymFlags, IsOptimizedOut, Flags, "optimized away");
42   PUSH_FLAG(LocalSymFlags, IsEnregisteredGlobal, Flags, "enreg global");
43   PUSH_FLAG(LocalSymFlags, IsEnregisteredStatic, Flags, "enreg static");
44   return typesetItemList(Opts, 4, IndentLevel, " | ");
45 }
46
47 static std::string formatExportFlags(uint32_t IndentLevel, ExportFlags Flags) {
48   std::vector<std::string> Opts;
49   if (Flags == ExportFlags::None)
50     return "none";
51
52   PUSH_FLAG(ExportFlags, IsConstant, Flags, "constant");
53   PUSH_FLAG(ExportFlags, IsData, Flags, "data");
54   PUSH_FLAG(ExportFlags, IsPrivate, Flags, "private");
55   PUSH_FLAG(ExportFlags, HasNoName, Flags, "no name");
56   PUSH_FLAG(ExportFlags, HasExplicitOrdinal, Flags, "explicit ord");
57   PUSH_FLAG(ExportFlags, IsForwarder, Flags, "forwarder");
58
59   return typesetItemList(Opts, 4, IndentLevel, " | ");
60 }
61
62 static std::string formatCompileSym2Flags(uint32_t IndentLevel,
63                                           CompileSym2Flags Flags) {
64   std::vector<std::string> Opts;
65   Flags &= ~CompileSym2Flags::SourceLanguageMask;
66   if (Flags == CompileSym2Flags::None)
67     return "none";
68
69   PUSH_FLAG(CompileSym2Flags, EC, Flags, "edit and continue");
70   PUSH_FLAG(CompileSym2Flags, NoDbgInfo, Flags, "no dbg info");
71   PUSH_FLAG(CompileSym2Flags, LTCG, Flags, "ltcg");
72   PUSH_FLAG(CompileSym2Flags, NoDataAlign, Flags, "no data align");
73   PUSH_FLAG(CompileSym2Flags, ManagedPresent, Flags, "has managed code");
74   PUSH_FLAG(CompileSym2Flags, SecurityChecks, Flags, "security checks");
75   PUSH_FLAG(CompileSym2Flags, HotPatch, Flags, "hot patchable");
76   PUSH_FLAG(CompileSym2Flags, CVTCIL, Flags, "cvtcil");
77   PUSH_FLAG(CompileSym2Flags, MSILModule, Flags, "msil module");
78   return typesetItemList(Opts, 4, IndentLevel, " | ");
79 }
80
81 static std::string formatCompileSym3Flags(uint32_t IndentLevel,
82                                           CompileSym3Flags Flags) {
83   std::vector<std::string> Opts;
84   Flags &= ~CompileSym3Flags::SourceLanguageMask;
85
86   if (Flags == CompileSym3Flags::None)
87     return "none";
88
89   PUSH_FLAG(CompileSym3Flags, EC, Flags, "edit and continue");
90   PUSH_FLAG(CompileSym3Flags, NoDbgInfo, Flags, "no dbg info");
91   PUSH_FLAG(CompileSym3Flags, LTCG, Flags, "ltcg");
92   PUSH_FLAG(CompileSym3Flags, NoDataAlign, Flags, "no data align");
93   PUSH_FLAG(CompileSym3Flags, ManagedPresent, Flags, "has managed code");
94   PUSH_FLAG(CompileSym3Flags, SecurityChecks, Flags, "security checks");
95   PUSH_FLAG(CompileSym3Flags, HotPatch, Flags, "hot patchable");
96   PUSH_FLAG(CompileSym3Flags, CVTCIL, Flags, "cvtcil");
97   PUSH_FLAG(CompileSym3Flags, MSILModule, Flags, "msil module");
98   PUSH_FLAG(CompileSym3Flags, Sdl, Flags, "sdl");
99   PUSH_FLAG(CompileSym3Flags, PGO, Flags, "pgo");
100   PUSH_FLAG(CompileSym3Flags, Exp, Flags, "exp");
101   return typesetItemList(Opts, 4, IndentLevel, " | ");
102 }
103
104 static std::string formatFrameProcedureOptions(uint32_t IndentLevel,
105                                                FrameProcedureOptions FPO) {
106   std::vector<std::string> Opts;
107   if (FPO == FrameProcedureOptions::None)
108     return "none";
109
110   PUSH_FLAG(FrameProcedureOptions, HasAlloca, FPO, "has alloca");
111   PUSH_FLAG(FrameProcedureOptions, HasSetJmp, FPO, "has setjmp");
112   PUSH_FLAG(FrameProcedureOptions, HasLongJmp, FPO, "has longjmp");
113   PUSH_FLAG(FrameProcedureOptions, HasInlineAssembly, FPO, "has inline asm");
114   PUSH_FLAG(FrameProcedureOptions, HasExceptionHandling, FPO, "has eh");
115   PUSH_FLAG(FrameProcedureOptions, MarkedInline, FPO, "marked inline");
116   PUSH_FLAG(FrameProcedureOptions, HasStructuredExceptionHandling, FPO,
117             "has seh");
118   PUSH_FLAG(FrameProcedureOptions, Naked, FPO, "naked");
119   PUSH_FLAG(FrameProcedureOptions, SecurityChecks, FPO, "secure checks");
120   PUSH_FLAG(FrameProcedureOptions, AsynchronousExceptionHandling, FPO,
121             "has async eh");
122   PUSH_FLAG(FrameProcedureOptions, NoStackOrderingForSecurityChecks, FPO,
123             "no stack order");
124   PUSH_FLAG(FrameProcedureOptions, Inlined, FPO, "inlined");
125   PUSH_FLAG(FrameProcedureOptions, StrictSecurityChecks, FPO,
126             "strict secure checks");
127   PUSH_FLAG(FrameProcedureOptions, SafeBuffers, FPO, "safe buffers");
128   PUSH_FLAG(FrameProcedureOptions, ProfileGuidedOptimization, FPO, "pgo");
129   PUSH_FLAG(FrameProcedureOptions, ValidProfileCounts, FPO,
130             "has profile counts");
131   PUSH_FLAG(FrameProcedureOptions, OptimizedForSpeed, FPO, "opt speed");
132   PUSH_FLAG(FrameProcedureOptions, GuardCfg, FPO, "guard cfg");
133   PUSH_FLAG(FrameProcedureOptions, GuardCfw, FPO, "guard cfw");
134   return typesetItemList(Opts, 4, IndentLevel, " | ");
135 }
136
137 static std::string formatPublicSymFlags(uint32_t IndentLevel,
138                                         PublicSymFlags Flags) {
139   std::vector<std::string> Opts;
140   if (Flags == PublicSymFlags::None)
141     return "none";
142
143   PUSH_FLAG(PublicSymFlags, Code, Flags, "code");
144   PUSH_FLAG(PublicSymFlags, Function, Flags, "function");
145   PUSH_FLAG(PublicSymFlags, Managed, Flags, "managed");
146   PUSH_FLAG(PublicSymFlags, MSIL, Flags, "msil");
147   return typesetItemList(Opts, 4, IndentLevel, " | ");
148 }
149
150 static std::string formatProcSymFlags(uint32_t IndentLevel,
151                                       ProcSymFlags Flags) {
152   std::vector<std::string> Opts;
153   if (Flags == ProcSymFlags::None)
154     return "none";
155
156   PUSH_FLAG(ProcSymFlags, HasFP, Flags, "has fp");
157   PUSH_FLAG(ProcSymFlags, HasIRET, Flags, "has iret");
158   PUSH_FLAG(ProcSymFlags, HasFRET, Flags, "has fret");
159   PUSH_FLAG(ProcSymFlags, IsNoReturn, Flags, "noreturn");
160   PUSH_FLAG(ProcSymFlags, IsUnreachable, Flags, "unreachable");
161   PUSH_FLAG(ProcSymFlags, HasCustomCallingConv, Flags, "custom calling conv");
162   PUSH_FLAG(ProcSymFlags, IsNoInline, Flags, "noinline");
163   PUSH_FLAG(ProcSymFlags, HasOptimizedDebugInfo, Flags, "opt debuginfo");
164   return typesetItemList(Opts, 4, IndentLevel, " | ");
165 }
166
167 static std::string formatThunkOrdinal(ThunkOrdinal Ordinal) {
168   switch (Ordinal) {
169     RETURN_CASE(ThunkOrdinal, Standard, "thunk");
170     RETURN_CASE(ThunkOrdinal, ThisAdjustor, "this adjustor");
171     RETURN_CASE(ThunkOrdinal, Vcall, "vcall");
172     RETURN_CASE(ThunkOrdinal, Pcode, "pcode");
173     RETURN_CASE(ThunkOrdinal, UnknownLoad, "unknown load");
174     RETURN_CASE(ThunkOrdinal, TrampIncremental, "tramp incremental");
175     RETURN_CASE(ThunkOrdinal, BranchIsland, "branch island");
176   }
177   return formatUnknownEnum(Ordinal);
178 }
179
180 static std::string formatTrampolineType(TrampolineType Tramp) {
181   switch (Tramp) {
182     RETURN_CASE(TrampolineType, TrampIncremental, "tramp incremental");
183     RETURN_CASE(TrampolineType, BranchIsland, "branch island");
184   }
185   return formatUnknownEnum(Tramp);
186 }
187
188 static std::string formatSourceLanguage(SourceLanguage Lang) {
189   switch (Lang) {
190     RETURN_CASE(SourceLanguage, C, "c");
191     RETURN_CASE(SourceLanguage, Cpp, "c++");
192     RETURN_CASE(SourceLanguage, Fortran, "fortran");
193     RETURN_CASE(SourceLanguage, Masm, "masm");
194     RETURN_CASE(SourceLanguage, Pascal, "pascal");
195     RETURN_CASE(SourceLanguage, Basic, "basic");
196     RETURN_CASE(SourceLanguage, Cobol, "cobol");
197     RETURN_CASE(SourceLanguage, Link, "link");
198     RETURN_CASE(SourceLanguage, VB, "vb");
199     RETURN_CASE(SourceLanguage, Cvtres, "cvtres");
200     RETURN_CASE(SourceLanguage, Cvtpgd, "cvtpgd");
201     RETURN_CASE(SourceLanguage, CSharp, "c#");
202     RETURN_CASE(SourceLanguage, ILAsm, "il asm");
203     RETURN_CASE(SourceLanguage, Java, "java");
204     RETURN_CASE(SourceLanguage, JScript, "javascript");
205     RETURN_CASE(SourceLanguage, MSIL, "msil");
206     RETURN_CASE(SourceLanguage, HLSL, "hlsl");
207     RETURN_CASE(SourceLanguage, D, "d");
208   }
209   return formatUnknownEnum(Lang);
210 }
211
212 static std::string formatMachineType(CPUType Cpu) {
213   switch (Cpu) {
214     RETURN_CASE(CPUType, Intel8080, "intel 8080");
215     RETURN_CASE(CPUType, Intel8086, "intel 8086");
216     RETURN_CASE(CPUType, Intel80286, "intel 80286");
217     RETURN_CASE(CPUType, Intel80386, "intel 80386");
218     RETURN_CASE(CPUType, Intel80486, "intel 80486");
219     RETURN_CASE(CPUType, Pentium, "intel pentium");
220     RETURN_CASE(CPUType, PentiumPro, "intel pentium pro");
221     RETURN_CASE(CPUType, Pentium3, "intel pentium 3");
222     RETURN_CASE(CPUType, MIPS, "mips");
223     RETURN_CASE(CPUType, MIPS16, "mips-16");
224     RETURN_CASE(CPUType, MIPS32, "mips-32");
225     RETURN_CASE(CPUType, MIPS64, "mips-64");
226     RETURN_CASE(CPUType, MIPSI, "mips i");
227     RETURN_CASE(CPUType, MIPSII, "mips ii");
228     RETURN_CASE(CPUType, MIPSIII, "mips iii");
229     RETURN_CASE(CPUType, MIPSIV, "mips iv");
230     RETURN_CASE(CPUType, MIPSV, "mips v");
231     RETURN_CASE(CPUType, M68000, "motorola 68000");
232     RETURN_CASE(CPUType, M68010, "motorola 68010");
233     RETURN_CASE(CPUType, M68020, "motorola 68020");
234     RETURN_CASE(CPUType, M68030, "motorola 68030");
235     RETURN_CASE(CPUType, M68040, "motorola 68040");
236     RETURN_CASE(CPUType, Alpha, "alpha");
237     RETURN_CASE(CPUType, Alpha21164, "alpha 21164");
238     RETURN_CASE(CPUType, Alpha21164A, "alpha 21164a");
239     RETURN_CASE(CPUType, Alpha21264, "alpha 21264");
240     RETURN_CASE(CPUType, Alpha21364, "alpha 21364");
241     RETURN_CASE(CPUType, PPC601, "powerpc 601");
242     RETURN_CASE(CPUType, PPC603, "powerpc 603");
243     RETURN_CASE(CPUType, PPC604, "powerpc 604");
244     RETURN_CASE(CPUType, PPC620, "powerpc 620");
245     RETURN_CASE(CPUType, PPCFP, "powerpc fp");
246     RETURN_CASE(CPUType, PPCBE, "powerpc be");
247     RETURN_CASE(CPUType, SH3, "sh3");
248     RETURN_CASE(CPUType, SH3E, "sh3e");
249     RETURN_CASE(CPUType, SH3DSP, "sh3 dsp");
250     RETURN_CASE(CPUType, SH4, "sh4");
251     RETURN_CASE(CPUType, SHMedia, "shmedia");
252     RETURN_CASE(CPUType, ARM3, "arm 3");
253     RETURN_CASE(CPUType, ARM4, "arm 4");
254     RETURN_CASE(CPUType, ARM4T, "arm 4t");
255     RETURN_CASE(CPUType, ARM5, "arm 5");
256     RETURN_CASE(CPUType, ARM5T, "arm 5t");
257     RETURN_CASE(CPUType, ARM6, "arm 6");
258     RETURN_CASE(CPUType, ARM_XMAC, "arm xmac");
259     RETURN_CASE(CPUType, ARM_WMMX, "arm wmmx");
260     RETURN_CASE(CPUType, ARM7, "arm 7");
261     RETURN_CASE(CPUType, ARM64, "arm64");
262     RETURN_CASE(CPUType, Omni, "omni");
263     RETURN_CASE(CPUType, Ia64, "intel itanium ia64");
264     RETURN_CASE(CPUType, Ia64_2, "intel itanium ia64 2");
265     RETURN_CASE(CPUType, CEE, "cee");
266     RETURN_CASE(CPUType, AM33, "am33");
267     RETURN_CASE(CPUType, M32R, "m32r");
268     RETURN_CASE(CPUType, TriCore, "tri-core");
269     RETURN_CASE(CPUType, X64, "intel x86-x64");
270     RETURN_CASE(CPUType, EBC, "ebc");
271     RETURN_CASE(CPUType, Thumb, "thumb");
272     RETURN_CASE(CPUType, ARMNT, "arm nt");
273     RETURN_CASE(CPUType, D3D11_Shader, "d3d11 shader");
274   }
275   return formatUnknownEnum(Cpu);
276 }
277
278 static std::string formatCookieKind(FrameCookieKind Kind) {
279   switch (Kind) {
280     RETURN_CASE(FrameCookieKind, Copy, "copy");
281     RETURN_CASE(FrameCookieKind, XorStackPointer, "xor stack ptr");
282     RETURN_CASE(FrameCookieKind, XorFramePointer, "xor frame ptr");
283     RETURN_CASE(FrameCookieKind, XorR13, "xor rot13");
284   }
285   return formatUnknownEnum(Kind);
286 }
287
288 static std::string formatRegisterId(RegisterId Id) {
289   switch (Id) {
290 #define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
291 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
292 #undef CV_REGISTER
293   }
294   return formatUnknownEnum(Id);
295 }
296
297 static std::string formatRange(LocalVariableAddrRange Range) {
298   return formatv("[{0},+{1})",
299                  formatSegmentOffset(Range.ISectStart, Range.OffsetStart),
300                  Range.Range)
301       .str();
302 }
303
304 static std::string formatGaps(uint32_t IndentLevel,
305                               ArrayRef<LocalVariableAddrGap> Gaps) {
306   std::vector<std::string> GapStrs;
307   for (const auto &G : Gaps) {
308     GapStrs.push_back(formatv("({0},{1})", G.GapStartOffset, G.Range).str());
309   }
310   return typesetItemList(GapStrs, 7, IndentLevel, ", ");
311 }
312
313 Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record) {
314   return visitSymbolBegin(Record, 0);
315 }
316
317 Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record,
318                                             uint32_t Offset) {
319   // formatLine puts the newline at the beginning, so we use formatLine here
320   // to start a new line, and then individual visit methods use format to
321   // append to the existing line.
322   P.formatLine("{0} | {1} [size = {2}]",
323                fmt_align(Offset, AlignStyle::Right, 6),
324                formatSymbolKind(Record.Type), Record.length());
325   P.Indent();
326   return Error::success();
327 }
328
329 Error MinimalSymbolDumper::visitSymbolEnd(CVSymbol &Record) {
330   if (RecordBytes) {
331     AutoIndent Indent(P, 7);
332     P.formatBinary("bytes", Record.content(), 0);
333   }
334   P.Unindent();
335   return Error::success();
336 }
337
338 std::string MinimalSymbolDumper::typeOrIdIndex(codeview::TypeIndex TI,
339                                                bool IsType) const {
340   if (TI.isSimple() || TI.isDecoratedItemId())
341     return formatv("{0}", TI).str();
342   auto &Container = IsType ? Types : Ids;
343   StringRef Name = Container.getTypeName(TI);
344   if (Name.size() > 32) {
345     Name = Name.take_front(32);
346     return formatv("{0} ({1}...)", TI, Name);
347   } else
348     return formatv("{0} ({1})", TI, Name);
349 }
350
351 std::string MinimalSymbolDumper::idIndex(codeview::TypeIndex TI) const {
352   return typeOrIdIndex(TI, false);
353 }
354
355 std::string MinimalSymbolDumper::typeIndex(TypeIndex TI) const {
356   return typeOrIdIndex(TI, true);
357 }
358
359 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
360   P.format(" `{0}`", Block.Name);
361   AutoIndent Indent(P, 7);
362   P.formatLine("parent = {0}, end = {1}", Block.Parent, Block.End);
363   P.formatLine("code size = {0}, addr = {1}", Block.CodeSize,
364                formatSegmentOffset(Block.Segment, Block.CodeOffset));
365   return Error::success();
366 }
367
368 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
369   P.format(" `{0}`", Thunk.Name);
370   AutoIndent Indent(P, 7);
371   P.formatLine("parent = {0}, end = {1}, next = {2}", Thunk.Parent, Thunk.End,
372                Thunk.Next);
373   P.formatLine("kind = {0}, size = {1}, addr = {2}",
374                formatThunkOrdinal(Thunk.Thunk), Thunk.Length,
375                formatSegmentOffset(Thunk.Segment, Thunk.Offset));
376
377   return Error::success();
378 }
379
380 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
381                                             TrampolineSym &Tramp) {
382   AutoIndent Indent(P, 7);
383   P.formatLine("type = {0}, size = {1}, source = {2}, target = {3}",
384                formatTrampolineType(Tramp.Type), Tramp.Size,
385                formatSegmentOffset(Tramp.ThunkSection, Tramp.ThunkOffset),
386                formatSegmentOffset(Tramp.TargetSection, Tramp.ThunkOffset));
387
388   return Error::success();
389 }
390
391 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
392                                             SectionSym &Section) {
393   P.format(" `{0}`", Section.Name);
394   AutoIndent Indent(P, 7);
395   P.formatLine("length = {0}, alignment = {1}, rva = {2}, section # = {3}",
396                Section.Length, Section.Alignment, Section.Rva,
397                Section.SectionNumber);
398   P.printLine("characteristics =");
399   AutoIndent Indent2(P, 2);
400   P.printLine(formatSectionCharacteristics(P.getIndentLevel(),
401                                            Section.Characteristics, 1, "",
402                                            CharacteristicStyle::Descriptive));
403   return Error::success();
404 }
405
406 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CoffGroupSym &CG) {
407   P.format(" `{0}`", CG.Name);
408   AutoIndent Indent(P, 7);
409   P.formatLine("length = {0}, addr = {1}", CG.Size,
410                formatSegmentOffset(CG.Segment, CG.Offset));
411   P.printLine("characteristics =");
412   AutoIndent Indent2(P, 2);
413   P.printLine(formatSectionCharacteristics(P.getIndentLevel(),
414                                            CG.Characteristics, 1, "",
415                                            CharacteristicStyle::Descriptive));
416   return Error::success();
417 }
418
419 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
420                                             BPRelativeSym &BPRel) {
421   P.format(" `{0}`", BPRel.Name);
422   AutoIndent Indent(P, 7);
423   P.formatLine("type = {0}, offset = {1}", typeIndex(BPRel.Type), BPRel.Offset);
424   return Error::success();
425 }
426
427 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
428                                             BuildInfoSym &BuildInfo) {
429   P.format(" BuildId = `{0}`", BuildInfo.BuildId);
430   return Error::success();
431 }
432
433 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
434                                             CallSiteInfoSym &CSI) {
435   AutoIndent Indent(P, 7);
436   P.formatLine("type = {0}, addr = {1}", typeIndex(CSI.Type),
437                formatSegmentOffset(CSI.Segment, CSI.CodeOffset));
438   return Error::success();
439 }
440
441 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
442                                             EnvBlockSym &EnvBlock) {
443   AutoIndent Indent(P, 7);
444   for (const auto &Entry : EnvBlock.Fields) {
445     P.formatLine("- {0}", Entry);
446   }
447   return Error::success();
448 }
449
450 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FileStaticSym &FS) {
451   P.format(" `{0}`", FS.Name);
452   AutoIndent Indent(P, 7);
453   P.formatLine("type = {0}, file name offset = {1}, flags = {2}",
454                typeIndex(FS.Index), FS.ModFilenameOffset,
455                formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));
456   return Error::success();
457 }
458
459 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
460   P.format(" `{0}`", Export.Name);
461   AutoIndent Indent(P, 7);
462   P.formatLine("ordinal = {0}, flags = {1}", Export.Ordinal,
463                formatExportFlags(P.getIndentLevel() + 9, Export.Flags));
464   return Error::success();
465 }
466
467 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
468                                             Compile2Sym &Compile2) {
469   AutoIndent Indent(P, 7);
470   SourceLanguage Lang = static_cast<SourceLanguage>(
471       Compile2.Flags & CompileSym2Flags::SourceLanguageMask);
472   P.formatLine("machine = {0}, ver = {1}, language = {2}",
473                formatMachineType(Compile2.Machine), Compile2.Version,
474                formatSourceLanguage(Lang));
475   P.formatLine("frontend = {0}.{1}.{2}, backend = {3}.{4}.{5}",
476                Compile2.VersionFrontendMajor, Compile2.VersionFrontendMinor,
477                Compile2.VersionFrontendBuild, Compile2.VersionBackendMajor,
478                Compile2.VersionBackendMinor, Compile2.VersionBackendBuild);
479   P.formatLine("flags = {0}",
480                formatCompileSym2Flags(P.getIndentLevel() + 9, Compile2.Flags));
481   P.formatLine(
482       "extra strings = {0}",
483       typesetStringList(P.getIndentLevel() + 9 + 2, Compile2.ExtraStrings));
484   return Error::success();
485 }
486
487 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
488                                             Compile3Sym &Compile3) {
489   AutoIndent Indent(P, 7);
490   SourceLanguage Lang = static_cast<SourceLanguage>(
491       Compile3.Flags & CompileSym3Flags::SourceLanguageMask);
492   P.formatLine("machine = {0}, Ver = {1}, language = {2}",
493                formatMachineType(Compile3.Machine), Compile3.Version,
494                formatSourceLanguage(Lang));
495   P.formatLine("frontend = {0}.{1}.{2}.{3}, backend = {4}.{5}.{6}.{7}",
496                Compile3.VersionFrontendMajor, Compile3.VersionFrontendMinor,
497                Compile3.VersionFrontendBuild, Compile3.VersionFrontendQFE,
498                Compile3.VersionBackendMajor, Compile3.VersionBackendMinor,
499                Compile3.VersionBackendBuild, Compile3.VersionBackendQFE);
500   P.formatLine("flags = {0}",
501                formatCompileSym3Flags(P.getIndentLevel() + 9, Compile3.Flags));
502   return Error::success();
503 }
504
505 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
506                                             ConstantSym &Constant) {
507   P.format(" `{0}`", Constant.Name);
508   AutoIndent Indent(P, 7);
509   P.formatLine("type = {0}, value = {1}", typeIndex(Constant.Type),
510                Constant.Value.toString(10));
511   return Error::success();
512 }
513
514 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
515   P.format(" `{0}`", Data.Name);
516   AutoIndent Indent(P, 7);
517   P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),
518                formatSegmentOffset(Data.Segment, Data.DataOffset));
519   return Error::success();
520 }
521
522 Error MinimalSymbolDumper::visitKnownRecord(
523     CVSymbol &CVR, DefRangeFramePointerRelFullScopeSym &Def) {
524   P.format(" offset = {0}", Def.Offset);
525   return Error::success();
526 }
527
528 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
529                                             DefRangeFramePointerRelSym &Def) {
530   AutoIndent Indent(P, 7);
531   P.formatLine("offset = {0}, range = {1}", Def.Offset, formatRange(Def.Range));
532   P.formatLine("gaps = {2}", Def.Offset,
533                formatGaps(P.getIndentLevel() + 9, Def.Gaps));
534   return Error::success();
535 }
536
537 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
538                                             DefRangeRegisterRelSym &Def) {
539   AutoIndent Indent(P, 7);
540   P.formatLine("register = {0}, base ptr = {1}, offset in parent = {2}, has "
541                "spilled udt = {3}",
542                uint16_t(Def.Hdr.Register), int32_t(Def.Hdr.BasePointerOffset),
543                Def.offsetInParent(), Def.hasSpilledUDTMember());
544   P.formatLine("range = {0}, gaps = {1}", formatRange(Def.Range),
545                formatGaps(P.getIndentLevel() + 9, Def.Gaps));
546   return Error::success();
547 }
548
549 Error MinimalSymbolDumper::visitKnownRecord(
550     CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
551   AutoIndent Indent(P, 7);
552   P.formatLine("register = {0}, may have no name = {1}, range start = "
553                "{2}, length = {3}",
554                uint16_t(DefRangeRegister.Hdr.Register),
555                uint16_t(DefRangeRegister.Hdr.MayHaveNoName),
556                formatSegmentOffset(DefRangeRegister.Range.ISectStart,
557                                    DefRangeRegister.Range.OffsetStart),
558                DefRangeRegister.Range.Range);
559   P.formatLine("gaps = [{0}]",
560                formatGaps(P.getIndentLevel() + 9, DefRangeRegister.Gaps));
561   return Error::success();
562 }
563
564 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
565                                             DefRangeSubfieldRegisterSym &Def) {
566   AutoIndent Indent(P, 7);
567   bool NoName = !!(Def.Hdr.MayHaveNoName == 0);
568   P.formatLine("register = {0}, may have no name = {1}, offset in parent = {2}",
569                uint16_t(Def.Hdr.Register), NoName,
570                uint32_t(Def.Hdr.OffsetInParent));
571   P.formatLine("range = {0}, gaps = {1}", formatRange(Def.Range),
572                formatGaps(P.getIndentLevel() + 9, Def.Gaps));
573   return Error::success();
574 }
575
576 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
577                                             DefRangeSubfieldSym &Def) {
578   AutoIndent Indent(P, 7);
579   P.formatLine("program = {0}, offset in parent = {1}, range = {2}",
580                Def.Program, Def.OffsetInParent, formatRange(Def.Range));
581   P.formatLine("gaps = {0}", formatGaps(P.getIndentLevel() + 9, Def.Gaps));
582   return Error::success();
583 }
584
585 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DefRangeSym &Def) {
586   AutoIndent Indent(P, 7);
587   P.formatLine("program = {0}, range = {1}", Def.Program,
588                formatRange(Def.Range));
589   P.formatLine("gaps = {0}", formatGaps(P.getIndentLevel() + 9, Def.Gaps));
590   return Error::success();
591 }
592
593 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameCookieSym &FC) {
594   AutoIndent Indent(P, 7);
595   P.formatLine("code offset = {0}, Register = {1}, kind = {2}, flags = {3}",
596                FC.CodeOffset, FC.Register, formatCookieKind(FC.CookieKind),
597                FC.Flags);
598   return Error::success();
599 }
600
601 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameProcSym &FP) {
602   AutoIndent Indent(P, 7);
603   P.formatLine("size = {0}, padding size = {1}, offset to padding = {2}",
604                FP.TotalFrameBytes, FP.PaddingFrameBytes, FP.OffsetToPadding);
605   P.formatLine("bytes of callee saved registers = {0}, exception handler addr "
606                "= {1}",
607                FP.BytesOfCalleeSavedRegisters,
608                formatSegmentOffset(FP.SectionIdOfExceptionHandler,
609                                    FP.OffsetOfExceptionHandler));
610   P.formatLine("flags = {0}",
611                formatFrameProcedureOptions(P.getIndentLevel() + 9, FP.Flags));
612   return Error::success();
613 }
614
615 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
616                                             HeapAllocationSiteSym &HAS) {
617   AutoIndent Indent(P, 7);
618   P.formatLine("type = {0}, addr = {1} call size = {2}", typeIndex(HAS.Type),
619                formatSegmentOffset(HAS.Segment, HAS.CodeOffset),
620                HAS.CallInstructionSize);
621   return Error::success();
622 }
623
624 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, InlineSiteSym &IS) {
625   AutoIndent Indent(P, 7);
626   auto Bytes = makeArrayRef(IS.AnnotationData);
627   StringRef Annotations(reinterpret_cast<const char *>(Bytes.begin()),
628                         Bytes.size());
629
630   P.formatLine("inlinee = {0}, parent = {1}, end = {2}", idIndex(IS.Inlinee),
631                IS.Parent, IS.End);
632   P.formatLine("annotations = {0}", toHex(Annotations));
633   return Error::success();
634 }
635
636 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
637                                             RegisterSym &Register) {
638   P.format(" `{0}`", Register.Name);
639   AutoIndent Indent(P, 7);
640   P.formatLine("register = {0}, type = {1}",
641                formatRegisterId(Register.Register), typeIndex(Register.Index));
642   return Error::success();
643 }
644
645 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
646                                             PublicSym32 &Public) {
647   P.format(" `{0}`", Public.Name);
648   AutoIndent Indent(P, 7);
649   P.formatLine("flags = {0}, addr = {1}",
650                formatPublicSymFlags(P.getIndentLevel() + 9, Public.Flags),
651                formatSegmentOffset(Public.Segment, Public.Offset));
652   return Error::success();
653 }
654
655 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcRefSym &PR) {
656   P.format(" `{0}`", PR.Name);
657   AutoIndent Indent(P, 7);
658   P.formatLine("module = {0}, sum name = {1}, offset = {2}", PR.Module,
659                PR.SumName, PR.SymOffset);
660   return Error::success();
661 }
662
663 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
664   P.format(" `{0}` (addr = {1})", Label.Name,
665            formatSegmentOffset(Label.Segment, Label.CodeOffset));
666   AutoIndent Indent(P, 7);
667   P.formatLine("flags = {0}",
668                formatProcSymFlags(P.getIndentLevel() + 9, Label.Flags));
669   return Error::success();
670 }
671
672 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
673   P.format(" `{0}`", Local.Name);
674   AutoIndent Indent(P, 7);
675
676   std::string FlagStr =
677       formatLocalSymFlags(P.getIndentLevel() + 9, Local.Flags);
678   P.formatLine("type={0}, flags = {1}", typeIndex(Local.Type), FlagStr);
679   return Error::success();
680 }
681
682 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
683                                             ObjNameSym &ObjName) {
684   P.format(" sig={0}, `{1}`", ObjName.Signature, ObjName.Name);
685   return Error::success();
686 }
687
688 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
689   P.format(" `{0}`", Proc.Name);
690   AutoIndent Indent(P, 7);
691   P.formatLine("parent = {0}, end = {1}, addr = {2}, code size = {3}",
692                Proc.Parent, Proc.End,
693                formatSegmentOffset(Proc.Segment, Proc.CodeOffset),
694                Proc.CodeSize);
695   bool IsType = true;
696   switch (Proc.getKind()) {
697   case SymbolRecordKind::GlobalProcIdSym:
698   case SymbolRecordKind::ProcIdSym:
699   case SymbolRecordKind::DPCProcIdSym:
700     IsType = false;
701     break;
702   default:
703     break;
704   }
705   P.formatLine("type = `{0}`, debug start = {1}, debug end = {2}, flags = {3}",
706                typeOrIdIndex(Proc.FunctionType, IsType), Proc.DbgStart,
707                Proc.DbgEnd,
708                formatProcSymFlags(P.getIndentLevel() + 9, Proc.Flags));
709   return Error::success();
710 }
711
712 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
713                                             ScopeEndSym &ScopeEnd) {
714   return Error::success();
715 }
716
717 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
718   AutoIndent Indent(P, 7);
719   for (const auto &I : Caller.Indices) {
720     P.formatLine("callee: {0}", idIndex(I));
721   }
722   return Error::success();
723 }
724
725 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
726                                             RegRelativeSym &RegRel) {
727   P.format(" `{0}`", RegRel.Name);
728   AutoIndent Indent(P, 7);
729   P.formatLine("type = {0}, register = {1}, offset = {2}",
730                typeIndex(RegRel.Type), formatRegisterId(RegRel.Register),
731                RegRel.Offset);
732   return Error::success();
733 }
734
735 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
736                                             ThreadLocalDataSym &Data) {
737   P.format(" `{0}`", Data.Name);
738   AutoIndent Indent(P, 7);
739   P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),
740                formatSegmentOffset(Data.Segment, Data.DataOffset));
741   return Error::success();
742 }
743
744 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
745   P.format(" `{0}`", UDT.Name);
746   AutoIndent Indent(P, 7);
747   P.formatLine("original type = {0}", UDT.Type);
748   return Error::success();
749 }