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