blob: 45b63983beb499fbaa8a913590140485eacc1f3a [file] [log] [blame]
Zachary Turneraaad5742016-05-23 23:41:13 +00001//===-- SymbolDumper.cpp - CodeView symbol info dumper ----------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Zachary Turneraaad5742016-05-23 23:41:13 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
Zachary Turneraaad5742016-05-23 23:41:13 +000010#include "llvm/ADT/SmallString.h"
11#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
Zachary Turner591312c2017-05-30 17:13:33 +000012#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000013#include "llvm/DebugInfo/CodeView/EnumTables.h"
Zachary Turner0d840742016-10-07 21:34:46 +000014#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
Zachary Turneraaad5742016-05-23 23:41:13 +000015#include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h"
16#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
Zachary Turner0d840742016-10-07 21:34:46 +000017#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbackPipeline.h"
18#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
Zachary Turneraaad5742016-05-23 23:41:13 +000019#include "llvm/DebugInfo/CodeView/TypeIndex.h"
Zachary Turner0d840742016-10-07 21:34:46 +000020#include "llvm/Support/Error.h"
Zachary Turneraaad5742016-05-23 23:41:13 +000021#include "llvm/Support/ScopedPrinter.h"
22
23#include <system_error>
24
25using namespace llvm;
26using namespace llvm::codeview;
27
Zachary Turneraaad5742016-05-23 23:41:13 +000028namespace {
Zachary Turneraaad5742016-05-23 23:41:13 +000029/// Use this private dumper implementation to keep implementation details about
30/// the visitor out of SymbolDumper.h.
Zachary Turner0d840742016-10-07 21:34:46 +000031class CVSymbolDumperImpl : public SymbolVisitorCallbacks {
Zachary Turneraaad5742016-05-23 23:41:13 +000032public:
Zachary Turner526f4f22017-05-19 19:26:58 +000033 CVSymbolDumperImpl(TypeCollection &Types, SymbolDumpDelegate *ObjDelegate,
Reid Klecknera6f64262018-09-11 22:00:50 +000034 ScopedPrinter &W, CPUType CPU, bool PrintRecordBytes)
35 : Types(Types), ObjDelegate(ObjDelegate), W(W), CompilationCPUType(CPU),
Zachary Turner0d840742016-10-07 21:34:46 +000036 PrintRecordBytes(PrintRecordBytes), InFunctionScope(false) {}
Zachary Turneraaad5742016-05-23 23:41:13 +000037
38/// CVSymbolVisitor overrides.
39#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
Zachary Turner0d840742016-10-07 21:34:46 +000040 Error visitKnownRecord(CVSymbol &CVR, Name &Record) override;
Zachary Turneraaad5742016-05-23 23:41:13 +000041#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
Zachary Turnerd4273832017-05-30 21:53:05 +000042#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
Zachary Turneraaad5742016-05-23 23:41:13 +000043
Zachary Turner0d840742016-10-07 21:34:46 +000044 Error visitSymbolBegin(CVSymbol &Record) override;
45 Error visitSymbolEnd(CVSymbol &Record) override;
46 Error visitUnknownSymbol(CVSymbol &Record) override;
Zachary Turneraaad5742016-05-23 23:41:13 +000047
Reid Klecknera6f64262018-09-11 22:00:50 +000048 CPUType getCompilationCPUType() const { return CompilationCPUType; }
49
Zachary Turneraaad5742016-05-23 23:41:13 +000050private:
51 void printLocalVariableAddrRange(const LocalVariableAddrRange &Range,
52 uint32_t RelocationOffset);
53 void printLocalVariableAddrGap(ArrayRef<LocalVariableAddrGap> Gaps);
Zachary Turner629cb7d2017-01-11 23:24:22 +000054 void printTypeIndex(StringRef FieldName, TypeIndex TI);
Zachary Turneraaad5742016-05-23 23:41:13 +000055
Zachary Turner526f4f22017-05-19 19:26:58 +000056 TypeCollection &Types;
Zachary Turneraaad5742016-05-23 23:41:13 +000057 SymbolDumpDelegate *ObjDelegate;
58 ScopedPrinter &W;
59
Reid Klecknera6f64262018-09-11 22:00:50 +000060 /// Save the machine or CPU type when dumping a compile symbols.
61 CPUType CompilationCPUType = CPUType::X64;
62
Zachary Turneraaad5742016-05-23 23:41:13 +000063 bool PrintRecordBytes;
64 bool InFunctionScope;
65};
66}
67
Reid Kleckner8d8888f2017-07-11 23:41:41 +000068static StringRef getSymbolKindName(SymbolKind Kind) {
69 switch (Kind) {
70#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
71 case EnumName: \
72 return #Name;
73#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
74 default:
75 break;
76 }
77 return "UnknownSym";
78}
79
Zachary Turneraaad5742016-05-23 23:41:13 +000080void CVSymbolDumperImpl::printLocalVariableAddrRange(
81 const LocalVariableAddrRange &Range, uint32_t RelocationOffset) {
82 DictScope S(W, "LocalVariableAddrRange");
83 if (ObjDelegate)
84 ObjDelegate->printRelocatedField("OffsetStart", RelocationOffset,
85 Range.OffsetStart);
86 W.printHex("ISectStart", Range.ISectStart);
87 W.printHex("Range", Range.Range);
88}
89
90void CVSymbolDumperImpl::printLocalVariableAddrGap(
91 ArrayRef<LocalVariableAddrGap> Gaps) {
92 for (auto &Gap : Gaps) {
93 ListScope S(W, "LocalVariableAddrGap");
94 W.printHex("GapStartOffset", Gap.GapStartOffset);
95 W.printHex("Range", Gap.Range);
96 }
97}
98
Zachary Turner629cb7d2017-01-11 23:24:22 +000099void CVSymbolDumperImpl::printTypeIndex(StringRef FieldName, TypeIndex TI) {
Zachary Turner526f4f22017-05-19 19:26:58 +0000100 codeview::printTypeIndex(W, FieldName, TI, Types);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000101}
102
Zachary Turner0d840742016-10-07 21:34:46 +0000103Error CVSymbolDumperImpl::visitSymbolBegin(CVSymbol &CVR) {
Reid Klecknere10d0042019-04-04 00:28:48 +0000104 W.startLine() << getSymbolKindName(CVR.kind());
Reid Kleckner8d8888f2017-07-11 23:41:41 +0000105 W.getOStream() << " {\n";
106 W.indent();
Reid Klecknere10d0042019-04-04 00:28:48 +0000107 W.printEnum("Kind", unsigned(CVR.kind()), getSymbolTypeNames());
Zachary Turner0d840742016-10-07 21:34:46 +0000108 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000109}
110
Zachary Turner0d840742016-10-07 21:34:46 +0000111Error CVSymbolDumperImpl::visitSymbolEnd(CVSymbol &CVR) {
112 if (PrintRecordBytes && ObjDelegate)
113 ObjDelegate->printBinaryBlockWithRelocs("SymData", CVR.content());
Reid Kleckner8d8888f2017-07-11 23:41:41 +0000114
115 W.unindent();
116 W.startLine() << "}\n";
Zachary Turner0d840742016-10-07 21:34:46 +0000117 return Error::success();
118}
119
120Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000121 StringRef LinkageName;
Zachary Turner46225b12016-12-16 22:48:14 +0000122 W.printHex("PtrParent", Block.Parent);
123 W.printHex("PtrEnd", Block.End);
124 W.printHex("CodeSize", Block.CodeSize);
Zachary Turneraaad5742016-05-23 23:41:13 +0000125 if (ObjDelegate) {
126 ObjDelegate->printRelocatedField("CodeOffset", Block.getRelocationOffset(),
Zachary Turner46225b12016-12-16 22:48:14 +0000127 Block.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000128 }
Zachary Turner46225b12016-12-16 22:48:14 +0000129 W.printHex("Segment", Block.Segment);
Zachary Turneraaad5742016-05-23 23:41:13 +0000130 W.printString("BlockName", Block.Name);
131 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000132 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000133}
134
Zachary Turner0d840742016-10-07 21:34:46 +0000135Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
Brock Wyma94ece8f2018-04-16 16:53:57 +0000136 W.printString("Name", Thunk.Name);
Zachary Turner46225b12016-12-16 22:48:14 +0000137 W.printNumber("Parent", Thunk.Parent);
138 W.printNumber("End", Thunk.End);
139 W.printNumber("Next", Thunk.Next);
140 W.printNumber("Off", Thunk.Offset);
141 W.printNumber("Seg", Thunk.Segment);
142 W.printNumber("Len", Thunk.Length);
143 W.printEnum("Ordinal", uint8_t(Thunk.Thunk), getThunkOrdinalNames());
Zachary Turner0d840742016-10-07 21:34:46 +0000144 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000145}
146
Zachary Turner0d840742016-10-07 21:34:46 +0000147Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
148 TrampolineSym &Tramp) {
Zachary Turner46225b12016-12-16 22:48:14 +0000149 W.printEnum("Type", uint16_t(Tramp.Type), getTrampolineNames());
150 W.printNumber("Size", Tramp.Size);
151 W.printNumber("ThunkOff", Tramp.ThunkOffset);
152 W.printNumber("TargetOff", Tramp.TargetOffset);
153 W.printNumber("ThunkSection", Tramp.ThunkSection);
154 W.printNumber("TargetSection", Tramp.TargetSection);
Zachary Turner0d840742016-10-07 21:34:46 +0000155 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000156}
157
Zachary Turner0d840742016-10-07 21:34:46 +0000158Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, SectionSym &Section) {
Zachary Turner46225b12016-12-16 22:48:14 +0000159 W.printNumber("SectionNumber", Section.SectionNumber);
160 W.printNumber("Alignment", Section.Alignment);
161 W.printNumber("Rva", Section.Rva);
162 W.printNumber("Length", Section.Length);
163 W.printFlags("Characteristics", Section.Characteristics,
Zachary Turner93839cb2016-06-02 05:07:49 +0000164 getImageSectionCharacteristicNames(),
165 COFF::SectionCharacteristics(0x00F00000));
166
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000167 W.printString("Name", Section.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000168 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000169}
170
Zachary Turner0d840742016-10-07 21:34:46 +0000171Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000172 CoffGroupSym &CoffGroup) {
Zachary Turner46225b12016-12-16 22:48:14 +0000173 W.printNumber("Size", CoffGroup.Size);
174 W.printFlags("Characteristics", CoffGroup.Characteristics,
Zachary Turner93839cb2016-06-02 05:07:49 +0000175 getImageSectionCharacteristicNames(),
176 COFF::SectionCharacteristics(0x00F00000));
Zachary Turner46225b12016-12-16 22:48:14 +0000177 W.printNumber("Offset", CoffGroup.Offset);
178 W.printNumber("Segment", CoffGroup.Segment);
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000179 W.printString("Name", CoffGroup.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000180 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000181}
182
Zachary Turner0d840742016-10-07 21:34:46 +0000183Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
184 BPRelativeSym &BPRel) {
Zachary Turner46225b12016-12-16 22:48:14 +0000185 W.printNumber("Offset", BPRel.Offset);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000186 printTypeIndex("Type", BPRel.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000187 W.printString("VarName", BPRel.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000188 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000189}
190
Zachary Turner0d840742016-10-07 21:34:46 +0000191Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
Zachary Turneraaad5742016-05-23 23:41:13 +0000192 BuildInfoSym &BuildInfo) {
Reid Kleckneraf88a912017-07-15 18:10:39 +0000193 printTypeIndex("BuildId", BuildInfo.BuildId);
Zachary Turner0d840742016-10-07 21:34:46 +0000194 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000195}
196
Zachary Turner0d840742016-10-07 21:34:46 +0000197Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
198 CallSiteInfoSym &CallSiteInfo) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000199 StringRef LinkageName;
200 if (ObjDelegate) {
Zachary Turner46225b12016-12-16 22:48:14 +0000201 ObjDelegate->printRelocatedField("CodeOffset",
202 CallSiteInfo.getRelocationOffset(),
203 CallSiteInfo.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000204 }
Zachary Turner46225b12016-12-16 22:48:14 +0000205 W.printHex("Segment", CallSiteInfo.Segment);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000206 printTypeIndex("Type", CallSiteInfo.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000207 if (!LinkageName.empty())
208 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000209 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000210}
211
Zachary Turner0d840742016-10-07 21:34:46 +0000212Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
213 EnvBlockSym &EnvBlock) {
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000214 ListScope L(W, "Entries");
215 for (auto Entry : EnvBlock.Fields) {
216 W.printString(Entry);
217 }
Zachary Turner0d840742016-10-07 21:34:46 +0000218 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000219}
220
Zachary Turner0d840742016-10-07 21:34:46 +0000221Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
222 FileStaticSym &FileStatic) {
Zachary Turner63055452017-06-15 22:24:24 +0000223 printTypeIndex("Index", FileStatic.Index);
Zachary Turner46225b12016-12-16 22:48:14 +0000224 W.printNumber("ModFilenameOffset", FileStatic.ModFilenameOffset);
225 W.printFlags("Flags", uint16_t(FileStatic.Flags), getLocalFlagNames());
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000226 W.printString("Name", FileStatic.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000227 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000228}
229
Zachary Turner0d840742016-10-07 21:34:46 +0000230Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
Zachary Turner46225b12016-12-16 22:48:14 +0000231 W.printNumber("Ordinal", Export.Ordinal);
232 W.printFlags("Flags", uint16_t(Export.Flags), getExportSymFlagNames());
Zachary Turner9f054d42016-05-25 00:12:40 +0000233 W.printString("Name", Export.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000234 return Error::success();
Zachary Turner9f054d42016-05-25 00:12:40 +0000235}
236
Zachary Turner0d840742016-10-07 21:34:46 +0000237Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
238 Compile2Sym &Compile2) {
Zachary Turner46225b12016-12-16 22:48:14 +0000239 W.printEnum("Language", Compile2.getLanguage(), getSourceLanguageNames());
240 W.printFlags("Flags", Compile2.getFlags(), getCompileSym2FlagNames());
241 W.printEnum("Machine", unsigned(Compile2.Machine), getCPUTypeNames());
Reid Klecknera6f64262018-09-11 22:00:50 +0000242 CompilationCPUType = Compile2.Machine;
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000243 std::string FrontendVersion;
244 {
245 raw_string_ostream Out(FrontendVersion);
Zachary Turner46225b12016-12-16 22:48:14 +0000246 Out << Compile2.VersionFrontendMajor << '.' << Compile2.VersionFrontendMinor
247 << '.' << Compile2.VersionFrontendBuild;
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000248 }
249 std::string BackendVersion;
250 {
251 raw_string_ostream Out(BackendVersion);
Zachary Turner46225b12016-12-16 22:48:14 +0000252 Out << Compile2.VersionBackendMajor << '.' << Compile2.VersionBackendMinor
253 << '.' << Compile2.VersionBackendBuild;
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000254 }
255 W.printString("FrontendVersion", FrontendVersion);
256 W.printString("BackendVersion", BackendVersion);
257 W.printString("VersionName", Compile2.Version);
Zachary Turner0d840742016-10-07 21:34:46 +0000258 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000259}
260
Zachary Turner0d840742016-10-07 21:34:46 +0000261Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
262 Compile3Sym &Compile3) {
Zachary Turner9f6ac4c2018-10-08 04:34:41 +0000263 W.printEnum("Language", uint8_t(Compile3.getLanguage()), getSourceLanguageNames());
Zachary Turner94926a62018-10-08 04:19:16 +0000264 W.printFlags("Flags", uint32_t(Compile3.getFlags()),
265 getCompileSym3FlagNames());
Zachary Turner46225b12016-12-16 22:48:14 +0000266 W.printEnum("Machine", unsigned(Compile3.Machine), getCPUTypeNames());
Reid Klecknera6f64262018-09-11 22:00:50 +0000267 CompilationCPUType = Compile3.Machine;
Zachary Turneraaad5742016-05-23 23:41:13 +0000268 std::string FrontendVersion;
269 {
270 raw_string_ostream Out(FrontendVersion);
Zachary Turner46225b12016-12-16 22:48:14 +0000271 Out << Compile3.VersionFrontendMajor << '.' << Compile3.VersionFrontendMinor
272 << '.' << Compile3.VersionFrontendBuild << '.'
273 << Compile3.VersionFrontendQFE;
Zachary Turneraaad5742016-05-23 23:41:13 +0000274 }
275 std::string BackendVersion;
276 {
277 raw_string_ostream Out(BackendVersion);
Zachary Turner46225b12016-12-16 22:48:14 +0000278 Out << Compile3.VersionBackendMajor << '.' << Compile3.VersionBackendMinor
279 << '.' << Compile3.VersionBackendBuild << '.'
280 << Compile3.VersionBackendQFE;
Zachary Turneraaad5742016-05-23 23:41:13 +0000281 }
282 W.printString("FrontendVersion", FrontendVersion);
283 W.printString("BackendVersion", BackendVersion);
284 W.printString("VersionName", Compile3.Version);
Zachary Turner0d840742016-10-07 21:34:46 +0000285 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000286}
287
Zachary Turner0d840742016-10-07 21:34:46 +0000288Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
289 ConstantSym &Constant) {
Zachary Turner629cb7d2017-01-11 23:24:22 +0000290 printTypeIndex("Type", Constant.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000291 W.printNumber("Value", Constant.Value);
292 W.printString("Name", Constant.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000293 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000294}
295
Zachary Turner0d840742016-10-07 21:34:46 +0000296Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000297 StringRef LinkageName;
298 if (ObjDelegate) {
299 ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
Zachary Turner46225b12016-12-16 22:48:14 +0000300 Data.DataOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000301 }
Zachary Turner629cb7d2017-01-11 23:24:22 +0000302 printTypeIndex("Type", Data.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000303 W.printString("DisplayName", Data.Name);
304 if (!LinkageName.empty())
305 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000306 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000307}
308
Zachary Turner0d840742016-10-07 21:34:46 +0000309Error CVSymbolDumperImpl::visitKnownRecord(
310 CVSymbol &CVR,
Zachary Turneraaad5742016-05-23 23:41:13 +0000311 DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
Zachary Turner46225b12016-12-16 22:48:14 +0000312 W.printNumber("Offset", DefRangeFramePointerRelFullScope.Offset);
Zachary Turner0d840742016-10-07 21:34:46 +0000313 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000314}
315
Zachary Turner0d840742016-10-07 21:34:46 +0000316Error CVSymbolDumperImpl::visitKnownRecord(
317 CVSymbol &CVR, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
Nilanjana Basuda60fc82019-08-05 14:16:58 +0000318 W.printNumber("Offset", DefRangeFramePointerRel.Hdr.Offset);
Zachary Turner46225b12016-12-16 22:48:14 +0000319 printLocalVariableAddrRange(DefRangeFramePointerRel.Range,
Zachary Turneraaad5742016-05-23 23:41:13 +0000320 DefRangeFramePointerRel.getRelocationOffset());
321 printLocalVariableAddrGap(DefRangeFramePointerRel.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000322 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000323}
324
Zachary Turner0d840742016-10-07 21:34:46 +0000325Error CVSymbolDumperImpl::visitKnownRecord(
326 CVSymbol &CVR, DefRangeRegisterRelSym &DefRangeRegisterRel) {
Hans Wennborgea89ff72017-10-02 17:44:47 +0000327 W.printEnum("BaseRegister", uint16_t(DefRangeRegisterRel.Hdr.Register),
Tom Taneb4d6142019-05-31 23:43:31 +0000328 getRegisterNames(CompilationCPUType));
Zachary Turneraaad5742016-05-23 23:41:13 +0000329 W.printBoolean("HasSpilledUDTMember",
330 DefRangeRegisterRel.hasSpilledUDTMember());
331 W.printNumber("OffsetInParent", DefRangeRegisterRel.offsetInParent());
Zachary Turner46225b12016-12-16 22:48:14 +0000332 W.printNumber("BasePointerOffset", DefRangeRegisterRel.Hdr.BasePointerOffset);
333 printLocalVariableAddrRange(DefRangeRegisterRel.Range,
Zachary Turneraaad5742016-05-23 23:41:13 +0000334 DefRangeRegisterRel.getRelocationOffset());
335 printLocalVariableAddrGap(DefRangeRegisterRel.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000336 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000337}
338
Zachary Turner0d840742016-10-07 21:34:46 +0000339Error CVSymbolDumperImpl::visitKnownRecord(
340 CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
Hans Wennborgea89ff72017-10-02 17:44:47 +0000341 W.printEnum("Register", uint16_t(DefRangeRegister.Hdr.Register),
Tom Taneb4d6142019-05-31 23:43:31 +0000342 getRegisterNames(CompilationCPUType));
Zachary Turner46225b12016-12-16 22:48:14 +0000343 W.printNumber("MayHaveNoName", DefRangeRegister.Hdr.MayHaveNoName);
344 printLocalVariableAddrRange(DefRangeRegister.Range,
Zachary Turneraaad5742016-05-23 23:41:13 +0000345 DefRangeRegister.getRelocationOffset());
346 printLocalVariableAddrGap(DefRangeRegister.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000347 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000348}
349
Zachary Turner0d840742016-10-07 21:34:46 +0000350Error CVSymbolDumperImpl::visitKnownRecord(
351 CVSymbol &CVR, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
Hans Wennborgea89ff72017-10-02 17:44:47 +0000352 W.printEnum("Register", uint16_t(DefRangeSubfieldRegister.Hdr.Register),
Tom Taneb4d6142019-05-31 23:43:31 +0000353 getRegisterNames(CompilationCPUType));
Zachary Turner46225b12016-12-16 22:48:14 +0000354 W.printNumber("MayHaveNoName", DefRangeSubfieldRegister.Hdr.MayHaveNoName);
355 W.printNumber("OffsetInParent", DefRangeSubfieldRegister.Hdr.OffsetInParent);
356 printLocalVariableAddrRange(DefRangeSubfieldRegister.Range,
Zachary Turneraaad5742016-05-23 23:41:13 +0000357 DefRangeSubfieldRegister.getRelocationOffset());
358 printLocalVariableAddrGap(DefRangeSubfieldRegister.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000359 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000360}
361
Zachary Turner0d840742016-10-07 21:34:46 +0000362Error CVSymbolDumperImpl::visitKnownRecord(
363 CVSymbol &CVR, DefRangeSubfieldSym &DefRangeSubfield) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000364 if (ObjDelegate) {
Zachary Turner591312c2017-05-30 17:13:33 +0000365 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
Zachary Turner2d5c2cd2017-05-03 17:11:11 +0000366 auto ExpectedProgram = Strings.getString(DefRangeSubfield.Program);
367 if (!ExpectedProgram) {
368 consumeError(ExpectedProgram.takeError());
Zachary Turner0d840742016-10-07 21:34:46 +0000369 return llvm::make_error<CodeViewError>(
370 "String table offset outside of bounds of String Table!");
Zachary Turner2d5c2cd2017-05-03 17:11:11 +0000371 }
372 W.printString("Program", *ExpectedProgram);
Zachary Turneraaad5742016-05-23 23:41:13 +0000373 }
Zachary Turner46225b12016-12-16 22:48:14 +0000374 W.printNumber("OffsetInParent", DefRangeSubfield.OffsetInParent);
375 printLocalVariableAddrRange(DefRangeSubfield.Range,
Zachary Turneraaad5742016-05-23 23:41:13 +0000376 DefRangeSubfield.getRelocationOffset());
377 printLocalVariableAddrGap(DefRangeSubfield.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000378 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000379}
380
Zachary Turner0d840742016-10-07 21:34:46 +0000381Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
382 DefRangeSym &DefRange) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000383 if (ObjDelegate) {
Zachary Turner591312c2017-05-30 17:13:33 +0000384 DebugStringTableSubsectionRef Strings = ObjDelegate->getStringTable();
Zachary Turner2d5c2cd2017-05-03 17:11:11 +0000385 auto ExpectedProgram = Strings.getString(DefRange.Program);
386 if (!ExpectedProgram) {
387 consumeError(ExpectedProgram.takeError());
Zachary Turner0d840742016-10-07 21:34:46 +0000388 return llvm::make_error<CodeViewError>(
389 "String table offset outside of bounds of String Table!");
Zachary Turner2d5c2cd2017-05-03 17:11:11 +0000390 }
391 W.printString("Program", *ExpectedProgram);
Zachary Turneraaad5742016-05-23 23:41:13 +0000392 }
Zachary Turner46225b12016-12-16 22:48:14 +0000393 printLocalVariableAddrRange(DefRange.Range, DefRange.getRelocationOffset());
Zachary Turneraaad5742016-05-23 23:41:13 +0000394 printLocalVariableAddrGap(DefRange.Gaps);
Zachary Turner0d840742016-10-07 21:34:46 +0000395 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000396}
397
Zachary Turner0d840742016-10-07 21:34:46 +0000398Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
399 FrameCookieSym &FrameCookie) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000400 StringRef LinkageName;
401 if (ObjDelegate) {
Zachary Turner46225b12016-12-16 22:48:14 +0000402 ObjDelegate->printRelocatedField("CodeOffset",
403 FrameCookie.getRelocationOffset(),
404 FrameCookie.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000405 }
Tom Taneb4d6142019-05-31 23:43:31 +0000406 W.printEnum("Register", uint16_t(FrameCookie.Register),
407 getRegisterNames(CompilationCPUType));
Zachary Turner46225b12016-12-16 22:48:14 +0000408 W.printEnum("CookieKind", uint16_t(FrameCookie.CookieKind),
Zachary Turner93839cb2016-06-02 05:07:49 +0000409 getFrameCookieKindNames());
Zachary Turner46225b12016-12-16 22:48:14 +0000410 W.printHex("Flags", FrameCookie.Flags);
Zachary Turner0d840742016-10-07 21:34:46 +0000411 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000412}
413
Zachary Turner0d840742016-10-07 21:34:46 +0000414Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
Zachary Turneraaad5742016-05-23 23:41:13 +0000415 FrameProcSym &FrameProc) {
Zachary Turner46225b12016-12-16 22:48:14 +0000416 W.printHex("TotalFrameBytes", FrameProc.TotalFrameBytes);
417 W.printHex("PaddingFrameBytes", FrameProc.PaddingFrameBytes);
418 W.printHex("OffsetToPadding", FrameProc.OffsetToPadding);
Zachary Turneraaad5742016-05-23 23:41:13 +0000419 W.printHex("BytesOfCalleeSavedRegisters",
Zachary Turner46225b12016-12-16 22:48:14 +0000420 FrameProc.BytesOfCalleeSavedRegisters);
421 W.printHex("OffsetOfExceptionHandler", FrameProc.OffsetOfExceptionHandler);
Zachary Turneraaad5742016-05-23 23:41:13 +0000422 W.printHex("SectionIdOfExceptionHandler",
Zachary Turner46225b12016-12-16 22:48:14 +0000423 FrameProc.SectionIdOfExceptionHandler);
424 W.printFlags("Flags", static_cast<uint32_t>(FrameProc.Flags),
425 getFrameProcSymFlagNames());
Reid Klecknera6f64262018-09-11 22:00:50 +0000426 W.printEnum("LocalFramePtrReg",
427 uint16_t(FrameProc.getLocalFramePtrReg(CompilationCPUType)),
Tom Taneb4d6142019-05-31 23:43:31 +0000428 getRegisterNames(CompilationCPUType));
Reid Klecknera6f64262018-09-11 22:00:50 +0000429 W.printEnum("ParamFramePtrReg",
430 uint16_t(FrameProc.getParamFramePtrReg(CompilationCPUType)),
Tom Taneb4d6142019-05-31 23:43:31 +0000431 getRegisterNames(CompilationCPUType));
Zachary Turner0d840742016-10-07 21:34:46 +0000432 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000433}
434
Zachary Turner0d840742016-10-07 21:34:46 +0000435Error CVSymbolDumperImpl::visitKnownRecord(
436 CVSymbol &CVR, HeapAllocationSiteSym &HeapAllocSite) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000437 StringRef LinkageName;
438 if (ObjDelegate) {
Zachary Turner46225b12016-12-16 22:48:14 +0000439 ObjDelegate->printRelocatedField("CodeOffset",
440 HeapAllocSite.getRelocationOffset(),
441 HeapAllocSite.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000442 }
Zachary Turner46225b12016-12-16 22:48:14 +0000443 W.printHex("Segment", HeapAllocSite.Segment);
444 W.printHex("CallInstructionSize", HeapAllocSite.CallInstructionSize);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000445 printTypeIndex("Type", HeapAllocSite.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000446 if (!LinkageName.empty())
447 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000448 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000449}
450
Zachary Turner0d840742016-10-07 21:34:46 +0000451Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
452 InlineSiteSym &InlineSite) {
Zachary Turner46225b12016-12-16 22:48:14 +0000453 W.printHex("PtrParent", InlineSite.Parent);
454 W.printHex("PtrEnd", InlineSite.End);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000455 printTypeIndex("Inlinee", InlineSite.Inlinee);
Zachary Turneraaad5742016-05-23 23:41:13 +0000456
457 ListScope BinaryAnnotations(W, "BinaryAnnotations");
458 for (auto &Annotation : InlineSite.annotations()) {
459 switch (Annotation.OpCode) {
460 case BinaryAnnotationsOpCode::Invalid:
Zachary Turner42cb87f2017-03-17 00:15:27 +0000461 W.printString("(Annotation Padding)");
462 break;
Zachary Turneraaad5742016-05-23 23:41:13 +0000463 case BinaryAnnotationsOpCode::CodeOffset:
464 case BinaryAnnotationsOpCode::ChangeCodeOffset:
465 case BinaryAnnotationsOpCode::ChangeCodeLength:
466 W.printHex(Annotation.Name, Annotation.U1);
467 break;
468 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
469 case BinaryAnnotationsOpCode::ChangeLineEndDelta:
470 case BinaryAnnotationsOpCode::ChangeRangeKind:
471 case BinaryAnnotationsOpCode::ChangeColumnStart:
472 case BinaryAnnotationsOpCode::ChangeColumnEnd:
473 W.printNumber(Annotation.Name, Annotation.U1);
474 break;
475 case BinaryAnnotationsOpCode::ChangeLineOffset:
476 case BinaryAnnotationsOpCode::ChangeColumnEndDelta:
477 W.printNumber(Annotation.Name, Annotation.S1);
478 break;
479 case BinaryAnnotationsOpCode::ChangeFile:
480 if (ObjDelegate) {
481 W.printHex("ChangeFile",
482 ObjDelegate->getFileNameForFileOffset(Annotation.U1),
483 Annotation.U1);
484 } else {
485 W.printHex("ChangeFile", Annotation.U1);
486 }
487
488 break;
489 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset: {
490 W.startLine() << "ChangeCodeOffsetAndLineOffset: {CodeOffset: "
491 << W.hex(Annotation.U1) << ", LineOffset: " << Annotation.S1
492 << "}\n";
493 break;
494 }
495 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset: {
496 W.startLine() << "ChangeCodeLengthAndCodeOffset: {CodeOffset: "
497 << W.hex(Annotation.U2)
498 << ", Length: " << W.hex(Annotation.U1) << "}\n";
499 break;
500 }
501 }
502 }
Zachary Turner0d840742016-10-07 21:34:46 +0000503 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000504}
505
Zachary Turner0d840742016-10-07 21:34:46 +0000506Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
507 RegisterSym &Register) {
Zachary Turner63055452017-06-15 22:24:24 +0000508 printTypeIndex("Type", Register.Index);
Tom Taneb4d6142019-05-31 23:43:31 +0000509 W.printEnum("Seg", uint16_t(Register.Register),
510 getRegisterNames(CompilationCPUType));
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000511 W.printString("Name", Register.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000512 return Error::success();
Zachary Turner4caa1bf2016-05-24 22:58:46 +0000513}
514
Zachary Turner0d840742016-10-07 21:34:46 +0000515Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, PublicSym32 &Public) {
Reid Kleckner18d90e12017-06-19 16:54:51 +0000516 W.printFlags("Flags", uint32_t(Public.Flags), getPublicSymFlagNames());
Zachary Turner46225b12016-12-16 22:48:14 +0000517 W.printNumber("Seg", Public.Segment);
518 W.printNumber("Off", Public.Offset);
Zachary Turner9e33e6f2016-05-24 18:55:14 +0000519 W.printString("Name", Public.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000520 return Error::success();
Zachary Turner9e33e6f2016-05-24 18:55:14 +0000521}
522
Zachary Turner0d840742016-10-07 21:34:46 +0000523Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcRefSym &ProcRef) {
Zachary Turner46225b12016-12-16 22:48:14 +0000524 W.printNumber("SumName", ProcRef.SumName);
525 W.printNumber("SymOffset", ProcRef.SymOffset);
526 W.printNumber("Mod", ProcRef.Module);
Zachary Turner9e33e6f2016-05-24 18:55:14 +0000527 W.printString("Name", ProcRef.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000528 return Error::success();
Zachary Turner9e33e6f2016-05-24 18:55:14 +0000529}
530
Zachary Turner0d840742016-10-07 21:34:46 +0000531Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000532 StringRef LinkageName;
533 if (ObjDelegate) {
534 ObjDelegate->printRelocatedField("CodeOffset", Label.getRelocationOffset(),
Zachary Turner46225b12016-12-16 22:48:14 +0000535 Label.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000536 }
Zachary Turner46225b12016-12-16 22:48:14 +0000537 W.printHex("Segment", Label.Segment);
538 W.printHex("Flags", uint8_t(Label.Flags));
539 W.printFlags("Flags", uint8_t(Label.Flags), getProcSymFlagNames());
Zachary Turneraaad5742016-05-23 23:41:13 +0000540 W.printString("DisplayName", Label.Name);
541 if (!LinkageName.empty())
542 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000543 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000544}
545
Zachary Turner0d840742016-10-07 21:34:46 +0000546Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
Zachary Turner629cb7d2017-01-11 23:24:22 +0000547 printTypeIndex("Type", Local.Type);
Zachary Turner46225b12016-12-16 22:48:14 +0000548 W.printFlags("Flags", uint16_t(Local.Flags), getLocalFlagNames());
Zachary Turneraaad5742016-05-23 23:41:13 +0000549 W.printString("VarName", Local.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000550 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000551}
552
Zachary Turner0d840742016-10-07 21:34:46 +0000553Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ObjNameSym &ObjName) {
Zachary Turner46225b12016-12-16 22:48:14 +0000554 W.printHex("Signature", ObjName.Signature);
Zachary Turneraaad5742016-05-23 23:41:13 +0000555 W.printString("ObjectName", ObjName.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000556 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000557}
558
Zachary Turner0d840742016-10-07 21:34:46 +0000559Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000560 if (InFunctionScope)
Zachary Turner0d840742016-10-07 21:34:46 +0000561 return llvm::make_error<CodeViewError>(
562 "Visiting a ProcSym while inside function scope!");
Zachary Turneraaad5742016-05-23 23:41:13 +0000563
564 InFunctionScope = true;
565
566 StringRef LinkageName;
Zachary Turner46225b12016-12-16 22:48:14 +0000567 W.printHex("PtrParent", Proc.Parent);
568 W.printHex("PtrEnd", Proc.End);
569 W.printHex("PtrNext", Proc.Next);
570 W.printHex("CodeSize", Proc.CodeSize);
571 W.printHex("DbgStart", Proc.DbgStart);
572 W.printHex("DbgEnd", Proc.DbgEnd);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000573 printTypeIndex("FunctionType", Proc.FunctionType);
Zachary Turneraaad5742016-05-23 23:41:13 +0000574 if (ObjDelegate) {
575 ObjDelegate->printRelocatedField("CodeOffset", Proc.getRelocationOffset(),
Zachary Turner46225b12016-12-16 22:48:14 +0000576 Proc.CodeOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000577 }
Zachary Turner46225b12016-12-16 22:48:14 +0000578 W.printHex("Segment", Proc.Segment);
579 W.printFlags("Flags", static_cast<uint8_t>(Proc.Flags),
Zachary Turner93839cb2016-06-02 05:07:49 +0000580 getProcSymFlagNames());
Zachary Turneraaad5742016-05-23 23:41:13 +0000581 W.printString("DisplayName", Proc.Name);
582 if (!LinkageName.empty())
583 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000584 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000585}
586
Zachary Turner0d840742016-10-07 21:34:46 +0000587Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
588 ScopeEndSym &ScopeEnd) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000589 InFunctionScope = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000590 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000591}
592
Zachary Turner0d840742016-10-07 21:34:46 +0000593Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
594 ListScope S(W, CVR.kind() == S_CALLEES ? "Callees" : "Callers");
Zachary Turneraaad5742016-05-23 23:41:13 +0000595 for (auto FuncID : Caller.Indices)
Zachary Turner629cb7d2017-01-11 23:24:22 +0000596 printTypeIndex("FuncID", FuncID);
Zachary Turner0d840742016-10-07 21:34:46 +0000597 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000598}
599
Zachary Turner0d840742016-10-07 21:34:46 +0000600Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
601 RegRelativeSym &RegRel) {
Zachary Turner46225b12016-12-16 22:48:14 +0000602 W.printHex("Offset", RegRel.Offset);
Zachary Turner629cb7d2017-01-11 23:24:22 +0000603 printTypeIndex("Type", RegRel.Type);
Tom Taneb4d6142019-05-31 23:43:31 +0000604 W.printEnum("Register", uint16_t(RegRel.Register),
605 getRegisterNames(CompilationCPUType));
Zachary Turneraaad5742016-05-23 23:41:13 +0000606 W.printString("VarName", RegRel.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000607 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000608}
609
Zachary Turner0d840742016-10-07 21:34:46 +0000610Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
611 ThreadLocalDataSym &Data) {
Zachary Turneraaad5742016-05-23 23:41:13 +0000612 StringRef LinkageName;
613 if (ObjDelegate) {
614 ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
Zachary Turner46225b12016-12-16 22:48:14 +0000615 Data.DataOffset, &LinkageName);
Zachary Turneraaad5742016-05-23 23:41:13 +0000616 }
Zachary Turner629cb7d2017-01-11 23:24:22 +0000617 printTypeIndex("Type", Data.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000618 W.printString("DisplayName", Data.Name);
619 if (!LinkageName.empty())
620 W.printString("LinkageName", LinkageName);
Zachary Turner0d840742016-10-07 21:34:46 +0000621 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000622}
623
Zachary Turner0d840742016-10-07 21:34:46 +0000624Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
Zachary Turner629cb7d2017-01-11 23:24:22 +0000625 printTypeIndex("Type", UDT.Type);
Zachary Turneraaad5742016-05-23 23:41:13 +0000626 W.printString("UDTName", UDT.Name);
Zachary Turner0d840742016-10-07 21:34:46 +0000627 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000628}
629
Alexandre Ganeaee8a7202018-07-31 19:15:50 +0000630Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
631 UsingNamespaceSym &UN) {
632 W.printString("Namespace", UN.Name);
633 return Error::success();
634}
635
Reid Kleckner7c438c52019-05-15 20:53:39 +0000636Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
637 AnnotationSym &Annot) {
638 W.printHex("Offset", Annot.CodeOffset);
639 W.printHex("Segment", Annot.Segment);
640
641 ListScope S(W, "Strings");
642 for (StringRef Str : Annot.Strings)
643 W.printString(Str);
644
645 return Error::success();
646}
647
Zachary Turner0d840742016-10-07 21:34:46 +0000648Error CVSymbolDumperImpl::visitUnknownSymbol(CVSymbol &CVR) {
Zachary Turner0d840742016-10-07 21:34:46 +0000649 W.printNumber("Length", CVR.length());
650 return Error::success();
Zachary Turneraaad5742016-05-23 23:41:13 +0000651}
652
Zachary Turner0d840742016-10-07 21:34:46 +0000653Error CVSymbolDumper::dump(CVRecord<SymbolKind> &Record) {
654 SymbolVisitorCallbackPipeline Pipeline;
Zachary Turnerebd3ae82017-06-01 21:52:41 +0000655 SymbolDeserializer Deserializer(ObjDelegate.get(), Container);
Reid Klecknera6f64262018-09-11 22:00:50 +0000656 CVSymbolDumperImpl Dumper(Types, ObjDelegate.get(), W, CompilationCPUType,
657 PrintRecordBytes);
Zachary Turner0d840742016-10-07 21:34:46 +0000658
659 Pipeline.addCallbackToPipeline(Deserializer);
660 Pipeline.addCallbackToPipeline(Dumper);
661 CVSymbolVisitor Visitor(Pipeline);
Reid Klecknera6f64262018-09-11 22:00:50 +0000662 auto Err = Visitor.visitSymbolRecord(Record);
663 CompilationCPUType = Dumper.getCompilationCPUType();
664 return Err;
Zachary Turneraaad5742016-05-23 23:41:13 +0000665}
666
Zachary Turner0d840742016-10-07 21:34:46 +0000667Error CVSymbolDumper::dump(const CVSymbolArray &Symbols) {
668 SymbolVisitorCallbackPipeline Pipeline;
Zachary Turnerebd3ae82017-06-01 21:52:41 +0000669 SymbolDeserializer Deserializer(ObjDelegate.get(), Container);
Reid Klecknera6f64262018-09-11 22:00:50 +0000670 CVSymbolDumperImpl Dumper(Types, ObjDelegate.get(), W, CompilationCPUType,
671 PrintRecordBytes);
Zachary Turner0d840742016-10-07 21:34:46 +0000672
673 Pipeline.addCallbackToPipeline(Deserializer);
674 Pipeline.addCallbackToPipeline(Dumper);
675 CVSymbolVisitor Visitor(Pipeline);
Reid Klecknera6f64262018-09-11 22:00:50 +0000676 auto Err = Visitor.visitSymbolStream(Symbols);
677 CompilationCPUType = Dumper.getCompilationCPUType();
678 return Err;
Zachary Turneraaad5742016-05-23 23:41:13 +0000679}