1//===-- SymbolDumper.cpp - CodeView symbol info dumper ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
10#include "llvm/ADT/StringRef.h"
11#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
12#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
13#include "llvm/DebugInfo/CodeView/EnumTables.h"
14#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
15#include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h"
16#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
17#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbackPipeline.h"
18#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
19#include "llvm/DebugInfo/CodeView/TypeIndex.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/ScopedPrinter.h"
22
23using namespace llvm;
24using namespace llvm::codeview;
25
26namespace {
27/// Use this private dumper implementation to keep implementation details about
28/// the visitor out of SymbolDumper.h.
29class CVSymbolDumperImpl : public SymbolVisitorCallbacks {
30public:
31 CVSymbolDumperImpl(TypeCollection &Types, SymbolDumpDelegate *ObjDelegate,
32 ScopedPrinter &W, CPUType CPU, bool PrintRecordBytes)
33 : Types(Types), ObjDelegate(ObjDelegate), W(W), CompilationCPUType(CPU),
34 PrintRecordBytes(PrintRecordBytes), InFunctionScope(false) {}
35
36/// CVSymbolVisitor overrides.
37#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
38 Error visitKnownRecord(CVSymbol &CVR, Name &Record) override;
39#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
40#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
41
42 Error visitSymbolBegin(CVSymbol &Record) override;
43 Error visitSymbolEnd(CVSymbol &Record) override;
44 Error visitUnknownSymbol(CVSymbol &Record) override;
45
46 CPUType getCompilationCPUType() const { return CompilationCPUType; }
47
48private:
49 void printLocalVariableAddrRange(const LocalVariableAddrRange &Range,
50 uint32_t RelocationOffset);
51 void printLocalVariableAddrGap(ArrayRef<LocalVariableAddrGap> Gaps);
52 void printTypeIndex(StringRef FieldName, TypeIndex TI);
53
54 TypeCollection &Types;
55 SymbolDumpDelegate *ObjDelegate;
56 ScopedPrinter &W;
57
58 /// Save the machine or CPU type when dumping a compile symbols.
59 CPUType CompilationCPUType = CPUType::X64;
60
61 bool PrintRecordBytes;
62 bool InFunctionScope;
63};
64}
65
66static StringRef getSymbolKindName(SymbolKind Kind) {
67 switch (Kind) {
68#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
69 case EnumName: \
70 return #Name;
71#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
72 default:
73 break;
74 }
75 return "UnknownSym";
76}
77
78void CVSymbolDumperImpl::printLocalVariableAddrRange(
79 const LocalVariableAddrRange &Range, uint32_t RelocationOffset) {
80 DictScope S(W, "LocalVariableAddrRange");
81 if (ObjDelegate)
82 ObjDelegate->printRelocatedField(Label: "OffsetStart", RelocOffset: RelocationOffset,
83 Offset: Range.OffsetStart);
84 W.printHex(Label: "ISectStart", Value: Range.ISectStart);
85 W.printHex(Label: "Range", Value: Range.Range);
86}
87
88void CVSymbolDumperImpl::printLocalVariableAddrGap(
89 ArrayRef<LocalVariableAddrGap> Gaps) {
90 for (auto &Gap : Gaps) {
91 ListScope S(W, "LocalVariableAddrGap");
92 W.printHex(Label: "GapStartOffset", Value: Gap.GapStartOffset);
93 W.printHex(Label: "Range", Value: Gap.Range);
94 }
95}
96
97void CVSymbolDumperImpl::printTypeIndex(StringRef FieldName, TypeIndex TI) {
98 codeview::printTypeIndex(Printer&: W, FieldName, TI, Types);
99}
100
101Error CVSymbolDumperImpl::visitSymbolBegin(CVSymbol &CVR) {
102 W.startLine() << getSymbolKindName(Kind: CVR.kind());
103 W.getOStream() << " {\n";
104 W.indent();
105 W.printEnum(Label: "Kind", Value: unsigned(CVR.kind()), EnumValues: getSymbolTypeNames());
106 return Error::success();
107}
108
109Error CVSymbolDumperImpl::visitSymbolEnd(CVSymbol &CVR) {
110 if (PrintRecordBytes && ObjDelegate)
111 ObjDelegate->printBinaryBlockWithRelocs(Label: "SymData", Block: CVR.content());
112
113 W.unindent();
114 W.startLine() << "}\n";
115 return Error::success();
116}
117
118Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
119 StringRef LinkageName;
120 W.printHex(Label: "PtrParent", Value: Block.Parent);
121 W.printHex(Label: "PtrEnd", Value: Block.End);
122 W.printHex(Label: "CodeSize", Value: Block.CodeSize);
123 if (ObjDelegate) {
124 ObjDelegate->printRelocatedField(Label: "CodeOffset", RelocOffset: Block.getRelocationOffset(),
125 Offset: Block.CodeOffset, RelocSym: &LinkageName);
126 }
127 W.printHex(Label: "Segment", Value: Block.Segment);
128 W.printString(Label: "BlockName", Value: Block.Name);
129 W.printString(Label: "LinkageName", Value: LinkageName);
130 return Error::success();
131}
132
133Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
134 W.printString(Label: "Name", Value: Thunk.Name);
135 W.printNumber(Label: "Parent", Value: Thunk.Parent);
136 W.printNumber(Label: "End", Value: Thunk.End);
137 W.printNumber(Label: "Next", Value: Thunk.Next);
138 W.printNumber(Label: "Off", Value: Thunk.Offset);
139 W.printNumber(Label: "Seg", Value: Thunk.Segment);
140 W.printNumber(Label: "Len", Value: Thunk.Length);
141 W.printEnum(Label: "Ordinal", Value: uint8_t(Thunk.Thunk), EnumValues: getThunkOrdinalNames());
142 return Error::success();
143}
144
145Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
146 TrampolineSym &Tramp) {
147 W.printEnum(Label: "Type", Value: uint16_t(Tramp.Type), EnumValues: getTrampolineNames());
148 W.printNumber(Label: "Size", Value: Tramp.Size);
149 W.printNumber(Label: "ThunkOff", Value: Tramp.ThunkOffset);
150 W.printNumber(Label: "TargetOff", Value: Tramp.TargetOffset);
151 W.printNumber(Label: "ThunkSection", Value: Tramp.ThunkSection);
152 W.printNumber(Label: "TargetSection", Value: Tramp.TargetSection);
153 return Error::success();
154}
155
156Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, SectionSym &Section) {
157 W.printNumber(Label: "SectionNumber", Value: Section.SectionNumber);
158 W.printNumber(Label: "Alignment", Value: Section.Alignment);
159 W.printNumber(Label: "Rva", Value: Section.Rva);
160 W.printNumber(Label: "Length", Value: Section.Length);
161 W.printFlags(Label: "Characteristics", Value: Section.Characteristics,
162 Flags: getImageSectionCharacteristicNames(),
163 EnumMask1: COFF::SectionCharacteristics(0x00F00000));
164
165 W.printString(Label: "Name", Value: Section.Name);
166 return Error::success();
167}
168
169Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
170 CoffGroupSym &CoffGroup) {
171 W.printNumber(Label: "Size", Value: CoffGroup.Size);
172 W.printFlags(Label: "Characteristics", Value: CoffGroup.Characteristics,
173 Flags: getImageSectionCharacteristicNames(),
174 EnumMask1: COFF::SectionCharacteristics(0x00F00000));
175 W.printNumber(Label: "Offset", Value: CoffGroup.Offset);
176 W.printNumber(Label: "Segment", Value: CoffGroup.Segment);
177 W.printString(Label: "Name", Value: CoffGroup.Name);
178 return Error::success();
179}
180
181Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
182 BPRelativeSym &BPRel) {
183 W.printNumber(Label: "Offset", Value: BPRel.Offset);
184 printTypeIndex(FieldName: "Type", TI: BPRel.Type);
185 W.printString(Label: "VarName", Value: BPRel.Name);
186 return Error::success();
187}
188
189Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
190 BuildInfoSym &BuildInfo) {
191 printTypeIndex(FieldName: "BuildId", TI: BuildInfo.BuildId);
192 return Error::success();
193}
194
195Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
196 CallSiteInfoSym &CallSiteInfo) {
197 StringRef LinkageName;
198 if (ObjDelegate) {
199 ObjDelegate->printRelocatedField(Label: "CodeOffset",
200 RelocOffset: CallSiteInfo.getRelocationOffset(),
201 Offset: CallSiteInfo.CodeOffset, RelocSym: &LinkageName);
202 }
203 W.printHex(Label: "Segment", Value: CallSiteInfo.Segment);
204 printTypeIndex(FieldName: "Type", TI: CallSiteInfo.Type);
205 if (!LinkageName.empty())
206 W.printString(Label: "LinkageName", Value: LinkageName);
207 return Error::success();
208}
209
210Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
211 EnvBlockSym &EnvBlock) {
212 ListScope L(W, "Entries");
213 for (auto Entry : EnvBlock.Fields) {
214 W.printString(Value: Entry);
215 }
216 return Error::success();
217}
218
219Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
220 FileStaticSym &FileStatic) {
221 printTypeIndex(FieldName: "Index", TI: FileStatic.Index);
222 W.printNumber(Label: "ModFilenameOffset", Value: FileStatic.ModFilenameOffset);
223 W.printFlags(Label: "Flags", Value: uint16_t(FileStatic.Flags), Flags: getLocalFlagNames());
224 W.printString(Label: "Name", Value: FileStatic.Name);
225 return Error::success();
226}
227
228Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
229 W.printNumber(Label: "Ordinal", Value: Export.Ordinal);
230 W.printFlags(Label: "Flags", Value: uint16_t(Export.Flags), Flags: getExportSymFlagNames());
231 W.printString(Label: "Name", Value: Export.Name);
232 return Error::success();
233}
234
235Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
236 Compile2Sym &Compile2) {
237 W.printEnum(Label: "Language", Value: Compile2.getLanguage(), EnumValues: getSourceLanguageNames());
238 W.printFlags(Label: "Flags", Value: Compile2.getFlags(), Flags: getCompileSym2FlagNames());
239 W.printEnum(Label: "Machine", Value: unsigned(Compile2.Machine), EnumValues: getCPUTypeNames());
240 CompilationCPUType = Compile2.Machine;
241 std::string FrontendVersion;
242 {
243 raw_string_ostream Out(FrontendVersion);
244 Out << Compile2.VersionFrontendMajor << '.' << Compile2.VersionFrontendMinor
245 << '.' << Compile2.VersionFrontendBuild;
246 }
247 std::string BackendVersion;
248 {
249 raw_string_ostream Out(BackendVersion);
250 Out << Compile2.VersionBackendMajor << '.' << Compile2.VersionBackendMinor
251 << '.' << Compile2.VersionBackendBuild;
252 }
253 W.printString(Label: "FrontendVersion", Value: FrontendVersion);
254 W.printString(Label: "BackendVersion", Value: BackendVersion);
255 W.printString(Label: "VersionName", Value: Compile2.Version);
256 return Error::success();
257}
258
259Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
260 Compile3Sym &Compile3) {
261 W.printEnum(Label: "Language", Value: uint8_t(Compile3.getLanguage()), EnumValues: getSourceLanguageNames());
262 W.printFlags(Label: "Flags", Value: uint32_t(Compile3.getFlags()),
263 Flags: getCompileSym3FlagNames());
264 W.printEnum(Label: "Machine", Value: unsigned(Compile3.Machine), EnumValues: getCPUTypeNames());
265 CompilationCPUType = Compile3.Machine;
266 std::string FrontendVersion;
267 {
268 raw_string_ostream Out(FrontendVersion);
269 Out << Compile3.VersionFrontendMajor << '.' << Compile3.VersionFrontendMinor
270 << '.' << Compile3.VersionFrontendBuild << '.'
271 << Compile3.VersionFrontendQFE;
272 }
273 std::string BackendVersion;
274 {
275 raw_string_ostream Out(BackendVersion);
276 Out << Compile3.VersionBackendMajor << '.' << Compile3.VersionBackendMinor
277 << '.' << Compile3.VersionBackendBuild << '.'
278 << Compile3.VersionBackendQFE;
279 }
280 W.printString(Label: "FrontendVersion", Value: FrontendVersion);
281 W.printString(Label: "BackendVersion", Value: BackendVersion);
282 W.printString(Label: "VersionName", Value: Compile3.Version);
283 return Error::success();
284}
285
286Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
287 ConstantSym &Constant) {
288 printTypeIndex(FieldName: "Type", TI: Constant.Type);
289 W.printNumber(Label: "Value", Value: Constant.Value);
290 W.printString(Label: "Name", Value: Constant.Name);
291 return Error::success();
292}
293
294Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
295 StringRef LinkageName;
296 if (ObjDelegate) {
297 ObjDelegate->printRelocatedField(Label: "DataOffset", RelocOffset: Data.getRelocationOffset(),
298 Offset: Data.DataOffset, RelocSym: &LinkageName);
299 }
300 printTypeIndex(FieldName: "Type", TI: Data.Type);
301 W.printString(Label: "DisplayName", Value: Data.Name);
302 if (!LinkageName.empty())
303 W.printString(Label: "LinkageName", Value: LinkageName);
304 return Error::success();
305}
306
307Error CVSymbolDumperImpl::visitKnownRecord(
308 CVSymbol &CVR,
309 DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
310 W.printNumber(Label: "Offset", Value: DefRangeFramePointerRelFullScope.Offset);
311 return Error::success();
312}
313
314Error CVSymbolDumperImpl::visitKnownRecord(
315 CVSymbol &CVR, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
316 W.printNumber(Label: "Offset", Value: DefRangeFramePointerRel.Hdr.Offset);
317 printLocalVariableAddrRange(Range: DefRangeFramePointerRel.Range,
318 RelocationOffset: DefRangeFramePointerRel.getRelocationOffset());
319 printLocalVariableAddrGap(Gaps: DefRangeFramePointerRel.Gaps);
320 return Error::success();
321}
322
323Error CVSymbolDumperImpl::visitKnownRecord(
324 CVSymbol &CVR, DefRangeRegisterRelSym &DefRangeRegisterRel) {
325 W.printEnum(Label: "BaseRegister", Value: uint16_t(DefRangeRegisterRel.Hdr.Register),
326 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
327 W.printBoolean(Label: "HasSpilledUDTMember",
328 Value: DefRangeRegisterRel.hasSpilledUDTMember());
329 W.printNumber(Label: "OffsetInParent", Value: DefRangeRegisterRel.offsetInParent());
330 W.printNumber(Label: "BasePointerOffset", Value: DefRangeRegisterRel.Hdr.BasePointerOffset);
331 printLocalVariableAddrRange(Range: DefRangeRegisterRel.Range,
332 RelocationOffset: DefRangeRegisterRel.getRelocationOffset());
333 printLocalVariableAddrGap(Gaps: DefRangeRegisterRel.Gaps);
334 return Error::success();
335}
336
337Error CVSymbolDumperImpl::visitKnownRecord(
338 CVSymbol &CVR, DefRangeRegisterRelIndirSym &DefRangeRegisterRelIndir) {
339 W.printEnum(Label: "BaseRegister", Value: uint16_t(DefRangeRegisterRelIndir.Hdr.Register),
340 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
341 W.printBoolean(Label: "HasSpilledUDTMember",
342 Value: DefRangeRegisterRelIndir.hasSpilledUDTMember());
343 W.printNumber(Label: "OffsetInParent", Value: DefRangeRegisterRelIndir.offsetInParent());
344 W.printNumber(Label: "BasePointerOffset",
345 Value: DefRangeRegisterRelIndir.Hdr.BasePointerOffset);
346 W.printNumber(Label: "OffsetInUDT", Value: DefRangeRegisterRelIndir.Hdr.OffsetInUdt);
347 printLocalVariableAddrRange(Range: DefRangeRegisterRelIndir.Range,
348 RelocationOffset: DefRangeRegisterRelIndir.getRelocationOffset());
349 printLocalVariableAddrGap(Gaps: DefRangeRegisterRelIndir.Gaps);
350 return Error::success();
351}
352
353Error CVSymbolDumperImpl::visitKnownRecord(
354 CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
355 W.printEnum(Label: "Register", Value: uint16_t(DefRangeRegister.Hdr.Register),
356 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
357 W.printNumber(Label: "MayHaveNoName", Value: DefRangeRegister.Hdr.MayHaveNoName);
358 printLocalVariableAddrRange(Range: DefRangeRegister.Range,
359 RelocationOffset: DefRangeRegister.getRelocationOffset());
360 printLocalVariableAddrGap(Gaps: DefRangeRegister.Gaps);
361 return Error::success();
362}
363
364Error CVSymbolDumperImpl::visitKnownRecord(
365 CVSymbol &CVR, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
366 W.printEnum(Label: "Register", Value: uint16_t(DefRangeSubfieldRegister.Hdr.Register),
367 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
368 W.printNumber(Label: "MayHaveNoName", Value: DefRangeSubfieldRegister.Hdr.MayHaveNoName);
369 W.printNumber(Label: "OffsetInParent", Value: DefRangeSubfieldRegister.Hdr.OffsetInParent);
370 printLocalVariableAddrRange(Range: DefRangeSubfieldRegister.Range,
371 RelocationOffset: DefRangeSubfieldRegister.getRelocationOffset());
372 printLocalVariableAddrGap(Gaps: DefRangeSubfieldRegister.Gaps);
373 return Error::success();
374}
375
376Error CVSymbolDumperImpl::visitKnownRecord(
377 CVSymbol &CVR, DefRangeSubfieldSym &DefRangeSubfield) {
378 if (ObjDelegate) {
379 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
380 auto ExpectedProgram = Strings.getString(Offset: DefRangeSubfield.Program);
381 if (!ExpectedProgram) {
382 consumeError(Err: ExpectedProgram.takeError());
383 return llvm::make_error<CodeViewError>(
384 Args: "String table offset outside of bounds of String Table!");
385 }
386 W.printString(Label: "Program", Value: *ExpectedProgram);
387 }
388 W.printNumber(Label: "OffsetInParent", Value: DefRangeSubfield.OffsetInParent);
389 printLocalVariableAddrRange(Range: DefRangeSubfield.Range,
390 RelocationOffset: DefRangeSubfield.getRelocationOffset());
391 printLocalVariableAddrGap(Gaps: DefRangeSubfield.Gaps);
392 return Error::success();
393}
394
395Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
396 DefRangeSym &DefRange) {
397 if (ObjDelegate) {
398 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
399 auto ExpectedProgram = Strings.getString(Offset: DefRange.Program);
400 if (!ExpectedProgram) {
401 consumeError(Err: ExpectedProgram.takeError());
402 return llvm::make_error<CodeViewError>(
403 Args: "String table offset outside of bounds of String Table!");
404 }
405 W.printString(Label: "Program", Value: *ExpectedProgram);
406 }
407 printLocalVariableAddrRange(Range: DefRange.Range, RelocationOffset: DefRange.getRelocationOffset());
408 printLocalVariableAddrGap(Gaps: DefRange.Gaps);
409 return Error::success();
410}
411
412Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
413 FrameCookieSym &FrameCookie) {
414 StringRef LinkageName;
415 if (ObjDelegate) {
416 ObjDelegate->printRelocatedField(Label: "CodeOffset",
417 RelocOffset: FrameCookie.getRelocationOffset(),
418 Offset: FrameCookie.CodeOffset, RelocSym: &LinkageName);
419 }
420 W.printEnum(Label: "Register", Value: uint16_t(FrameCookie.Register),
421 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
422 W.printEnum(Label: "CookieKind", Value: uint16_t(FrameCookie.CookieKind),
423 EnumValues: getFrameCookieKindNames());
424 W.printHex(Label: "Flags", Value: FrameCookie.Flags);
425 return Error::success();
426}
427
428Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
429 FrameProcSym &FrameProc) {
430 W.printHex(Label: "TotalFrameBytes", Value: FrameProc.TotalFrameBytes);
431 W.printHex(Label: "PaddingFrameBytes", Value: FrameProc.PaddingFrameBytes);
432 W.printHex(Label: "OffsetToPadding", Value: FrameProc.OffsetToPadding);
433 W.printHex(Label: "BytesOfCalleeSavedRegisters",
434 Value: FrameProc.BytesOfCalleeSavedRegisters);
435 W.printHex(Label: "OffsetOfExceptionHandler", Value: FrameProc.OffsetOfExceptionHandler);
436 W.printHex(Label: "SectionIdOfExceptionHandler",
437 Value: FrameProc.SectionIdOfExceptionHandler);
438 W.printFlags(Label: "Flags", Value: static_cast<uint32_t>(FrameProc.Flags),
439 Flags: getFrameProcSymFlagNames());
440 W.printEnum(Label: "LocalFramePtrReg",
441 Value: uint16_t(FrameProc.getLocalFramePtrReg(CPU: CompilationCPUType)),
442 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
443 W.printEnum(Label: "ParamFramePtrReg",
444 Value: uint16_t(FrameProc.getParamFramePtrReg(CPU: CompilationCPUType)),
445 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
446 return Error::success();
447}
448
449Error CVSymbolDumperImpl::visitKnownRecord(
450 CVSymbol &CVR, HeapAllocationSiteSym &HeapAllocSite) {
451 StringRef LinkageName;
452 if (ObjDelegate) {
453 ObjDelegate->printRelocatedField(Label: "CodeOffset",
454 RelocOffset: HeapAllocSite.getRelocationOffset(),
455 Offset: HeapAllocSite.CodeOffset, RelocSym: &LinkageName);
456 }
457 W.printHex(Label: "Segment", Value: HeapAllocSite.Segment);
458 W.printHex(Label: "CallInstructionSize", Value: HeapAllocSite.CallInstructionSize);
459 printTypeIndex(FieldName: "Type", TI: HeapAllocSite.Type);
460 if (!LinkageName.empty())
461 W.printString(Label: "LinkageName", Value: LinkageName);
462 return Error::success();
463}
464
465Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
466 InlineSiteSym &InlineSite) {
467 W.printHex(Label: "PtrParent", Value: InlineSite.Parent);
468 W.printHex(Label: "PtrEnd", Value: InlineSite.End);
469 printTypeIndex(FieldName: "Inlinee", TI: InlineSite.Inlinee);
470
471 ListScope BinaryAnnotations(W, "BinaryAnnotations");
472 for (auto &Annotation : InlineSite.annotations()) {
473 switch (Annotation.OpCode) {
474 case BinaryAnnotationsOpCode::Invalid:
475 W.printString(Value: "(Annotation Padding)");
476 break;
477 case BinaryAnnotationsOpCode::CodeOffset:
478 case BinaryAnnotationsOpCode::ChangeCodeOffset:
479 case BinaryAnnotationsOpCode::ChangeCodeLength:
480 W.printHex(Label: Annotation.Name, Value: Annotation.U1);
481 break;
482 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
483 case BinaryAnnotationsOpCode::ChangeLineEndDelta:
484 case BinaryAnnotationsOpCode::ChangeRangeKind:
485 case BinaryAnnotationsOpCode::ChangeColumnStart:
486 case BinaryAnnotationsOpCode::ChangeColumnEnd:
487 W.printNumber(Label: Annotation.Name, Value: Annotation.U1);
488 break;
489 case BinaryAnnotationsOpCode::ChangeLineOffset:
490 case BinaryAnnotationsOpCode::ChangeColumnEndDelta:
491 W.printNumber(Label: Annotation.Name, Value: Annotation.S1);
492 break;
493 case BinaryAnnotationsOpCode::ChangeFile:
494 if (ObjDelegate) {
495 W.printHex(Label: "ChangeFile",
496 Str: ObjDelegate->getFileNameForFileOffset(FileOffset: Annotation.U1),
497 Value: Annotation.U1);
498 } else {
499 W.printHex(Label: "ChangeFile", Value: Annotation.U1);
500 }
501
502 break;
503 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset: {
504 W.startLine() << "ChangeCodeOffsetAndLineOffset: {CodeOffset: "
505 << W.hex(Value: Annotation.U1) << ", LineOffset: " << Annotation.S1
506 << "}\n";
507 break;
508 }
509 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset: {
510 W.startLine() << "ChangeCodeLengthAndCodeOffset: {CodeOffset: "
511 << W.hex(Value: Annotation.U2)
512 << ", Length: " << W.hex(Value: Annotation.U1) << "}\n";
513 break;
514 }
515 }
516 }
517 return Error::success();
518}
519
520Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
521 RegisterSym &Register) {
522 printTypeIndex(FieldName: "Type", TI: Register.Index);
523 W.printEnum(Label: "Seg", Value: uint16_t(Register.Register),
524 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
525 W.printString(Label: "Name", Value: Register.Name);
526 return Error::success();
527}
528
529Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, PublicSym32 &Public) {
530 W.printFlags(Label: "Flags", Value: uint32_t(Public.Flags), Flags: getPublicSymFlagNames());
531 W.printNumber(Label: "Seg", Value: Public.Segment);
532 W.printNumber(Label: "Off", Value: Public.Offset);
533 W.printString(Label: "Name", Value: Public.Name);
534 return Error::success();
535}
536
537Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcRefSym &ProcRef) {
538 W.printNumber(Label: "SumName", Value: ProcRef.SumName);
539 W.printNumber(Label: "SymOffset", Value: ProcRef.SymOffset);
540 W.printNumber(Label: "Mod", Value: ProcRef.Module);
541 W.printString(Label: "Name", Value: ProcRef.Name);
542 return Error::success();
543}
544
545Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
546 StringRef LinkageName;
547 if (ObjDelegate) {
548 ObjDelegate->printRelocatedField(Label: "CodeOffset", RelocOffset: Label.getRelocationOffset(),
549 Offset: Label.CodeOffset, RelocSym: &LinkageName);
550 }
551 W.printHex(Label: "Segment", Value: Label.Segment);
552 W.printHex(Label: "Flags", Value: uint8_t(Label.Flags));
553 W.printFlags(Label: "Flags", Value: uint8_t(Label.Flags), Flags: getProcSymFlagNames());
554 W.printString(Label: "DisplayName", Value: Label.Name);
555 if (!LinkageName.empty())
556 W.printString(Label: "LinkageName", Value: LinkageName);
557 return Error::success();
558}
559
560Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
561 printTypeIndex(FieldName: "Type", TI: Local.Type);
562 W.printFlags(Label: "Flags", Value: uint16_t(Local.Flags), Flags: getLocalFlagNames());
563 W.printString(Label: "VarName", Value: Local.Name);
564 return Error::success();
565}
566
567Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ObjNameSym &ObjName) {
568 W.printHex(Label: "Signature", Value: ObjName.Signature);
569 W.printString(Label: "ObjectName", Value: ObjName.Name);
570 return Error::success();
571}
572
573Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
574 if (InFunctionScope)
575 return llvm::make_error<CodeViewError>(
576 Args: "Visiting a ProcSym while inside function scope!");
577
578 InFunctionScope = true;
579
580 StringRef LinkageName;
581 W.printHex(Label: "PtrParent", Value: Proc.Parent);
582 W.printHex(Label: "PtrEnd", Value: Proc.End);
583 W.printHex(Label: "PtrNext", Value: Proc.Next);
584 W.printHex(Label: "CodeSize", Value: Proc.CodeSize);
585 W.printHex(Label: "DbgStart", Value: Proc.DbgStart);
586 W.printHex(Label: "DbgEnd", Value: Proc.DbgEnd);
587 printTypeIndex(FieldName: "FunctionType", TI: Proc.FunctionType);
588 if (ObjDelegate) {
589 ObjDelegate->printRelocatedField(Label: "CodeOffset", RelocOffset: Proc.getRelocationOffset(),
590 Offset: Proc.CodeOffset, RelocSym: &LinkageName);
591 }
592 W.printHex(Label: "Segment", Value: Proc.Segment);
593 W.printFlags(Label: "Flags", Value: static_cast<uint8_t>(Proc.Flags),
594 Flags: getProcSymFlagNames());
595 W.printString(Label: "DisplayName", Value: Proc.Name);
596 if (!LinkageName.empty())
597 W.printString(Label: "LinkageName", Value: LinkageName);
598 return Error::success();
599}
600
601Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
602 ScopeEndSym &ScopeEnd) {
603 InFunctionScope = false;
604 return Error::success();
605}
606
607Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
608 llvm::StringRef ScopeName;
609 switch (CVR.kind()) {
610 case S_CALLEES:
611 ScopeName = "Callees";
612 break;
613 case S_CALLERS:
614 ScopeName = "Callers";
615 break;
616 case S_INLINEES:
617 ScopeName = "Inlinees";
618 break;
619 default:
620 return llvm::make_error<CodeViewError>(
621 Args: "Unknown CV Record type for a CallerSym object!");
622 }
623 ListScope S(W, ScopeName);
624 for (auto FuncID : Caller.Indices)
625 printTypeIndex(FieldName: "FuncID", TI: FuncID);
626 return Error::success();
627}
628
629Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
630 RegRelativeSym &RegRel) {
631 W.printHex(Label: "Offset", Value: RegRel.Offset);
632 printTypeIndex(FieldName: "Type", TI: RegRel.Type);
633 W.printEnum(Label: "Register", Value: uint16_t(RegRel.Register),
634 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
635 W.printString(Label: "VarName", Value: RegRel.Name);
636 return Error::success();
637}
638
639Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
640 RegRelativeIndirSym &RegRelIndir) {
641 W.printHex(Label: "Offset", Value: RegRelIndir.Offset);
642 printTypeIndex(FieldName: "Type", TI: RegRelIndir.Type);
643 W.printEnum(Label: "Register", Value: uint16_t(RegRelIndir.Register),
644 EnumValues: getRegisterNames(Cpu: CompilationCPUType));
645 W.printHex(Label: "OffsetInUdt", Value: RegRelIndir.OffsetInUdt);
646 W.printString(Label: "VarName", Value: RegRelIndir.Name);
647 return Error::success();
648}
649
650Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
651 ThreadLocalDataSym &Data) {
652 StringRef LinkageName;
653 if (ObjDelegate) {
654 ObjDelegate->printRelocatedField(Label: "DataOffset", RelocOffset: Data.getRelocationOffset(),
655 Offset: Data.DataOffset, RelocSym: &LinkageName);
656 }
657 printTypeIndex(FieldName: "Type", TI: Data.Type);
658 W.printString(Label: "DisplayName", Value: Data.Name);
659 if (!LinkageName.empty())
660 W.printString(Label: "LinkageName", Value: LinkageName);
661 return Error::success();
662}
663
664Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
665 printTypeIndex(FieldName: "Type", TI: UDT.Type);
666 W.printString(Label: "UDTName", Value: UDT.Name);
667 return Error::success();
668}
669
670Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
671 UsingNamespaceSym &UN) {
672 W.printString(Label: "Namespace", Value: UN.Name);
673 return Error::success();
674}
675
676Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
677 AnnotationSym &Annot) {
678 W.printHex(Label: "Offset", Value: Annot.CodeOffset);
679 W.printHex(Label: "Segment", Value: Annot.Segment);
680
681 ListScope S(W, "Strings");
682 for (StringRef Str : Annot.Strings)
683 W.printString(Value: Str);
684
685 return Error::success();
686}
687
688Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
689 JumpTableSym &JumpTable) {
690 W.printHex(Label: "BaseOffset", Value: JumpTable.BaseOffset);
691 W.printNumber(Label: "BaseSegment", Value: JumpTable.BaseSegment);
692 W.printEnum(Label: "SwitchType", Value: static_cast<uint16_t>(JumpTable.SwitchType),
693 EnumValues: getJumpTableEntrySizeNames());
694 W.printHex(Label: "BranchOffset", Value: JumpTable.BranchOffset);
695 W.printHex(Label: "TableOffset", Value: JumpTable.TableOffset);
696 W.printNumber(Label: "BranchSegment", Value: JumpTable.BranchSegment);
697 W.printNumber(Label: "TableSegment", Value: JumpTable.TableSegment);
698 W.printNumber(Label: "EntriesCount", Value: JumpTable.EntriesCount);
699 return Error::success();
700}
701
702Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
703 HotPatchFuncSym &HotPatchFunc) {
704 printTypeIndex(FieldName: "Function", TI: HotPatchFunc.Function);
705 W.printString(Label: "Name", Value: HotPatchFunc.Name);
706 return Error::success();
707}
708
709Error CVSymbolDumperImpl::visitUnknownSymbol(CVSymbol &CVR) {
710 W.printNumber(Label: "Length", Value: CVR.length());
711 return Error::success();
712}
713
714Error CVSymbolDumper::dump(CVRecord<SymbolKind> &Record) {
715 SymbolVisitorCallbackPipeline Pipeline;
716 SymbolDeserializer Deserializer(ObjDelegate.get(), Container);
717 CVSymbolDumperImpl Dumper(Types, ObjDelegate.get(), W, CompilationCPUType,
718 PrintRecordBytes);
719
720 Pipeline.addCallbackToPipeline(Callbacks&: Deserializer);
721 Pipeline.addCallbackToPipeline(Callbacks&: Dumper);
722 CVSymbolVisitor Visitor(Pipeline);
723 auto Err = Visitor.visitSymbolRecord(Record);
724 CompilationCPUType = Dumper.getCompilationCPUType();
725 return Err;
726}
727
728Error CVSymbolDumper::dump(const CVSymbolArray &Symbols) {
729 SymbolVisitorCallbackPipeline Pipeline;
730 SymbolDeserializer Deserializer(ObjDelegate.get(), Container);
731 CVSymbolDumperImpl Dumper(Types, ObjDelegate.get(), W, CompilationCPUType,
732 PrintRecordBytes);
733
734 Pipeline.addCallbackToPipeline(Callbacks&: Deserializer);
735 Pipeline.addCallbackToPipeline(Callbacks&: Dumper);
736 CVSymbolVisitor Visitor(Pipeline);
737 auto Err = Visitor.visitSymbolStream(Symbols);
738 CompilationCPUType = Dumper.getCompilationCPUType();
739 return Err;
740}
741