1//===- MinimalSymbolDumper.cpp -------------------------------- *- 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 "MinimalSymbolDumper.h"
10
11#include "llvm/ADT/StringExtras.h"
12#include "llvm/DebugInfo/CodeView/CVRecord.h"
13#include "llvm/DebugInfo/CodeView/CodeView.h"
14#include "llvm/DebugInfo/CodeView/Formatters.h"
15#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
16#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
17#include "llvm/DebugInfo/CodeView/TypeRecord.h"
18#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
19#include "llvm/DebugInfo/PDB/Native/InputFile.h"
20#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
21#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
22#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
23#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
24#include "llvm/Object/COFF.h"
25#include "llvm/Support/FormatVariadic.h"
26
27using namespace llvm;
28using namespace llvm::codeview;
29using namespace llvm::pdb;
30
31static std::string formatLocalSymFlags(uint32_t IndentLevel,
32 LocalSymFlags Flags) {
33 std::vector<std::string> Opts;
34 if (Flags == LocalSymFlags::None)
35 return "none";
36
37 PUSH_FLAG(LocalSymFlags, IsParameter, Flags, "param");
38 PUSH_FLAG(LocalSymFlags, IsAddressTaken, Flags, "address is taken");
39 PUSH_FLAG(LocalSymFlags, IsCompilerGenerated, Flags, "compiler generated");
40 PUSH_FLAG(LocalSymFlags, IsAggregate, Flags, "aggregate");
41 PUSH_FLAG(LocalSymFlags, IsAggregated, Flags, "aggregated");
42 PUSH_FLAG(LocalSymFlags, IsAliased, Flags, "aliased");
43 PUSH_FLAG(LocalSymFlags, IsAlias, Flags, "alias");
44 PUSH_FLAG(LocalSymFlags, IsReturnValue, Flags, "return val");
45 PUSH_FLAG(LocalSymFlags, IsOptimizedOut, Flags, "optimized away");
46 PUSH_FLAG(LocalSymFlags, IsEnregisteredGlobal, Flags, "enreg global");
47 PUSH_FLAG(LocalSymFlags, IsEnregisteredStatic, Flags, "enreg static");
48 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
49}
50
51static std::string formatExportFlags(uint32_t IndentLevel, ExportFlags Flags) {
52 std::vector<std::string> Opts;
53 if (Flags == ExportFlags::None)
54 return "none";
55
56 PUSH_FLAG(ExportFlags, IsConstant, Flags, "constant");
57 PUSH_FLAG(ExportFlags, IsData, Flags, "data");
58 PUSH_FLAG(ExportFlags, IsPrivate, Flags, "private");
59 PUSH_FLAG(ExportFlags, HasNoName, Flags, "no name");
60 PUSH_FLAG(ExportFlags, HasExplicitOrdinal, Flags, "explicit ord");
61 PUSH_FLAG(ExportFlags, IsForwarder, Flags, "forwarder");
62
63 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
64}
65
66static std::string formatCompileSym2Flags(uint32_t IndentLevel,
67 CompileSym2Flags Flags) {
68 std::vector<std::string> Opts;
69 Flags &= ~CompileSym2Flags::SourceLanguageMask;
70 if (Flags == CompileSym2Flags::None)
71 return "none";
72
73 PUSH_FLAG(CompileSym2Flags, EC, Flags, "edit and continue");
74 PUSH_FLAG(CompileSym2Flags, NoDbgInfo, Flags, "no dbg info");
75 PUSH_FLAG(CompileSym2Flags, LTCG, Flags, "ltcg");
76 PUSH_FLAG(CompileSym2Flags, NoDataAlign, Flags, "no data align");
77 PUSH_FLAG(CompileSym2Flags, ManagedPresent, Flags, "has managed code");
78 PUSH_FLAG(CompileSym2Flags, SecurityChecks, Flags, "security checks");
79 PUSH_FLAG(CompileSym2Flags, HotPatch, Flags, "hot patchable");
80 PUSH_FLAG(CompileSym2Flags, CVTCIL, Flags, "cvtcil");
81 PUSH_FLAG(CompileSym2Flags, MSILModule, Flags, "msil module");
82 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
83}
84
85static std::string formatCompileSym3Flags(uint32_t IndentLevel,
86 CompileSym3Flags Flags) {
87 std::vector<std::string> Opts;
88 Flags &= ~CompileSym3Flags::SourceLanguageMask;
89
90 if (Flags == CompileSym3Flags::None)
91 return "none";
92
93 PUSH_FLAG(CompileSym3Flags, EC, Flags, "edit and continue");
94 PUSH_FLAG(CompileSym3Flags, NoDbgInfo, Flags, "no dbg info");
95 PUSH_FLAG(CompileSym3Flags, LTCG, Flags, "ltcg");
96 PUSH_FLAG(CompileSym3Flags, NoDataAlign, Flags, "no data align");
97 PUSH_FLAG(CompileSym3Flags, ManagedPresent, Flags, "has managed code");
98 PUSH_FLAG(CompileSym3Flags, SecurityChecks, Flags, "security checks");
99 PUSH_FLAG(CompileSym3Flags, HotPatch, Flags, "hot patchable");
100 PUSH_FLAG(CompileSym3Flags, CVTCIL, Flags, "cvtcil");
101 PUSH_FLAG(CompileSym3Flags, MSILModule, Flags, "msil module");
102 PUSH_FLAG(CompileSym3Flags, Sdl, Flags, "sdl");
103 PUSH_FLAG(CompileSym3Flags, PGO, Flags, "pgo");
104 PUSH_FLAG(CompileSym3Flags, Exp, Flags, "exp");
105 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
106}
107
108static std::string formatFrameProcedureOptions(uint32_t IndentLevel,
109 FrameProcedureOptions FPO) {
110 std::vector<std::string> Opts;
111 if (FPO == FrameProcedureOptions::None)
112 return "none";
113
114 PUSH_FLAG(FrameProcedureOptions, HasAlloca, FPO, "has alloca");
115 PUSH_FLAG(FrameProcedureOptions, HasSetJmp, FPO, "has setjmp");
116 PUSH_FLAG(FrameProcedureOptions, HasLongJmp, FPO, "has longjmp");
117 PUSH_FLAG(FrameProcedureOptions, HasInlineAssembly, FPO, "has inline asm");
118 PUSH_FLAG(FrameProcedureOptions, HasExceptionHandling, FPO, "has eh");
119 PUSH_FLAG(FrameProcedureOptions, MarkedInline, FPO, "marked inline");
120 PUSH_FLAG(FrameProcedureOptions, HasStructuredExceptionHandling, FPO,
121 "has seh");
122 PUSH_FLAG(FrameProcedureOptions, Naked, FPO, "naked");
123 PUSH_FLAG(FrameProcedureOptions, SecurityChecks, FPO, "secure checks");
124 PUSH_FLAG(FrameProcedureOptions, AsynchronousExceptionHandling, FPO,
125 "has async eh");
126 PUSH_FLAG(FrameProcedureOptions, NoStackOrderingForSecurityChecks, FPO,
127 "no stack order");
128 PUSH_FLAG(FrameProcedureOptions, Inlined, FPO, "inlined");
129 PUSH_FLAG(FrameProcedureOptions, StrictSecurityChecks, FPO,
130 "strict secure checks");
131 PUSH_FLAG(FrameProcedureOptions, SafeBuffers, FPO, "safe buffers");
132 PUSH_FLAG(FrameProcedureOptions, ProfileGuidedOptimization, FPO, "pgo");
133 PUSH_FLAG(FrameProcedureOptions, ValidProfileCounts, FPO,
134 "has profile counts");
135 PUSH_FLAG(FrameProcedureOptions, OptimizedForSpeed, FPO, "opt speed");
136 PUSH_FLAG(FrameProcedureOptions, GuardCfg, FPO, "guard cfg");
137 PUSH_FLAG(FrameProcedureOptions, GuardCfw, FPO, "guard cfw");
138 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
139}
140
141static std::string formatPublicSymFlags(uint32_t IndentLevel,
142 PublicSymFlags Flags) {
143 std::vector<std::string> Opts;
144 if (Flags == PublicSymFlags::None)
145 return "none";
146
147 PUSH_FLAG(PublicSymFlags, Code, Flags, "code");
148 PUSH_FLAG(PublicSymFlags, Function, Flags, "function");
149 PUSH_FLAG(PublicSymFlags, Managed, Flags, "managed");
150 PUSH_FLAG(PublicSymFlags, MSIL, Flags, "msil");
151 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
152}
153
154static std::string formatProcSymFlags(uint32_t IndentLevel,
155 ProcSymFlags Flags) {
156 std::vector<std::string> Opts;
157 if (Flags == ProcSymFlags::None)
158 return "none";
159
160 PUSH_FLAG(ProcSymFlags, HasFP, Flags, "has fp");
161 PUSH_FLAG(ProcSymFlags, HasIRET, Flags, "has iret");
162 PUSH_FLAG(ProcSymFlags, HasFRET, Flags, "has fret");
163 PUSH_FLAG(ProcSymFlags, IsNoReturn, Flags, "noreturn");
164 PUSH_FLAG(ProcSymFlags, IsUnreachable, Flags, "unreachable");
165 PUSH_FLAG(ProcSymFlags, HasCustomCallingConv, Flags, "custom calling conv");
166 PUSH_FLAG(ProcSymFlags, IsNoInline, Flags, "noinline");
167 PUSH_FLAG(ProcSymFlags, HasOptimizedDebugInfo, Flags, "opt debuginfo");
168 return typesetItemList(Opts, IndentLevel: 4, GroupSize: IndentLevel, Sep: " | ");
169}
170
171static std::string formatThunkOrdinal(ThunkOrdinal Ordinal) {
172 switch (Ordinal) {
173 RETURN_CASE(ThunkOrdinal, Standard, "thunk");
174 RETURN_CASE(ThunkOrdinal, ThisAdjustor, "this adjustor");
175 RETURN_CASE(ThunkOrdinal, Vcall, "vcall");
176 RETURN_CASE(ThunkOrdinal, Pcode, "pcode");
177 RETURN_CASE(ThunkOrdinal, UnknownLoad, "unknown load");
178 RETURN_CASE(ThunkOrdinal, TrampIncremental, "tramp incremental");
179 RETURN_CASE(ThunkOrdinal, BranchIsland, "branch island");
180 }
181 return formatUnknownEnum(Value: Ordinal);
182}
183
184static std::string formatTrampolineType(TrampolineType Tramp) {
185 switch (Tramp) {
186 RETURN_CASE(TrampolineType, TrampIncremental, "tramp incremental");
187 RETURN_CASE(TrampolineType, BranchIsland, "branch island");
188 }
189 return formatUnknownEnum(Value: Tramp);
190}
191
192static std::string formatSourceLanguage(SourceLanguage Lang) {
193 switch (Lang) {
194 RETURN_CASE(SourceLanguage, C, "c");
195 RETURN_CASE(SourceLanguage, Cpp, "c++");
196 RETURN_CASE(SourceLanguage, Fortran, "fortran");
197 RETURN_CASE(SourceLanguage, Masm, "masm");
198 RETURN_CASE(SourceLanguage, Pascal, "pascal");
199 RETURN_CASE(SourceLanguage, Basic, "basic");
200 RETURN_CASE(SourceLanguage, Cobol, "cobol");
201 RETURN_CASE(SourceLanguage, Link, "link");
202 RETURN_CASE(SourceLanguage, VB, "vb");
203 RETURN_CASE(SourceLanguage, Cvtres, "cvtres");
204 RETURN_CASE(SourceLanguage, Cvtpgd, "cvtpgd");
205 RETURN_CASE(SourceLanguage, CSharp, "c#");
206 RETURN_CASE(SourceLanguage, ILAsm, "il asm");
207 RETURN_CASE(SourceLanguage, Java, "java");
208 RETURN_CASE(SourceLanguage, JScript, "javascript");
209 RETURN_CASE(SourceLanguage, MSIL, "msil");
210 RETURN_CASE(SourceLanguage, HLSL, "hlsl");
211 RETURN_CASE(SourceLanguage, D, "d");
212 RETURN_CASE(SourceLanguage, Swift, "swift");
213 RETURN_CASE(SourceLanguage, Rust, "rust");
214 RETURN_CASE(SourceLanguage, ObjC, "objc");
215 RETURN_CASE(SourceLanguage, ObjCpp, "objc++");
216 RETURN_CASE(SourceLanguage, AliasObj, "aliasobj");
217 RETURN_CASE(SourceLanguage, Go, "go");
218 RETURN_CASE(SourceLanguage, OldSwift, "swift");
219 }
220 return formatUnknownEnum(Value: Lang);
221}
222
223static std::string formatMachineType(CPUType Cpu) {
224 switch (Cpu) {
225 RETURN_CASE(CPUType, Intel8080, "intel 8080");
226 RETURN_CASE(CPUType, Intel8086, "intel 8086");
227 RETURN_CASE(CPUType, Intel80286, "intel 80286");
228 RETURN_CASE(CPUType, Intel80386, "intel 80386");
229 RETURN_CASE(CPUType, Intel80486, "intel 80486");
230 RETURN_CASE(CPUType, Pentium, "intel pentium");
231 RETURN_CASE(CPUType, PentiumPro, "intel pentium pro");
232 RETURN_CASE(CPUType, Pentium3, "intel pentium 3");
233 RETURN_CASE(CPUType, MIPS, "mips");
234 RETURN_CASE(CPUType, MIPS16, "mips-16");
235 RETURN_CASE(CPUType, MIPS32, "mips-32");
236 RETURN_CASE(CPUType, MIPS64, "mips-64");
237 RETURN_CASE(CPUType, MIPSI, "mips i");
238 RETURN_CASE(CPUType, MIPSII, "mips ii");
239 RETURN_CASE(CPUType, MIPSIII, "mips iii");
240 RETURN_CASE(CPUType, MIPSIV, "mips iv");
241 RETURN_CASE(CPUType, MIPSV, "mips v");
242 RETURN_CASE(CPUType, M68000, "motorola 68000");
243 RETURN_CASE(CPUType, M68010, "motorola 68010");
244 RETURN_CASE(CPUType, M68020, "motorola 68020");
245 RETURN_CASE(CPUType, M68030, "motorola 68030");
246 RETURN_CASE(CPUType, M68040, "motorola 68040");
247 RETURN_CASE(CPUType, Alpha, "alpha");
248 RETURN_CASE(CPUType, Alpha21164, "alpha 21164");
249 RETURN_CASE(CPUType, Alpha21164A, "alpha 21164a");
250 RETURN_CASE(CPUType, Alpha21264, "alpha 21264");
251 RETURN_CASE(CPUType, Alpha21364, "alpha 21364");
252 RETURN_CASE(CPUType, PPC601, "powerpc 601");
253 RETURN_CASE(CPUType, PPC603, "powerpc 603");
254 RETURN_CASE(CPUType, PPC604, "powerpc 604");
255 RETURN_CASE(CPUType, PPC620, "powerpc 620");
256 RETURN_CASE(CPUType, PPCFP, "powerpc fp");
257 RETURN_CASE(CPUType, PPCBE, "powerpc be");
258 RETURN_CASE(CPUType, SH3, "sh3");
259 RETURN_CASE(CPUType, SH3E, "sh3e");
260 RETURN_CASE(CPUType, SH3DSP, "sh3 dsp");
261 RETURN_CASE(CPUType, SH4, "sh4");
262 RETURN_CASE(CPUType, SHMedia, "shmedia");
263 RETURN_CASE(CPUType, ARM3, "arm 3");
264 RETURN_CASE(CPUType, ARM4, "arm 4");
265 RETURN_CASE(CPUType, ARM4T, "arm 4t");
266 RETURN_CASE(CPUType, ARM5, "arm 5");
267 RETURN_CASE(CPUType, ARM5T, "arm 5t");
268 RETURN_CASE(CPUType, ARM6, "arm 6");
269 RETURN_CASE(CPUType, ARM_XMAC, "arm xmac");
270 RETURN_CASE(CPUType, ARM_WMMX, "arm wmmx");
271 RETURN_CASE(CPUType, ARM7, "arm 7");
272 RETURN_CASE(CPUType, ARM64, "arm64");
273 RETURN_CASE(CPUType, ARM64EC, "arm64ec");
274 RETURN_CASE(CPUType, ARM64X, "arm64x");
275 RETURN_CASE(CPUType, HybridX86ARM64, "hybrid x86 arm64");
276 RETURN_CASE(CPUType, Omni, "omni");
277 RETURN_CASE(CPUType, Ia64, "intel itanium ia64");
278 RETURN_CASE(CPUType, Ia64_2, "intel itanium ia64 2");
279 RETURN_CASE(CPUType, CEE, "cee");
280 RETURN_CASE(CPUType, AM33, "am33");
281 RETURN_CASE(CPUType, M32R, "m32r");
282 RETURN_CASE(CPUType, TriCore, "tri-core");
283 RETURN_CASE(CPUType, X64, "intel x86-x64");
284 RETURN_CASE(CPUType, EBC, "ebc");
285 RETURN_CASE(CPUType, Thumb, "thumb");
286 RETURN_CASE(CPUType, ARMNT, "arm nt");
287 RETURN_CASE(CPUType, D3D11_Shader, "d3d11 shader");
288 RETURN_CASE(CPUType, Unknown, "unknown");
289 }
290 return formatUnknownEnum(Value: Cpu);
291}
292
293static std::string formatCookieKind(FrameCookieKind Kind) {
294 switch (Kind) {
295 RETURN_CASE(FrameCookieKind, Copy, "copy");
296 RETURN_CASE(FrameCookieKind, XorStackPointer, "xor stack ptr");
297 RETURN_CASE(FrameCookieKind, XorFramePointer, "xor frame ptr");
298 RETURN_CASE(FrameCookieKind, XorR13, "xor rot13");
299 }
300 return formatUnknownEnum(Value: Kind);
301}
302
303static std::string formatRegisterId(RegisterId Id, CPUType Cpu) {
304 if (Cpu == CPUType::ARMNT) {
305 switch (Id) {
306#define CV_REGISTERS_ARM
307#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
308#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
309#undef CV_REGISTER
310#undef CV_REGISTERS_ARM
311
312 default:
313 break;
314 }
315 } else if (Cpu == CPUType::ARM64) {
316 switch (Id) {
317#define CV_REGISTERS_ARM64
318#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
319#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
320#undef CV_REGISTER
321#undef CV_REGISTERS_ARM64
322
323 default:
324 break;
325 }
326 } else {
327 switch (Id) {
328#define CV_REGISTERS_X86
329#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)
330#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
331#undef CV_REGISTER
332#undef CV_REGISTERS_X86
333
334 default:
335 break;
336 }
337 }
338 return formatUnknownEnum(Value: Id);
339}
340
341static std::string formatRegisterId(uint16_t Reg16, CPUType Cpu) {
342 return formatRegisterId(Id: RegisterId(Reg16), Cpu);
343}
344
345static std::string formatRegisterId(ulittle16_t &Reg16, CPUType Cpu) {
346 return formatRegisterId(Reg16: uint16_t(Reg16), Cpu);
347}
348
349static std::string formatRange(LocalVariableAddrRange Range) {
350 return formatv(Fmt: "[{0},+{1})",
351 Vals: formatSegmentOffset(Segment: Range.ISectStart, Offset: Range.OffsetStart),
352 Vals&: Range.Range)
353 .str();
354}
355
356static std::string formatGaps(uint32_t IndentLevel,
357 ArrayRef<LocalVariableAddrGap> Gaps) {
358 std::vector<std::string> GapStrs;
359 for (const auto &G : Gaps) {
360 GapStrs.push_back(x: formatv(Fmt: "({0},{1})", Vals: G.GapStartOffset, Vals: G.Range).str());
361 }
362 return typesetItemList(Opts: GapStrs, IndentLevel: 7, GroupSize: IndentLevel, Sep: ", ");
363}
364
365static std::string formatJumpTableEntrySize(JumpTableEntrySize EntrySize) {
366 switch (EntrySize) {
367 RETURN_CASE(JumpTableEntrySize, Int8, "int8");
368 RETURN_CASE(JumpTableEntrySize, UInt8, "uin8");
369 RETURN_CASE(JumpTableEntrySize, Int16, "int16");
370 RETURN_CASE(JumpTableEntrySize, UInt16, "uint16");
371 RETURN_CASE(JumpTableEntrySize, Int32, "int32");
372 RETURN_CASE(JumpTableEntrySize, UInt32, "uint32");
373 RETURN_CASE(JumpTableEntrySize, Pointer, "pointer");
374 RETURN_CASE(JumpTableEntrySize, UInt8ShiftLeft, "uint8shl");
375 RETURN_CASE(JumpTableEntrySize, UInt16ShiftLeft, "uint16shl");
376 RETURN_CASE(JumpTableEntrySize, Int8ShiftLeft, "int8shl");
377 RETURN_CASE(JumpTableEntrySize, Int16ShiftLeft, "int16shl");
378 }
379 return formatUnknownEnum(Value: EntrySize);
380}
381
382Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record) {
383 return visitSymbolBegin(Record, Offset: 0);
384}
385
386Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record,
387 uint32_t Offset) {
388 // formatLine puts the newline at the beginning, so we use formatLine here
389 // to start a new line, and then individual visit methods use format to
390 // append to the existing line.
391 P.formatLine(Fmt: "{0} | {1} [size = {2}]",
392 Items: fmt_align(Item&: Offset, Where: AlignStyle::Right, Amount: 6),
393 Items: formatSymbolKind(K: Record.kind()), Items: Record.length());
394 P.Indent();
395 return Error::success();
396}
397
398Error MinimalSymbolDumper::visitSymbolEnd(CVSymbol &Record) {
399 if (RecordBytes)
400 printSymbolBytes(Record);
401 P.Unindent();
402 return Error::success();
403}
404
405Error MinimalSymbolDumper::visitUnknownSymbol(CVSymbol &Record) {
406 if (!RecordBytes)
407 printSymbolBytes(Record);
408 return Error::success();
409}
410
411void MinimalSymbolDumper::printSymbolBytes(CVSymbol &Record) const {
412 AutoIndent Indent(P, 7);
413 P.formatBinary(Label: "bytes", Data: Record.content(), StartOffset: 0);
414}
415
416std::string MinimalSymbolDumper::typeOrIdIndex(codeview::TypeIndex TI,
417 bool IsType) const {
418 if (TI.isSimple() || TI.isDecoratedItemId())
419 return formatv(Fmt: "{0}", Vals&: TI).str();
420 auto &Container = IsType ? Types : Ids;
421 StringRef Name = Container.getTypeName(Index: TI);
422 if (Name.size() > 32) {
423 Name = Name.take_front(N: 32);
424 return std::string(formatv(Fmt: "{0} ({1}...)", Vals&: TI, Vals&: Name));
425 } else
426 return std::string(formatv(Fmt: "{0} ({1})", Vals&: TI, Vals&: Name));
427}
428
429std::string MinimalSymbolDumper::idIndex(codeview::TypeIndex TI) const {
430 return typeOrIdIndex(TI, IsType: false);
431}
432
433std::string MinimalSymbolDumper::typeIndex(TypeIndex TI) const {
434 return typeOrIdIndex(TI, IsType: true);
435}
436
437Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
438 P.format(Fmt: " `{0}`", Items&: Block.Name);
439 AutoIndent Indent(P, 7);
440 P.formatLine(Fmt: "parent = {0}, end = {1}", Items&: Block.Parent, Items&: Block.End);
441 P.formatLine(Fmt: "code size = {0}, addr = {1}", Items&: Block.CodeSize,
442 Items: formatSegmentOffset(Segment: Block.Segment, Offset: Block.CodeOffset));
443 return Error::success();
444}
445
446Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
447 P.format(Fmt: " `{0}`", Items&: Thunk.Name);
448 AutoIndent Indent(P, 7);
449 P.formatLine(Fmt: "parent = {0}, end = {1}, next = {2}", Items&: Thunk.Parent, Items&: Thunk.End,
450 Items&: Thunk.Next);
451 P.formatLine(Fmt: "kind = {0}, size = {1}, addr = {2}",
452 Items: formatThunkOrdinal(Ordinal: Thunk.Thunk), Items&: Thunk.Length,
453 Items: formatSegmentOffset(Segment: Thunk.Segment, Offset: Thunk.Offset));
454
455 return Error::success();
456}
457
458Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
459 TrampolineSym &Tramp) {
460 AutoIndent Indent(P, 7);
461 P.formatLine(Fmt: "type = {0}, size = {1}, source = {2}, target = {3}",
462 Items: formatTrampolineType(Tramp: Tramp.Type), Items&: Tramp.Size,
463 Items: formatSegmentOffset(Segment: Tramp.ThunkSection, Offset: Tramp.ThunkOffset),
464 Items: formatSegmentOffset(Segment: Tramp.TargetSection, Offset: Tramp.ThunkOffset));
465
466 return Error::success();
467}
468
469Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
470 SectionSym &Section) {
471 P.format(Fmt: " `{0}`", Items&: Section.Name);
472 AutoIndent Indent(P, 7);
473 P.formatLine(Fmt: "length = {0}, alignment = {1}, rva = {2}, section # = {3}",
474 Items&: Section.Length, Items&: Section.Alignment, Items&: Section.Rva,
475 Items&: Section.SectionNumber);
476 P.printLine(T: "characteristics =");
477 AutoIndent Indent2(P, 2);
478 P.printLine(T: formatSectionCharacteristics(IndentLevel: P.getIndentLevel(),
479 C: Section.Characteristics, FlagsPerLine: 1, Separator: "",
480 Style: CharacteristicStyle::Descriptive));
481 return Error::success();
482}
483
484Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CoffGroupSym &CG) {
485 P.format(Fmt: " `{0}`", Items&: CG.Name);
486 AutoIndent Indent(P, 7);
487 P.formatLine(Fmt: "length = {0}, addr = {1}", Items&: CG.Size,
488 Items: formatSegmentOffset(Segment: CG.Segment, Offset: CG.Offset));
489 P.printLine(T: "characteristics =");
490 AutoIndent Indent2(P, 2);
491 P.printLine(T: formatSectionCharacteristics(IndentLevel: P.getIndentLevel(),
492 C: CG.Characteristics, FlagsPerLine: 1, Separator: "",
493 Style: CharacteristicStyle::Descriptive));
494 return Error::success();
495}
496
497Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
498 BPRelativeSym &BPRel) {
499 P.format(Fmt: " `{0}`", Items&: BPRel.Name);
500 AutoIndent Indent(P, 7);
501 P.formatLine(Fmt: "type = {0}, offset = {1}", Items: typeIndex(TI: BPRel.Type), Items&: BPRel.Offset);
502 return Error::success();
503}
504
505Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
506 BuildInfoSym &BuildInfo) {
507 P.format(Fmt: " BuildId = `{0}`", Items&: BuildInfo.BuildId);
508 return Error::success();
509}
510
511Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
512 CallSiteInfoSym &CSI) {
513 AutoIndent Indent(P, 7);
514 P.formatLine(Fmt: "type = {0}, addr = {1}", Items: typeIndex(TI: CSI.Type),
515 Items: formatSegmentOffset(Segment: CSI.Segment, Offset: CSI.CodeOffset));
516 return Error::success();
517}
518
519Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
520 EnvBlockSym &EnvBlock) {
521 AutoIndent Indent(P, 7);
522 for (const auto &Entry : EnvBlock.Fields) {
523 P.formatLine(Fmt: "- {0}", Items: Entry);
524 }
525 return Error::success();
526}
527
528Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FileStaticSym &FS) {
529 P.format(Fmt: " `{0}`", Items&: FS.Name);
530 AutoIndent Indent(P, 7);
531 if (SymGroup) {
532 Expected<StringRef> FileName =
533 SymGroup->getNameFromStringTable(Offset: FS.ModFilenameOffset);
534 if (FileName) {
535 P.formatLine(Fmt: "type = {0}, file name = {1} ({2}), flags = {3}",
536 Items: typeIndex(TI: FS.Index), Items&: FS.ModFilenameOffset, Items&: *FileName,
537 Items: formatLocalSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: FS.Flags));
538 }
539 return Error::success();
540 }
541
542 P.formatLine(Fmt: "type = {0}, file name offset = {1}, flags = {2}",
543 Items: typeIndex(TI: FS.Index), Items&: FS.ModFilenameOffset,
544 Items: formatLocalSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: FS.Flags));
545 return Error::success();
546}
547
548Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
549 P.format(Fmt: " `{0}`", Items&: Export.Name);
550 AutoIndent Indent(P, 7);
551 P.formatLine(Fmt: "ordinal = {0}, flags = {1}", Items&: Export.Ordinal,
552 Items: formatExportFlags(IndentLevel: P.getIndentLevel() + 9, Flags: Export.Flags));
553 return Error::success();
554}
555
556Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
557 Compile2Sym &Compile2) {
558 AutoIndent Indent(P, 7);
559 SourceLanguage Lang = static_cast<SourceLanguage>(
560 Compile2.Flags & CompileSym2Flags::SourceLanguageMask);
561 CompilationCPU = Compile2.Machine;
562 P.formatLine(Fmt: "machine = {0}, ver = {1}, language = {2}",
563 Items: formatMachineType(Cpu: Compile2.Machine), Items&: Compile2.Version,
564 Items: formatSourceLanguage(Lang));
565 P.formatLine(Fmt: "frontend = {0}.{1}.{2}, backend = {3}.{4}.{5}",
566 Items&: Compile2.VersionFrontendMajor, Items&: Compile2.VersionFrontendMinor,
567 Items&: Compile2.VersionFrontendBuild, Items&: Compile2.VersionBackendMajor,
568 Items&: Compile2.VersionBackendMinor, Items&: Compile2.VersionBackendBuild);
569 P.formatLine(Fmt: "flags = {0}",
570 Items: formatCompileSym2Flags(IndentLevel: P.getIndentLevel() + 9, Flags: Compile2.Flags));
571 P.formatLine(
572 Fmt: "extra strings = {0}",
573 Items: typesetStringList(IndentLevel: P.getIndentLevel() + 9 + 2, Strings: Compile2.ExtraStrings));
574 return Error::success();
575}
576
577Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
578 Compile3Sym &Compile3) {
579 AutoIndent Indent(P, 7);
580 SourceLanguage Lang = static_cast<SourceLanguage>(
581 Compile3.Flags & CompileSym3Flags::SourceLanguageMask);
582 CompilationCPU = Compile3.Machine;
583 P.formatLine(Fmt: "machine = {0}, Ver = {1}, language = {2}",
584 Items: formatMachineType(Cpu: Compile3.Machine), Items&: Compile3.Version,
585 Items: formatSourceLanguage(Lang));
586 P.formatLine(Fmt: "frontend = {0}.{1}.{2}.{3}, backend = {4}.{5}.{6}.{7}",
587 Items&: Compile3.VersionFrontendMajor, Items&: Compile3.VersionFrontendMinor,
588 Items&: Compile3.VersionFrontendBuild, Items&: Compile3.VersionFrontendQFE,
589 Items&: Compile3.VersionBackendMajor, Items&: Compile3.VersionBackendMinor,
590 Items&: Compile3.VersionBackendBuild, Items&: Compile3.VersionBackendQFE);
591 P.formatLine(Fmt: "flags = {0}",
592 Items: formatCompileSym3Flags(IndentLevel: P.getIndentLevel() + 9, Flags: Compile3.Flags));
593 return Error::success();
594}
595
596Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
597 ConstantSym &Constant) {
598 P.format(Fmt: " `{0}`", Items&: Constant.Name);
599 AutoIndent Indent(P, 7);
600 P.formatLine(Fmt: "type = {0}, value = {1}", Items: typeIndex(TI: Constant.Type),
601 Items: toString(I: Constant.Value, Radix: 10));
602 return Error::success();
603}
604
605Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
606 P.format(Fmt: " `{0}`", Items&: Data.Name);
607 AutoIndent Indent(P, 7);
608 P.formatLine(Fmt: "type = {0}, addr = {1}", Items: typeIndex(TI: Data.Type),
609 Items: formatSegmentOffset(Segment: Data.Segment, Offset: Data.DataOffset));
610 return Error::success();
611}
612
613Error MinimalSymbolDumper::visitKnownRecord(
614 CVSymbol &CVR, DefRangeFramePointerRelFullScopeSym &Def) {
615 P.format(Fmt: " offset = {0}", Items&: Def.Offset);
616 return Error::success();
617}
618
619Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
620 DefRangeFramePointerRelSym &Def) {
621 AutoIndent Indent(P, 7);
622 P.formatLine(Fmt: "offset = {0}, range = {1}", Items&: Def.Hdr.Offset,
623 Items: formatRange(Range: Def.Range));
624 P.formatLine(Fmt: "gaps = [{0}]", Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: Def.Gaps));
625 return Error::success();
626}
627
628Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
629 DefRangeRegisterRelSym &Def) {
630 AutoIndent Indent(P, 7);
631 P.formatLine(Fmt: "register = {0}, offset = {1}, offset in parent = {2}, has "
632 "spilled udt = {3}",
633 Items: formatRegisterId(Reg16&: Def.Hdr.Register, Cpu: CompilationCPU),
634 Items: int32_t(Def.Hdr.BasePointerOffset), Items: Def.offsetInParent(),
635 Items: Def.hasSpilledUDTMember());
636 P.formatLine(Fmt: "range = {0}, gaps = [{1}]", Items: formatRange(Range: Def.Range),
637 Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: Def.Gaps));
638 return Error::success();
639}
640
641Error MinimalSymbolDumper::visitKnownRecord(
642 CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
643 AutoIndent Indent(P, 7);
644 P.formatLine(Fmt: "register = {0}, may have no name = {1}, range start = "
645 "{2}, length = {3}",
646 Items: formatRegisterId(Reg16&: DefRangeRegister.Hdr.Register, Cpu: CompilationCPU),
647 Items: bool(DefRangeRegister.Hdr.MayHaveNoName),
648 Items: formatSegmentOffset(Segment: DefRangeRegister.Range.ISectStart,
649 Offset: DefRangeRegister.Range.OffsetStart),
650 Items&: DefRangeRegister.Range.Range);
651 P.formatLine(Fmt: "gaps = [{0}]",
652 Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: DefRangeRegister.Gaps));
653 return Error::success();
654}
655
656Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
657 DefRangeSubfieldRegisterSym &Def) {
658 AutoIndent Indent(P, 7);
659 bool NoName = !!(Def.Hdr.MayHaveNoName == 0);
660 P.formatLine(Fmt: "register = {0}, may have no name = {1}, offset in parent = {2}",
661 Items: formatRegisterId(Reg16&: Def.Hdr.Register, Cpu: CompilationCPU), Items&: NoName,
662 Items: uint32_t(Def.Hdr.OffsetInParent));
663 P.formatLine(Fmt: "range = {0}, gaps = [{1}]", Items: formatRange(Range: Def.Range),
664 Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: Def.Gaps));
665 return Error::success();
666}
667
668Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
669 DefRangeSubfieldSym &Def) {
670 AutoIndent Indent(P, 7);
671 P.formatLine(Fmt: "program = {0}, offset in parent = {1}, range = {2}",
672 Items&: Def.Program, Items&: Def.OffsetInParent, Items: formatRange(Range: Def.Range));
673 P.formatLine(Fmt: "gaps = [{0}]", Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: Def.Gaps));
674 return Error::success();
675}
676
677Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DefRangeSym &Def) {
678 AutoIndent Indent(P, 7);
679 P.formatLine(Fmt: "program = {0}, range = {1}", Items&: Def.Program,
680 Items: formatRange(Range: Def.Range));
681 P.formatLine(Fmt: "gaps = [{0}]", Items: formatGaps(IndentLevel: P.getIndentLevel() + 9, Gaps: Def.Gaps));
682 return Error::success();
683}
684
685Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameCookieSym &FC) {
686 AutoIndent Indent(P, 7);
687 P.formatLine(Fmt: "code offset = {0}, Register = {1}, kind = {2}, flags = {3}",
688 Items&: FC.CodeOffset, Items: formatRegisterId(Reg16: FC.Register, Cpu: CompilationCPU),
689 Items: formatCookieKind(Kind: FC.CookieKind), Items&: FC.Flags);
690 return Error::success();
691}
692
693Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameProcSym &FP) {
694 AutoIndent Indent(P, 7);
695 P.formatLine(Fmt: "size = {0}, padding size = {1}, offset to padding = {2}",
696 Items&: FP.TotalFrameBytes, Items&: FP.PaddingFrameBytes, Items&: FP.OffsetToPadding);
697 P.formatLine(Fmt: "bytes of callee saved registers = {0}, exception handler addr "
698 "= {1}",
699 Items&: FP.BytesOfCalleeSavedRegisters,
700 Items: formatSegmentOffset(Segment: FP.SectionIdOfExceptionHandler,
701 Offset: FP.OffsetOfExceptionHandler));
702 P.formatLine(
703 Fmt: "local fp reg = {0}, param fp reg = {1}",
704 Items: formatRegisterId(Id: FP.getLocalFramePtrReg(CPU: CompilationCPU), Cpu: CompilationCPU),
705 Items: formatRegisterId(Id: FP.getParamFramePtrReg(CPU: CompilationCPU), Cpu: CompilationCPU));
706 P.formatLine(Fmt: "flags = {0}",
707 Items: formatFrameProcedureOptions(IndentLevel: P.getIndentLevel() + 9, FPO: FP.Flags));
708 return Error::success();
709}
710
711Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
712 HeapAllocationSiteSym &HAS) {
713 AutoIndent Indent(P, 7);
714 P.formatLine(Fmt: "type = {0}, addr = {1} call size = {2}", Items: typeIndex(TI: HAS.Type),
715 Items: formatSegmentOffset(Segment: HAS.Segment, Offset: HAS.CodeOffset),
716 Items&: HAS.CallInstructionSize);
717 return Error::success();
718}
719
720Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, InlineSiteSym &IS) {
721 AutoIndent Indent(P, 7);
722 P.formatLine(Fmt: "inlinee = {0}, parent = {1}, end = {2}", Items: idIndex(TI: IS.Inlinee),
723 Items&: IS.Parent, Items&: IS.End);
724
725 // Break down the annotation byte code and calculate code and line offsets.
726 // FIXME: It would be helpful if we could look up the initial file and inlinee
727 // lines offset using the inlinee index above.
728 uint32_t CodeOffset = 0;
729 int32_t LineOffset = 0;
730 for (auto &Annot : IS.annotations()) {
731 P.formatLine(Fmt: " {0}", Items: fmt_align(Item: toHex(Input: Annot.Bytes), Where: AlignStyle::Left, Amount: 9));
732
733 auto formatCodeOffset = [&](uint32_t Delta) {
734 CodeOffset += Delta;
735 P.format(Fmt: " code 0x{0} (+0x{1})", Items: utohexstr(X: CodeOffset), Items: utohexstr(X: Delta));
736 };
737 auto formatCodeLength = [&](uint32_t Length) {
738 // Notably, changing the code length does not affect the code offset.
739 P.format(Fmt: " code end 0x{0} (+0x{1})", Items: utohexstr(X: CodeOffset + Length),
740 Items: utohexstr(X: Length));
741 };
742 auto formatLineOffset = [&](int32_t Delta) {
743 LineOffset += Delta;
744 char Sign = Delta > 0 ? '+' : '-';
745 P.format(Fmt: " line {0} ({1}{2})", Items&: LineOffset, Items&: Sign, Items: std::abs(x: Delta));
746 };
747
748 // Use the opcode to interpret the integer values.
749 switch (Annot.OpCode) {
750 case BinaryAnnotationsOpCode::Invalid:
751 break;
752 case BinaryAnnotationsOpCode::CodeOffset:
753 case BinaryAnnotationsOpCode::ChangeCodeOffset:
754 formatCodeOffset(Annot.U1);
755 break;
756 case BinaryAnnotationsOpCode::ChangeLineOffset:
757 formatLineOffset(Annot.S1);
758 break;
759 case BinaryAnnotationsOpCode::ChangeCodeLength:
760 formatCodeLength(Annot.U1);
761 // Apparently this annotation updates the code offset. It's hard to make
762 // MSVC produce this opcode, but clang uses it, and debuggers seem to use
763 // this interpretation.
764 CodeOffset += Annot.U1;
765 break;
766 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
767 formatCodeOffset(Annot.U1);
768 formatLineOffset(Annot.S1);
769 break;
770 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
771 formatCodeOffset(Annot.U2);
772 formatCodeLength(Annot.U1);
773 break;
774
775 case BinaryAnnotationsOpCode::ChangeFile: {
776 uint32_t FileOffset = Annot.U1;
777 StringRef Filename = "<unknown>";
778 if (SymGroup) {
779 if (Expected<StringRef> MaybeFile =
780 SymGroup->getNameFromStringTable(Offset: FileOffset))
781 Filename = *MaybeFile;
782 else
783 return MaybeFile.takeError();
784 }
785 P.format(Fmt: " setfile {0} 0x{1}", Items&: Filename, Items: utohexstr(X: FileOffset));
786 break;
787 }
788
789 // The rest of these are hard to convince MSVC to emit, so they are not as
790 // well understood.
791 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
792 formatCodeOffset(Annot.U1);
793 break;
794 case BinaryAnnotationsOpCode::ChangeLineEndDelta:
795 case BinaryAnnotationsOpCode::ChangeRangeKind:
796 case BinaryAnnotationsOpCode::ChangeColumnStart:
797 case BinaryAnnotationsOpCode::ChangeColumnEnd:
798 P.format(Fmt: " {0} {1}", Items: Annot.Name, Items: Annot.U1);
799 break;
800 case BinaryAnnotationsOpCode::ChangeColumnEndDelta:
801 P.format(Fmt: " {0} {1}", Items: Annot.Name, Items: Annot.S1);
802 break;
803 }
804 }
805 return Error::success();
806}
807
808Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
809 RegisterSym &Register) {
810 P.format(Fmt: " `{0}`", Items&: Register.Name);
811 AutoIndent Indent(P, 7);
812 P.formatLine(Fmt: "register = {0}, type = {1}",
813 Items: formatRegisterId(Id: Register.Register, Cpu: CompilationCPU),
814 Items: typeIndex(TI: Register.Index));
815 return Error::success();
816}
817
818Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
819 PublicSym32 &Public) {
820 P.format(Fmt: " `{0}`", Items&: Public.Name);
821 AutoIndent Indent(P, 7);
822 P.formatLine(Fmt: "flags = {0}, addr = {1}",
823 Items: formatPublicSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: Public.Flags),
824 Items: formatSegmentOffset(Segment: Public.Segment, Offset: Public.Offset));
825 return Error::success();
826}
827
828Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcRefSym &PR) {
829 P.format(Fmt: " `{0}`", Items&: PR.Name);
830 AutoIndent Indent(P, 7);
831 P.formatLine(Fmt: "module = {0}, sum name = {1}, offset = {2}", Items&: PR.Module,
832 Items&: PR.SumName, Items&: PR.SymOffset);
833 return Error::success();
834}
835
836Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
837 P.format(Fmt: " `{0}` (addr = {1})", Items&: Label.Name,
838 Items: formatSegmentOffset(Segment: Label.Segment, Offset: Label.CodeOffset));
839 AutoIndent Indent(P, 7);
840 P.formatLine(Fmt: "flags = {0}",
841 Items: formatProcSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: Label.Flags));
842 return Error::success();
843}
844
845Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
846 P.format(Fmt: " `{0}`", Items&: Local.Name);
847 AutoIndent Indent(P, 7);
848
849 std::string FlagStr =
850 formatLocalSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: Local.Flags);
851 P.formatLine(Fmt: "type={0}, flags = {1}", Items: typeIndex(TI: Local.Type), Items&: FlagStr);
852 return Error::success();
853}
854
855Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
856 ObjNameSym &ObjName) {
857 P.format(Fmt: " sig={0}, `{1}`", Items&: ObjName.Signature, Items&: ObjName.Name);
858 return Error::success();
859}
860
861Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
862 P.format(Fmt: " `{0}`", Items&: Proc.Name);
863 AutoIndent Indent(P, 7);
864 P.formatLine(Fmt: "parent = {0}, end = {1}, addr = {2}, code size = {3}",
865 Items&: Proc.Parent, Items&: Proc.End,
866 Items: formatSegmentOffset(Segment: Proc.Segment, Offset: Proc.CodeOffset),
867 Items&: Proc.CodeSize);
868 bool IsType = true;
869 switch (Proc.getKind()) {
870 case SymbolRecordKind::GlobalProcIdSym:
871 case SymbolRecordKind::ProcIdSym:
872 case SymbolRecordKind::DPCProcIdSym:
873 IsType = false;
874 break;
875 default:
876 break;
877 }
878 P.formatLine(Fmt: "type = `{0}`, debug start = {1}, debug end = {2}, flags = {3}",
879 Items: typeOrIdIndex(TI: Proc.FunctionType, IsType), Items&: Proc.DbgStart,
880 Items&: Proc.DbgEnd,
881 Items: formatProcSymFlags(IndentLevel: P.getIndentLevel() + 9, Flags: Proc.Flags));
882 return Error::success();
883}
884
885Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
886 ScopeEndSym &ScopeEnd) {
887 return Error::success();
888}
889
890Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
891 const char *Format;
892 switch (CVR.kind()) {
893 case S_CALLEES:
894 Format = "callee: {0}";
895 break;
896 case S_CALLERS:
897 Format = "caller: {0}";
898 break;
899 case S_INLINEES:
900 Format = "inlinee: {0}";
901 break;
902 default:
903 return llvm::make_error<CodeViewError>(
904 Args: "Unknown CV Record type for a CallerSym object!");
905 }
906 AutoIndent Indent(P, 7);
907 for (const auto &I : Caller.Indices) {
908 P.formatLine(Fmt: Format, Items: idIndex(TI: I));
909 }
910 return Error::success();
911}
912
913Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
914 RegRelativeSym &RegRel) {
915 P.format(Fmt: " `{0}`", Items&: RegRel.Name);
916 AutoIndent Indent(P, 7);
917 P.formatLine(
918 Fmt: "type = {0}, register = {1}, offset = {2}", Items: typeIndex(TI: RegRel.Type),
919 Items: formatRegisterId(Id: RegRel.Register, Cpu: CompilationCPU), Items&: RegRel.Offset);
920 return Error::success();
921}
922
923Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
924 ThreadLocalDataSym &Data) {
925 P.format(Fmt: " `{0}`", Items&: Data.Name);
926 AutoIndent Indent(P, 7);
927 P.formatLine(Fmt: "type = {0}, addr = {1}", Items: typeIndex(TI: Data.Type),
928 Items: formatSegmentOffset(Segment: Data.Segment, Offset: Data.DataOffset));
929 return Error::success();
930}
931
932Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
933 P.format(Fmt: " `{0}`", Items&: UDT.Name);
934 AutoIndent Indent(P, 7);
935 P.formatLine(Fmt: "original type = {0}", Items&: UDT.Type);
936 return Error::success();
937}
938
939Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
940 UsingNamespaceSym &UN) {
941 P.format(Fmt: " `{0}`", Items&: UN.Name);
942 return Error::success();
943}
944
945Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
946 AnnotationSym &Annot) {
947 AutoIndent Indent(P, 7);
948 P.formatLine(Fmt: "addr = {0}", Items: formatSegmentOffset(Segment: Annot.Segment, Offset: Annot.CodeOffset));
949 P.formatLine(Fmt: "strings = {0}", Items: typesetStringList(IndentLevel: P.getIndentLevel() + 9 + 2,
950 Strings: Annot.Strings));
951 return Error::success();
952}
953
954Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
955 JumpTableSym &JumpTable) {
956 AutoIndent Indent(P, 7);
957 P.formatLine(
958 Fmt: "base = {0}, switchtype = {1}, branch = {2}, table = {3}, entriescount = "
959 "{4}",
960 Items: formatSegmentOffset(Segment: JumpTable.BaseSegment, Offset: JumpTable.BaseOffset),
961 Items: formatJumpTableEntrySize(EntrySize: JumpTable.SwitchType),
962 Items: formatSegmentOffset(Segment: JumpTable.BranchSegment, Offset: JumpTable.BranchOffset),
963 Items: formatSegmentOffset(Segment: JumpTable.TableSegment, Offset: JumpTable.TableOffset),
964 Items&: JumpTable.EntriesCount);
965 return Error::success();
966}
967
968Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,
969 HotPatchFuncSym &JumpTable) {
970 AutoIndent Indent(P, 7);
971 P.formatLine(Fmt: "function = {0}, name = {1}", Items: typeIndex(TI: JumpTable.Function),
972 Items&: JumpTable.Name);
973 return Error::success();
974}
975