1 //===- MinimalSymbolDumper.cpp -------------------------------- *- C++ --*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "MinimalSymbolDumper.h"
11 #include "FormatUtil.h"
12 #include "InputFile.h"
13 #include "LinePrinter.h"
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/DebugInfo/PDB/Native/PDBStringTable.h"
22 #include "llvm/Support/FormatVariadic.h"
25 using namespace llvm::codeview;
26 using namespace llvm::pdb;
28 static std::string formatLocalSymFlags(uint32_t IndentLevel,
29 LocalSymFlags Flags) {
30 std::vector<std::string> Opts;
31 if (Flags == LocalSymFlags::None)
34 PUSH_FLAG(LocalSymFlags, IsParameter, Flags, "param");
35 PUSH_FLAG(LocalSymFlags, IsAddressTaken, Flags, "address is taken");
36 PUSH_FLAG(LocalSymFlags, IsCompilerGenerated, Flags, "compiler generated");
37 PUSH_FLAG(LocalSymFlags, IsAggregate, Flags, "aggregate");
38 PUSH_FLAG(LocalSymFlags, IsAggregated, Flags, "aggregated");
39 PUSH_FLAG(LocalSymFlags, IsAliased, Flags, "aliased");
40 PUSH_FLAG(LocalSymFlags, IsAlias, Flags, "alias");
41 PUSH_FLAG(LocalSymFlags, IsReturnValue, Flags, "return val");
42 PUSH_FLAG(LocalSymFlags, IsOptimizedOut, Flags, "optimized away");
43 PUSH_FLAG(LocalSymFlags, IsEnregisteredGlobal, Flags, "enreg global");
44 PUSH_FLAG(LocalSymFlags, IsEnregisteredStatic, Flags, "enreg static");
45 return typesetItemList(Opts, 4, IndentLevel, " | ");
48 static std::string formatExportFlags(uint32_t IndentLevel, ExportFlags Flags) {
49 std::vector<std::string> Opts;
50 if (Flags == ExportFlags::None)
53 PUSH_FLAG(ExportFlags, IsConstant, Flags, "constant");
54 PUSH_FLAG(ExportFlags, IsData, Flags, "data");
55 PUSH_FLAG(ExportFlags, IsPrivate, Flags, "private");
56 PUSH_FLAG(ExportFlags, HasNoName, Flags, "no name");
57 PUSH_FLAG(ExportFlags, HasExplicitOrdinal, Flags, "explicit ord");
58 PUSH_FLAG(ExportFlags, IsForwarder, Flags, "forwarder");
60 return typesetItemList(Opts, 4, IndentLevel, " | ");
63 static std::string formatCompileSym2Flags(uint32_t IndentLevel,
64 CompileSym2Flags Flags) {
65 std::vector<std::string> Opts;
66 Flags &= ~CompileSym2Flags::SourceLanguageMask;
67 if (Flags == CompileSym2Flags::None)
70 PUSH_FLAG(CompileSym2Flags, EC, Flags, "edit and continue");
71 PUSH_FLAG(CompileSym2Flags, NoDbgInfo, Flags, "no dbg info");
72 PUSH_FLAG(CompileSym2Flags, LTCG, Flags, "ltcg");
73 PUSH_FLAG(CompileSym2Flags, NoDataAlign, Flags, "no data align");
74 PUSH_FLAG(CompileSym2Flags, ManagedPresent, Flags, "has managed code");
75 PUSH_FLAG(CompileSym2Flags, SecurityChecks, Flags, "security checks");
76 PUSH_FLAG(CompileSym2Flags, HotPatch, Flags, "hot patchable");
77 PUSH_FLAG(CompileSym2Flags, CVTCIL, Flags, "cvtcil");
78 PUSH_FLAG(CompileSym2Flags, MSILModule, Flags, "msil module");
79 return typesetItemList(Opts, 4, IndentLevel, " | ");
82 static std::string formatCompileSym3Flags(uint32_t IndentLevel,
83 CompileSym3Flags Flags) {
84 std::vector<std::string> Opts;
85 Flags &= ~CompileSym3Flags::SourceLanguageMask;
87 if (Flags == CompileSym3Flags::None)
90 PUSH_FLAG(CompileSym3Flags, EC, Flags, "edit and continue");
91 PUSH_FLAG(CompileSym3Flags, NoDbgInfo, Flags, "no dbg info");
92 PUSH_FLAG(CompileSym3Flags, LTCG, Flags, "ltcg");
93 PUSH_FLAG(CompileSym3Flags, NoDataAlign, Flags, "no data align");
94 PUSH_FLAG(CompileSym3Flags, ManagedPresent, Flags, "has managed code");
95 PUSH_FLAG(CompileSym3Flags, SecurityChecks, Flags, "security checks");
96 PUSH_FLAG(CompileSym3Flags, HotPatch, Flags, "hot patchable");
97 PUSH_FLAG(CompileSym3Flags, CVTCIL, Flags, "cvtcil");
98 PUSH_FLAG(CompileSym3Flags, MSILModule, Flags, "msil module");
99 PUSH_FLAG(CompileSym3Flags, Sdl, Flags, "sdl");
100 PUSH_FLAG(CompileSym3Flags, PGO, Flags, "pgo");
101 PUSH_FLAG(CompileSym3Flags, Exp, Flags, "exp");
102 return typesetItemList(Opts, 4, IndentLevel, " | ");
105 static std::string formatFrameProcedureOptions(uint32_t IndentLevel,
106 FrameProcedureOptions FPO) {
107 std::vector<std::string> Opts;
108 if (FPO == FrameProcedureOptions::None)
111 PUSH_FLAG(FrameProcedureOptions, HasAlloca, FPO, "has alloca");
112 PUSH_FLAG(FrameProcedureOptions, HasSetJmp, FPO, "has setjmp");
113 PUSH_FLAG(FrameProcedureOptions, HasLongJmp, FPO, "has longjmp");
114 PUSH_FLAG(FrameProcedureOptions, HasInlineAssembly, FPO, "has inline asm");
115 PUSH_FLAG(FrameProcedureOptions, HasExceptionHandling, FPO, "has eh");
116 PUSH_FLAG(FrameProcedureOptions, MarkedInline, FPO, "marked inline");
117 PUSH_FLAG(FrameProcedureOptions, HasStructuredExceptionHandling, FPO,
119 PUSH_FLAG(FrameProcedureOptions, Naked, FPO, "naked");
120 PUSH_FLAG(FrameProcedureOptions, SecurityChecks, FPO, "secure checks");
121 PUSH_FLAG(FrameProcedureOptions, AsynchronousExceptionHandling, FPO,
123 PUSH_FLAG(FrameProcedureOptions, NoStackOrderingForSecurityChecks, FPO,
125 PUSH_FLAG(FrameProcedureOptions, Inlined, FPO, "inlined");
126 PUSH_FLAG(FrameProcedureOptions, StrictSecurityChecks, FPO,
127 "strict secure checks");
128 PUSH_FLAG(FrameProcedureOptions, SafeBuffers, FPO, "safe buffers");
129 PUSH_FLAG(FrameProcedureOptions, ProfileGuidedOptimization, FPO, "pgo");
130 PUSH_FLAG(FrameProcedureOptions, ValidProfileCounts, FPO,
131 "has profile counts");
132 PUSH_FLAG(FrameProcedureOptions, OptimizedForSpeed, FPO, "opt speed");
133 PUSH_FLAG(FrameProcedureOptions, GuardCfg, FPO, "guard cfg");
134 PUSH_FLAG(FrameProcedureOptions, GuardCfw, FPO, "guard cfw");
135 return typesetItemList(Opts, 4, IndentLevel, " | ");
138 static std::string formatPublicSymFlags(uint32_t IndentLevel,
139 PublicSymFlags Flags) {
140 std::vector<std::string> Opts;
141 if (Flags == PublicSymFlags::None)
144 PUSH_FLAG(PublicSymFlags, Code, Flags, "code");
145 PUSH_FLAG(PublicSymFlags, Function, Flags, "function");
146 PUSH_FLAG(PublicSymFlags, Managed, Flags, "managed");
147 PUSH_FLAG(PublicSymFlags, MSIL, Flags, "msil");
148 return typesetItemList(Opts, 4, IndentLevel, " | ");
151 static std::string formatProcSymFlags(uint32_t IndentLevel,
152 ProcSymFlags Flags) {
153 std::vector<std::string> Opts;
154 if (Flags == ProcSymFlags::None)
157 PUSH_FLAG(ProcSymFlags, HasFP, Flags, "has fp");
158 PUSH_FLAG(ProcSymFlags, HasIRET, Flags, "has iret");
159 PUSH_FLAG(ProcSymFlags, HasFRET, Flags, "has fret");
160 PUSH_FLAG(ProcSymFlags, IsNoReturn, Flags, "noreturn");
161 PUSH_FLAG(ProcSymFlags, IsUnreachable, Flags, "unreachable");
162 PUSH_FLAG(ProcSymFlags, HasCustomCallingConv, Flags, "custom calling conv");
163 PUSH_FLAG(ProcSymFlags, IsNoInline, Flags, "noinline");
164 PUSH_FLAG(ProcSymFlags, HasOptimizedDebugInfo, Flags, "opt debuginfo");
165 return typesetItemList(Opts, 4, IndentLevel, " | ");
168 static std::string formatThunkOrdinal(ThunkOrdinal Ordinal) {
170 RETURN_CASE(ThunkOrdinal, Standard, "thunk");
171 RETURN_CASE(ThunkOrdinal, ThisAdjustor, "this adjustor");
172 RETURN_CASE(ThunkOrdinal, Vcall, "vcall");
173 RETURN_CASE(ThunkOrdinal, Pcode, "pcode");
174 RETURN_CASE(ThunkOrdinal, UnknownLoad, "unknown load");
175 RETURN_CASE(ThunkOrdinal, TrampIncremental, "tramp incremental");
176 RETURN_CASE(ThunkOrdinal, BranchIsland, "branch island");
178 return formatUnknownEnum(Ordinal);
181 static std::string formatTrampolineType(TrampolineType Tramp) {
183 RETURN_CASE(TrampolineType, TrampIncremental, "tramp incremental");
184 RETURN_CASE(TrampolineType, BranchIsland, "branch island");
186 return formatUnknownEnum(Tramp);
189 static std::string formatSourceLanguage(SourceLanguage Lang) {
191 RETURN_CASE(SourceLanguage, C, "c");
192 RETURN_CASE(SourceLanguage, Cpp, "c++");
193 RETURN_CASE(SourceLanguage, Fortran, "fortran");
194 RETURN_CASE(SourceLanguage, Masm, "masm");
195 RETURN_CASE(SourceLanguage, Pascal, "pascal");
196 RETURN_CASE(SourceLanguage, Basic, "basic");
197 RETURN_CASE(SourceLanguage, Cobol, "cobol");
198 RETURN_CASE(SourceLanguage, Link, "link");
199 RETURN_CASE(SourceLanguage, VB, "vb");
200 RETURN_CASE(SourceLanguage, Cvtres, "cvtres");
201 RETURN_CASE(SourceLanguage, Cvtpgd, "cvtpgd");
202 RETURN_CASE(SourceLanguage, CSharp, "c#");
203 RETURN_CASE(SourceLanguage, ILAsm, "il asm");
204 RETURN_CASE(SourceLanguage, Java, "java");
205 RETURN_CASE(SourceLanguage, JScript, "javascript");
206 RETURN_CASE(SourceLanguage, MSIL, "msil");
207 RETURN_CASE(SourceLanguage, HLSL, "hlsl");
208 RETURN_CASE(SourceLanguage, D, "d");
209 RETURN_CASE(SourceLanguage, Swift, "swift");
211 return formatUnknownEnum(Lang);
214 static std::string formatMachineType(CPUType Cpu) {
216 RETURN_CASE(CPUType, Intel8080, "intel 8080");
217 RETURN_CASE(CPUType, Intel8086, "intel 8086");
218 RETURN_CASE(CPUType, Intel80286, "intel 80286");
219 RETURN_CASE(CPUType, Intel80386, "intel 80386");
220 RETURN_CASE(CPUType, Intel80486, "intel 80486");
221 RETURN_CASE(CPUType, Pentium, "intel pentium");
222 RETURN_CASE(CPUType, PentiumPro, "intel pentium pro");
223 RETURN_CASE(CPUType, Pentium3, "intel pentium 3");
224 RETURN_CASE(CPUType, MIPS, "mips");
225 RETURN_CASE(CPUType, MIPS16, "mips-16");
226 RETURN_CASE(CPUType, MIPS32, "mips-32");
227 RETURN_CASE(CPUType, MIPS64, "mips-64");
228 RETURN_CASE(CPUType, MIPSI, "mips i");
229 RETURN_CASE(CPUType, MIPSII, "mips ii");
230 RETURN_CASE(CPUType, MIPSIII, "mips iii");
231 RETURN_CASE(CPUType, MIPSIV, "mips iv");
232 RETURN_CASE(CPUType, MIPSV, "mips v");
233 RETURN_CASE(CPUType, M68000, "motorola 68000");
234 RETURN_CASE(CPUType, M68010, "motorola 68010");
235 RETURN_CASE(CPUType, M68020, "motorola 68020");
236 RETURN_CASE(CPUType, M68030, "motorola 68030");
237 RETURN_CASE(CPUType, M68040, "motorola 68040");
238 RETURN_CASE(CPUType, Alpha, "alpha");
239 RETURN_CASE(CPUType, Alpha21164, "alpha 21164");
240 RETURN_CASE(CPUType, Alpha21164A, "alpha 21164a");
241 RETURN_CASE(CPUType, Alpha21264, "alpha 21264");
242 RETURN_CASE(CPUType, Alpha21364, "alpha 21364");
243 RETURN_CASE(CPUType, PPC601, "powerpc 601");
244 RETURN_CASE(CPUType, PPC603, "powerpc 603");
245 RETURN_CASE(CPUType, PPC604, "powerpc 604");
246 RETURN_CASE(CPUType, PPC620, "powerpc 620");
247 RETURN_CASE(CPUType, PPCFP, "powerpc fp");
248 RETURN_CASE(CPUType, PPCBE, "powerpc be");
249 RETURN_CASE(CPUType, SH3, "sh3");
250 RETURN_CASE(CPUType, SH3E, "sh3e");
251 RETURN_CASE(CPUType, SH3DSP, "sh3 dsp");
252 RETURN_CASE(CPUType, SH4, "sh4");
253 RETURN_CASE(CPUType, SHMedia, "shmedia");
254 RETURN_CASE(CPUType, ARM3, "arm 3");
255 RETURN_CASE(CPUType, ARM4, "arm 4");
256 RETURN_CASE(CPUType, ARM4T, "arm 4t");
257 RETURN_CASE(CPUType, ARM5, "arm 5");
258 RETURN_CASE(CPUType, ARM5T, "arm 5t");
259 RETURN_CASE(CPUType, ARM6, "arm 6");
260 RETURN_CASE(CPUType, ARM_XMAC, "arm xmac");
261 RETURN_CASE(CPUType, ARM_WMMX, "arm wmmx");
262 RETURN_CASE(CPUType, ARM7, "arm 7");
263 RETURN_CASE(CPUType, ARM64, "arm64");
264 RETURN_CASE(CPUType, Omni, "omni");
265 RETURN_CASE(CPUType, Ia64, "intel itanium ia64");
266 RETURN_CASE(CPUType, Ia64_2, "intel itanium ia64 2");
267 RETURN_CASE(CPUType, CEE, "cee");
268 RETURN_CASE(CPUType, AM33, "am33");
269 RETURN_CASE(CPUType, M32R, "m32r");
270 RETURN_CASE(CPUType, TriCore, "tri-core");
271 RETURN_CASE(CPUType, X64, "intel x86-x64");
272 RETURN_CASE(CPUType, EBC, "ebc");
273 RETURN_CASE(CPUType, Thumb, "thumb");
274 RETURN_CASE(CPUType, ARMNT, "arm nt");
275 RETURN_CASE(CPUType, D3D11_Shader, "d3d11 shader");
277 return formatUnknownEnum(Cpu);
280 static std::string formatCookieKind(FrameCookieKind Kind) {
282 RETURN_CASE(FrameCookieKind, Copy, "copy");
283 RETURN_CASE(FrameCookieKind, XorStackPointer, "xor stack ptr");
284 RETURN_CASE(FrameCookieKind, XorFramePointer, "xor frame ptr");
285 RETURN_CASE(FrameCookieKind, XorR13, "xor rot13");
287 return formatUnknownEnum(Kind);
290 static std::string formatRegisterId(RegisterId Id, CPUType Cpu) {
291 if (Cpu == CPUType::ARM64) {
293 #define CV_REGISTERS_ARM64
294 #define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
295 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
297 #undef CV_REGISTERS_ARM64
304 #define CV_REGISTERS_X86
305 #define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
306 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
308 #undef CV_REGISTERS_X86
314 return formatUnknownEnum(Id);
317 static std::string formatRegisterId(uint16_t Reg16, CPUType Cpu) {
318 return formatRegisterId(RegisterId(Reg16), Cpu);
321 static std::string formatRegisterId(ulittle16_t &Reg16, CPUType Cpu) {
322 return formatRegisterId(uint16_t(Reg16), Cpu);
325 static std::string formatRange(LocalVariableAddrRange Range) {
326 return formatv("[{0},+{1})",
327 formatSegmentOffset(Range.ISectStart, Range.OffsetStart),
332 static std::string formatGaps(uint32_t IndentLevel,
333 ArrayRef<LocalVariableAddrGap> Gaps) {
334 std::vector<std::string> GapStrs;
335 for (const auto &G : Gaps) {
336 GapStrs.push_back(formatv("({0},{1})", G.GapStartOffset, G.Range).str());
338 return typesetItemList(GapStrs, 7, IndentLevel, ", ");
341 Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record) {
342 return visitSymbolBegin(Record, 0);
345 Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record,
347 // formatLine puts the newline at the beginning, so we use formatLine here
348 // to start a new line, and then individual visit methods use format to
349 // append to the existing line.
350 P.formatLine("{0} | {1} [size = {2}]",
351 fmt_align(Offset, AlignStyle::Right, 6),
352 formatSymbolKind(Record.kind()), Record.length());
354 return Error::success();
357 Error MinimalSymbolDumper::visitSymbolEnd(CVSymbol &Record) {
359 AutoIndent Indent(P, 7);
360 P.formatBinary("bytes", Record.content(), 0);
363 return Error::success();
366 std::string MinimalSymbolDumper::typeOrIdIndex(codeview::TypeIndex TI,
368 if (TI.isSimple() || TI.isDecoratedItemId())
369 return formatv("{0}", TI).str();
370 auto &Container = IsType ? Types : Ids;
371 StringRef Name = Container.getTypeName(TI);
372 if (Name.size() > 32) {
373 Name = Name.take_front(32);
374 return formatv("{0} ({1}...)", TI, Name);
376 return formatv("{0} ({1})", TI, Name);
379 std::string MinimalSymbolDumper::idIndex(codeview::TypeIndex TI) const {
380 return typeOrIdIndex(TI, false);
383 std::string MinimalSymbolDumper::typeIndex(TypeIndex TI) const {
384 return typeOrIdIndex(TI, true);
387 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
388 P.format(" `{0}`", Block.Name);
389 AutoIndent Indent(P, 7);
390 P.formatLine("parent = {0}, end = {1}", Block.Parent, Block.End);
391 P.formatLine("code size = {0}, addr = {1}", Block.CodeSize,
392 formatSegmentOffset(Block.Segment, Block.CodeOffset));
393 return Error::success();
396 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
397 P.format(" `{0}`", Thunk.Name);
398 AutoIndent Indent(P, 7);
399 P.formatLine("parent = {0}, end = {1}, next = {2}", Thunk.Parent, Thunk.End,
401 P.formatLine("kind = {0}, size = {1}, addr = {2}",
402 formatThunkOrdinal(Thunk.Thunk), Thunk.Length,
403 formatSegmentOffset(Thunk.Segment, Thunk.Offset));
405 return Error::success();
408 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
409 TrampolineSym &Tramp) {
410 AutoIndent Indent(P, 7);
411 P.formatLine("type = {0}, size = {1}, source = {2}, target = {3}",
412 formatTrampolineType(Tramp.Type), Tramp.Size,
413 formatSegmentOffset(Tramp.ThunkSection, Tramp.ThunkOffset),
414 formatSegmentOffset(Tramp.TargetSection, Tramp.ThunkOffset));
416 return Error::success();
419 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
420 SectionSym &Section) {
421 P.format(" `{0}`", Section.Name);
422 AutoIndent Indent(P, 7);
423 P.formatLine("length = {0}, alignment = {1}, rva = {2}, section # = {3}",
424 Section.Length, Section.Alignment, Section.Rva,
425 Section.SectionNumber);
426 P.printLine("characteristics =");
427 AutoIndent Indent2(P, 2);
428 P.printLine(formatSectionCharacteristics(P.getIndentLevel(),
429 Section.Characteristics, 1, "",
430 CharacteristicStyle::Descriptive));
431 return Error::success();
434 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CoffGroupSym &CG) {
435 P.format(" `{0}`", CG.Name);
436 AutoIndent Indent(P, 7);
437 P.formatLine("length = {0}, addr = {1}", CG.Size,
438 formatSegmentOffset(CG.Segment, CG.Offset));
439 P.printLine("characteristics =");
440 AutoIndent Indent2(P, 2);
441 P.printLine(formatSectionCharacteristics(P.getIndentLevel(),
442 CG.Characteristics, 1, "",
443 CharacteristicStyle::Descriptive));
444 return Error::success();
447 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
448 BPRelativeSym &BPRel) {
449 P.format(" `{0}`", BPRel.Name);
450 AutoIndent Indent(P, 7);
451 P.formatLine("type = {0}, offset = {1}", typeIndex(BPRel.Type), BPRel.Offset);
452 return Error::success();
455 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
456 BuildInfoSym &BuildInfo) {
457 P.format(" BuildId = `{0}`", BuildInfo.BuildId);
458 return Error::success();
461 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
462 CallSiteInfoSym &CSI) {
463 AutoIndent Indent(P, 7);
464 P.formatLine("type = {0}, addr = {1}", typeIndex(CSI.Type),
465 formatSegmentOffset(CSI.Segment, CSI.CodeOffset));
466 return Error::success();
469 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
470 EnvBlockSym &EnvBlock) {
471 AutoIndent Indent(P, 7);
472 for (const auto &Entry : EnvBlock.Fields) {
473 P.formatLine("- {0}", Entry);
475 return Error::success();
478 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FileStaticSym &FS) {
479 P.format(" `{0}`", FS.Name);
480 AutoIndent Indent(P, 7);
482 Expected<StringRef> FileName =
483 SymGroup->getNameFromStringTable(FS.ModFilenameOffset);
485 P.formatLine("type = {0}, file name = {1} ({2}), flags = {3}",
486 typeIndex(FS.Index), FS.ModFilenameOffset, *FileName,
487 formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));
489 return Error::success();
492 P.formatLine("type = {0}, file name offset = {1}, flags = {2}",
493 typeIndex(FS.Index), FS.ModFilenameOffset,
494 formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));
495 return Error::success();
498 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
499 P.format(" `{0}`", Export.Name);
500 AutoIndent Indent(P, 7);
501 P.formatLine("ordinal = {0}, flags = {1}", Export.Ordinal,
502 formatExportFlags(P.getIndentLevel() + 9, Export.Flags));
503 return Error::success();
506 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
507 Compile2Sym &Compile2) {
508 AutoIndent Indent(P, 7);
509 SourceLanguage Lang = static_cast<SourceLanguage>(
510 Compile2.Flags & CompileSym2Flags::SourceLanguageMask);
511 CompilationCPU = Compile2.Machine;
512 P.formatLine("machine = {0}, ver = {1}, language = {2}",
513 formatMachineType(Compile2.Machine), Compile2.Version,
514 formatSourceLanguage(Lang));
515 P.formatLine("frontend = {0}.{1}.{2}, backend = {3}.{4}.{5}",
516 Compile2.VersionFrontendMajor, Compile2.VersionFrontendMinor,
517 Compile2.VersionFrontendBuild, Compile2.VersionBackendMajor,
518 Compile2.VersionBackendMinor, Compile2.VersionBackendBuild);
519 P.formatLine("flags = {0}",
520 formatCompileSym2Flags(P.getIndentLevel() + 9, Compile2.Flags));
522 "extra strings = {0}",
523 typesetStringList(P.getIndentLevel() + 9 + 2, Compile2.ExtraStrings));
524 return Error::success();
527 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
528 Compile3Sym &Compile3) {
529 AutoIndent Indent(P, 7);
530 SourceLanguage Lang = static_cast<SourceLanguage>(
531 Compile3.Flags & CompileSym3Flags::SourceLanguageMask);
532 CompilationCPU = Compile3.Machine;
533 P.formatLine("machine = {0}, Ver = {1}, language = {2}",
534 formatMachineType(Compile3.Machine), Compile3.Version,
535 formatSourceLanguage(Lang));
536 P.formatLine("frontend = {0}.{1}.{2}.{3}, backend = {4}.{5}.{6}.{7}",
537 Compile3.VersionFrontendMajor, Compile3.VersionFrontendMinor,
538 Compile3.VersionFrontendBuild, Compile3.VersionFrontendQFE,
539 Compile3.VersionBackendMajor, Compile3.VersionBackendMinor,
540 Compile3.VersionBackendBuild, Compile3.VersionBackendQFE);
541 P.formatLine("flags = {0}",
542 formatCompileSym3Flags(P.getIndentLevel() + 9, Compile3.Flags));
543 return Error::success();
546 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
547 ConstantSym &Constant) {
548 P.format(" `{0}`", Constant.Name);
549 AutoIndent Indent(P, 7);
550 P.formatLine("type = {0}, value = {1}", typeIndex(Constant.Type),
551 Constant.Value.toString(10));
552 return Error::success();
555 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
556 P.format(" `{0}`", Data.Name);
557 AutoIndent Indent(P, 7);
558 P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),
559 formatSegmentOffset(Data.Segment, Data.DataOffset));
560 return Error::success();
563 Error MinimalSymbolDumper::visitKnownRecord(
564 CVSymbol &CVR, DefRangeFramePointerRelFullScopeSym &Def) {
565 P.format(" offset = {0}", Def.Offset);
566 return Error::success();
569 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
570 DefRangeFramePointerRelSym &Def) {
571 AutoIndent Indent(P, 7);
572 P.formatLine("offset = {0}, range = {1}", Def.Offset, formatRange(Def.Range));
573 P.formatLine("gaps = {2}", Def.Offset,
574 formatGaps(P.getIndentLevel() + 9, Def.Gaps));
575 return Error::success();
578 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
579 DefRangeRegisterRelSym &Def) {
580 AutoIndent Indent(P, 7);
581 P.formatLine("register = {0}, offset = {1}, offset in parent = {2}, has "
583 formatRegisterId(Def.Hdr.Register, CompilationCPU),
584 int32_t(Def.Hdr.BasePointerOffset), Def.offsetInParent(),
585 Def.hasSpilledUDTMember());
586 P.formatLine("range = {0}, gaps = {1}", formatRange(Def.Range),
587 formatGaps(P.getIndentLevel() + 9, Def.Gaps));
588 return Error::success();
591 Error MinimalSymbolDumper::visitKnownRecord(
592 CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
593 AutoIndent Indent(P, 7);
594 P.formatLine("register = {0}, may have no name = {1}, range start = "
596 formatRegisterId(DefRangeRegister.Hdr.Register, CompilationCPU),
597 bool(DefRangeRegister.Hdr.MayHaveNoName),
598 formatSegmentOffset(DefRangeRegister.Range.ISectStart,
599 DefRangeRegister.Range.OffsetStart),
600 DefRangeRegister.Range.Range);
601 P.formatLine("gaps = [{0}]",
602 formatGaps(P.getIndentLevel() + 9, DefRangeRegister.Gaps));
603 return Error::success();
606 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
607 DefRangeSubfieldRegisterSym &Def) {
608 AutoIndent Indent(P, 7);
609 bool NoName = !!(Def.Hdr.MayHaveNoName == 0);
610 P.formatLine("register = {0}, may have no name = {1}, offset in parent = {2}",
611 formatRegisterId(Def.Hdr.Register, CompilationCPU), NoName,
612 uint32_t(Def.Hdr.OffsetInParent));
613 P.formatLine("range = {0}, gaps = {1}", formatRange(Def.Range),
614 formatGaps(P.getIndentLevel() + 9, Def.Gaps));
615 return Error::success();
618 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
619 DefRangeSubfieldSym &Def) {
620 AutoIndent Indent(P, 7);
621 P.formatLine("program = {0}, offset in parent = {1}, range = {2}",
622 Def.Program, Def.OffsetInParent, formatRange(Def.Range));
623 P.formatLine("gaps = {0}", formatGaps(P.getIndentLevel() + 9, Def.Gaps));
624 return Error::success();
627 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DefRangeSym &Def) {
628 AutoIndent Indent(P, 7);
629 P.formatLine("program = {0}, range = {1}", Def.Program,
630 formatRange(Def.Range));
631 P.formatLine("gaps = {0}", formatGaps(P.getIndentLevel() + 9, Def.Gaps));
632 return Error::success();
635 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameCookieSym &FC) {
636 AutoIndent Indent(P, 7);
637 P.formatLine("code offset = {0}, Register = {1}, kind = {2}, flags = {3}",
638 FC.CodeOffset, formatRegisterId(FC.Register, CompilationCPU),
639 formatCookieKind(FC.CookieKind), FC.Flags);
640 return Error::success();
643 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameProcSym &FP) {
644 AutoIndent Indent(P, 7);
645 P.formatLine("size = {0}, padding size = {1}, offset to padding = {2}",
646 FP.TotalFrameBytes, FP.PaddingFrameBytes, FP.OffsetToPadding);
647 P.formatLine("bytes of callee saved registers = {0}, exception handler addr "
649 FP.BytesOfCalleeSavedRegisters,
650 formatSegmentOffset(FP.SectionIdOfExceptionHandler,
651 FP.OffsetOfExceptionHandler));
653 "local fp reg = {0}, param fp reg = {1}",
654 formatRegisterId(FP.getLocalFramePtrReg(CompilationCPU), CompilationCPU),
655 formatRegisterId(FP.getParamFramePtrReg(CompilationCPU), CompilationCPU));
656 P.formatLine("flags = {0}",
657 formatFrameProcedureOptions(P.getIndentLevel() + 9, FP.Flags));
658 return Error::success();
661 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
662 HeapAllocationSiteSym &HAS) {
663 AutoIndent Indent(P, 7);
664 P.formatLine("type = {0}, addr = {1} call size = {2}", typeIndex(HAS.Type),
665 formatSegmentOffset(HAS.Segment, HAS.CodeOffset),
666 HAS.CallInstructionSize);
667 return Error::success();
670 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, InlineSiteSym &IS) {
671 AutoIndent Indent(P, 7);
672 P.formatLine("inlinee = {0}, parent = {1}, end = {2}", idIndex(IS.Inlinee),
675 // Break down the annotation byte code and calculate code and line offsets.
676 // FIXME: It would be helpful if we could look up the initial file and inlinee
677 // lines offset using the inlinee index above.
678 uint32_t CodeOffset = 0;
679 int32_t LineOffset = 0;
680 for (auto &Annot : IS.annotations()) {
681 P.formatLine(" {0}", fmt_align(toHex(Annot.Bytes), AlignStyle::Left, 9));
683 auto formatCodeOffset = [&](uint32_t Delta) {
685 P.format(" code 0x{0} (+0x{1})", utohexstr(CodeOffset), utohexstr(Delta));
687 auto formatCodeLength = [&](uint32_t Length) {
688 // Notably, changing the code length does not affect the code offset.
689 P.format(" code end 0x{0} (+0x{1})", utohexstr(CodeOffset + Length),
692 auto formatLineOffset = [&](int32_t Delta) {
694 char Sign = Delta > 0 ? '+' : '-';
695 P.format(" line {0} ({1}{2})", LineOffset, Sign, std::abs(Delta));
698 // Use the opcode to interpret the integer values.
699 switch (Annot.OpCode) {
700 case BinaryAnnotationsOpCode::Invalid:
702 case BinaryAnnotationsOpCode::CodeOffset:
703 case BinaryAnnotationsOpCode::ChangeCodeOffset:
704 formatCodeOffset(Annot.U1);
706 case BinaryAnnotationsOpCode::ChangeLineOffset:
707 formatLineOffset(Annot.S1);
709 case BinaryAnnotationsOpCode::ChangeCodeLength:
710 formatCodeLength(Annot.U1);
711 // Apparently this annotation updates the code offset. It's hard to make
712 // MSVC produce this opcode, but clang uses it, and debuggers seem to use
713 // this interpretation.
714 CodeOffset += Annot.U1;
716 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
717 formatCodeOffset(Annot.U1);
718 formatLineOffset(Annot.S1);
720 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
721 formatCodeOffset(Annot.U2);
722 formatCodeLength(Annot.U1);
725 case BinaryAnnotationsOpCode::ChangeFile: {
726 uint32_t FileOffset = Annot.U1;
727 StringRef Filename = "<unknown>";
729 if (Expected<StringRef> MaybeFile =
730 SymGroup->getNameFromStringTable(FileOffset))
731 Filename = *MaybeFile;
733 return MaybeFile.takeError();
735 P.format(" setfile {0} 0x{1}", utohexstr(FileOffset));
739 // The rest of these are hard to convince MSVC to emit, so they are not as
741 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
742 formatCodeOffset(Annot.U1);
744 case BinaryAnnotationsOpCode::ChangeLineEndDelta:
745 case BinaryAnnotationsOpCode::ChangeRangeKind:
746 case BinaryAnnotationsOpCode::ChangeColumnStart:
747 case BinaryAnnotationsOpCode::ChangeColumnEnd:
748 P.format(" {0} {1}", Annot.Name, Annot.U1);
750 case BinaryAnnotationsOpCode::ChangeColumnEndDelta:
751 P.format(" {0} {1}", Annot.Name, Annot.S1);
755 return Error::success();
758 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
759 RegisterSym &Register) {
760 P.format(" `{0}`", Register.Name);
761 AutoIndent Indent(P, 7);
762 P.formatLine("register = {0}, type = {1}",
763 formatRegisterId(Register.Register, CompilationCPU),
764 typeIndex(Register.Index));
765 return Error::success();
768 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
769 PublicSym32 &Public) {
770 P.format(" `{0}`", Public.Name);
771 AutoIndent Indent(P, 7);
772 P.formatLine("flags = {0}, addr = {1}",
773 formatPublicSymFlags(P.getIndentLevel() + 9, Public.Flags),
774 formatSegmentOffset(Public.Segment, Public.Offset));
775 return Error::success();
778 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcRefSym &PR) {
779 P.format(" `{0}`", PR.Name);
780 AutoIndent Indent(P, 7);
781 P.formatLine("module = {0}, sum name = {1}, offset = {2}", PR.Module,
782 PR.SumName, PR.SymOffset);
783 return Error::success();
786 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
787 P.format(" `{0}` (addr = {1})", Label.Name,
788 formatSegmentOffset(Label.Segment, Label.CodeOffset));
789 AutoIndent Indent(P, 7);
790 P.formatLine("flags = {0}",
791 formatProcSymFlags(P.getIndentLevel() + 9, Label.Flags));
792 return Error::success();
795 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
796 P.format(" `{0}`", Local.Name);
797 AutoIndent Indent(P, 7);
799 std::string FlagStr =
800 formatLocalSymFlags(P.getIndentLevel() + 9, Local.Flags);
801 P.formatLine("type={0}, flags = {1}", typeIndex(Local.Type), FlagStr);
802 return Error::success();
805 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
806 ObjNameSym &ObjName) {
807 P.format(" sig={0}, `{1}`", ObjName.Signature, ObjName.Name);
808 return Error::success();
811 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
812 P.format(" `{0}`", Proc.Name);
813 AutoIndent Indent(P, 7);
814 P.formatLine("parent = {0}, end = {1}, addr = {2}, code size = {3}",
815 Proc.Parent, Proc.End,
816 formatSegmentOffset(Proc.Segment, Proc.CodeOffset),
819 switch (Proc.getKind()) {
820 case SymbolRecordKind::GlobalProcIdSym:
821 case SymbolRecordKind::ProcIdSym:
822 case SymbolRecordKind::DPCProcIdSym:
828 P.formatLine("type = `{0}`, debug start = {1}, debug end = {2}, flags = {3}",
829 typeOrIdIndex(Proc.FunctionType, IsType), Proc.DbgStart,
831 formatProcSymFlags(P.getIndentLevel() + 9, Proc.Flags));
832 return Error::success();
835 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
836 ScopeEndSym &ScopeEnd) {
837 return Error::success();
840 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
841 AutoIndent Indent(P, 7);
842 for (const auto &I : Caller.Indices) {
843 P.formatLine("callee: {0}", idIndex(I));
845 return Error::success();
848 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
849 RegRelativeSym &RegRel) {
850 P.format(" `{0}`", RegRel.Name);
851 AutoIndent Indent(P, 7);
853 "type = {0}, register = {1}, offset = {2}", typeIndex(RegRel.Type),
854 formatRegisterId(RegRel.Register, CompilationCPU), RegRel.Offset);
855 return Error::success();
858 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
859 ThreadLocalDataSym &Data) {
860 P.format(" `{0}`", Data.Name);
861 AutoIndent Indent(P, 7);
862 P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),
863 formatSegmentOffset(Data.Segment, Data.DataOffset));
864 return Error::success();
867 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
868 P.format(" `{0}`", UDT.Name);
869 AutoIndent Indent(P, 7);
870 P.formatLine("original type = {0}", UDT.Type);
871 return Error::success();
874 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
875 UsingNamespaceSym &UN) {
876 P.format(" `{0}`", UN.Name);
877 return Error::success();
880 Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
881 AnnotationSym &Annot) {
882 AutoIndent Indent(P, 7);
883 P.formatLine("addr = {0}", formatSegmentOffset(Annot.Segment, Annot.CodeOffset));
884 P.formatLine("strings = {0}", typesetStringList(P.getIndentLevel() + 9 + 2,
886 return Error::success();