1*0b57cec5SDimitry Andric //===- YAMLOutputStyle.cpp ------------------------------------ *- C++ --*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "YAMLOutputStyle.h"
10*0b57cec5SDimitry Andric
11*0b57cec5SDimitry Andric #include "PdbYaml.h"
12*0b57cec5SDimitry Andric #include "llvm-pdbutil.h"
13*0b57cec5SDimitry Andric
14*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
15*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
16*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h"
17*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
18*0b57cec5SDimitry Andric #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
19*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
20*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
21*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
22*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
23*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
24*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
25*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
26*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
27*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
28*0b57cec5SDimitry Andric
29*0b57cec5SDimitry Andric using namespace llvm;
30*0b57cec5SDimitry Andric using namespace llvm::codeview;
31*0b57cec5SDimitry Andric using namespace llvm::pdb;
32*0b57cec5SDimitry Andric
checkModuleSubsection(opts::ModuleSubsection MS)33*0b57cec5SDimitry Andric static bool checkModuleSubsection(opts::ModuleSubsection MS) {
34*0b57cec5SDimitry Andric return any_of(opts::pdb2yaml::DumpModuleSubsections,
35*0b57cec5SDimitry Andric [=](opts::ModuleSubsection M) {
36*0b57cec5SDimitry Andric return M == MS || M == opts::ModuleSubsection::All;
37*0b57cec5SDimitry Andric });
38*0b57cec5SDimitry Andric }
39*0b57cec5SDimitry Andric
YAMLOutputStyle(PDBFile & File)40*0b57cec5SDimitry Andric YAMLOutputStyle::YAMLOutputStyle(PDBFile &File)
41*0b57cec5SDimitry Andric : File(File), Out(outs()), Obj(File.getAllocator()) {
42*0b57cec5SDimitry Andric Out.setWriteDefaultValues(!opts::pdb2yaml::Minimal);
43*0b57cec5SDimitry Andric }
44*0b57cec5SDimitry Andric
dump()45*0b57cec5SDimitry Andric Error YAMLOutputStyle::dump() {
46*0b57cec5SDimitry Andric if (opts::pdb2yaml::StreamDirectory)
47*0b57cec5SDimitry Andric opts::pdb2yaml::StreamMetadata = true;
48*0b57cec5SDimitry Andric
49*0b57cec5SDimitry Andric if (auto EC = dumpFileHeaders())
50*0b57cec5SDimitry Andric return EC;
51*0b57cec5SDimitry Andric
52*0b57cec5SDimitry Andric if (auto EC = dumpStreamMetadata())
53*0b57cec5SDimitry Andric return EC;
54*0b57cec5SDimitry Andric
55*0b57cec5SDimitry Andric if (auto EC = dumpStreamDirectory())
56*0b57cec5SDimitry Andric return EC;
57*0b57cec5SDimitry Andric
58*0b57cec5SDimitry Andric if (auto EC = dumpStringTable())
59*0b57cec5SDimitry Andric return EC;
60*0b57cec5SDimitry Andric
61*0b57cec5SDimitry Andric if (auto EC = dumpPDBStream())
62*0b57cec5SDimitry Andric return EC;
63*0b57cec5SDimitry Andric
64*0b57cec5SDimitry Andric if (auto EC = dumpDbiStream())
65*0b57cec5SDimitry Andric return EC;
66*0b57cec5SDimitry Andric
67*0b57cec5SDimitry Andric if (auto EC = dumpTpiStream())
68*0b57cec5SDimitry Andric return EC;
69*0b57cec5SDimitry Andric
70*0b57cec5SDimitry Andric if (auto EC = dumpIpiStream())
71*0b57cec5SDimitry Andric return EC;
72*0b57cec5SDimitry Andric
73*0b57cec5SDimitry Andric if (auto EC = dumpPublics())
74*0b57cec5SDimitry Andric return EC;
75*0b57cec5SDimitry Andric
76*0b57cec5SDimitry Andric flush();
77*0b57cec5SDimitry Andric return Error::success();
78*0b57cec5SDimitry Andric }
79*0b57cec5SDimitry Andric
80*0b57cec5SDimitry Andric
dumpFileHeaders()81*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpFileHeaders() {
82*0b57cec5SDimitry Andric if (opts::pdb2yaml::NoFileHeaders)
83*0b57cec5SDimitry Andric return Error::success();
84*0b57cec5SDimitry Andric
85*0b57cec5SDimitry Andric yaml::MSFHeaders Headers;
86*0b57cec5SDimitry Andric Obj.Headers.emplace();
87*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount();
88*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex();
89*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.BlockSize = File.getBlockSize();
90*0b57cec5SDimitry Andric auto Blocks = File.getDirectoryBlockArray();
91*0b57cec5SDimitry Andric Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
92*0b57cec5SDimitry Andric Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks();
93*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
94*0b57cec5SDimitry Andric Obj.Headers->NumStreams =
95*0b57cec5SDimitry Andric opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
96*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock();
97*0b57cec5SDimitry Andric Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1();
98*0b57cec5SDimitry Andric Obj.Headers->FileSize = File.getFileSize();
99*0b57cec5SDimitry Andric
100*0b57cec5SDimitry Andric return Error::success();
101*0b57cec5SDimitry Andric }
102*0b57cec5SDimitry Andric
dumpStringTable()103*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpStringTable() {
104*0b57cec5SDimitry Andric bool RequiresStringTable = opts::pdb2yaml::DumpModuleFiles ||
105*0b57cec5SDimitry Andric !opts::pdb2yaml::DumpModuleSubsections.empty();
106*0b57cec5SDimitry Andric bool RequestedStringTable = opts::pdb2yaml::StringTable;
107*0b57cec5SDimitry Andric if (!RequiresStringTable && !RequestedStringTable)
108*0b57cec5SDimitry Andric return Error::success();
109*0b57cec5SDimitry Andric
110*0b57cec5SDimitry Andric auto ExpectedST = File.getStringTable();
111*0b57cec5SDimitry Andric if (!ExpectedST)
112*0b57cec5SDimitry Andric return ExpectedST.takeError();
113*0b57cec5SDimitry Andric
114*0b57cec5SDimitry Andric Obj.StringTable.emplace();
115*0b57cec5SDimitry Andric const auto &ST = ExpectedST.get();
116*0b57cec5SDimitry Andric for (auto ID : ST.name_ids()) {
117*0b57cec5SDimitry Andric auto S = ST.getStringForID(ID);
118*0b57cec5SDimitry Andric if (!S)
119*0b57cec5SDimitry Andric return S.takeError();
120*0b57cec5SDimitry Andric if (S->empty())
121*0b57cec5SDimitry Andric continue;
122*0b57cec5SDimitry Andric Obj.StringTable->push_back(*S);
123*0b57cec5SDimitry Andric }
124*0b57cec5SDimitry Andric return Error::success();
125*0b57cec5SDimitry Andric }
126*0b57cec5SDimitry Andric
dumpStreamMetadata()127*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpStreamMetadata() {
128*0b57cec5SDimitry Andric if (!opts::pdb2yaml::StreamMetadata)
129*0b57cec5SDimitry Andric return Error::success();
130*0b57cec5SDimitry Andric
131*0b57cec5SDimitry Andric Obj.StreamSizes.emplace();
132*0b57cec5SDimitry Andric Obj.StreamSizes->assign(File.getStreamSizes().begin(),
133*0b57cec5SDimitry Andric File.getStreamSizes().end());
134*0b57cec5SDimitry Andric return Error::success();
135*0b57cec5SDimitry Andric }
136*0b57cec5SDimitry Andric
dumpStreamDirectory()137*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpStreamDirectory() {
138*0b57cec5SDimitry Andric if (!opts::pdb2yaml::StreamDirectory)
139*0b57cec5SDimitry Andric return Error::success();
140*0b57cec5SDimitry Andric
141*0b57cec5SDimitry Andric auto StreamMap = File.getStreamMap();
142*0b57cec5SDimitry Andric Obj.StreamMap.emplace();
143*0b57cec5SDimitry Andric for (auto &Stream : StreamMap) {
144*0b57cec5SDimitry Andric pdb::yaml::StreamBlockList BlockList;
145*0b57cec5SDimitry Andric BlockList.Blocks.assign(Stream.begin(), Stream.end());
146*0b57cec5SDimitry Andric Obj.StreamMap->push_back(BlockList);
147*0b57cec5SDimitry Andric }
148*0b57cec5SDimitry Andric
149*0b57cec5SDimitry Andric return Error::success();
150*0b57cec5SDimitry Andric }
151*0b57cec5SDimitry Andric
dumpPDBStream()152*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpPDBStream() {
153*0b57cec5SDimitry Andric if (!opts::pdb2yaml::PdbStream)
154*0b57cec5SDimitry Andric return Error::success();
155*0b57cec5SDimitry Andric
156*0b57cec5SDimitry Andric auto IS = File.getPDBInfoStream();
157*0b57cec5SDimitry Andric if (!IS)
158*0b57cec5SDimitry Andric return IS.takeError();
159*0b57cec5SDimitry Andric
160*0b57cec5SDimitry Andric auto &InfoS = IS.get();
161*0b57cec5SDimitry Andric Obj.PdbStream.emplace();
162*0b57cec5SDimitry Andric Obj.PdbStream->Age = InfoS.getAge();
163*0b57cec5SDimitry Andric Obj.PdbStream->Guid = InfoS.getGuid();
164*0b57cec5SDimitry Andric Obj.PdbStream->Signature = InfoS.getSignature();
165*0b57cec5SDimitry Andric Obj.PdbStream->Version = InfoS.getVersion();
166*0b57cec5SDimitry Andric Obj.PdbStream->Features = InfoS.getFeatureSignatures();
167*0b57cec5SDimitry Andric
168*0b57cec5SDimitry Andric return Error::success();
169*0b57cec5SDimitry Andric }
170*0b57cec5SDimitry Andric
convertSubsectionKind(DebugSubsectionKind K)171*0b57cec5SDimitry Andric static opts::ModuleSubsection convertSubsectionKind(DebugSubsectionKind K) {
172*0b57cec5SDimitry Andric switch (K) {
173*0b57cec5SDimitry Andric case DebugSubsectionKind::CrossScopeExports:
174*0b57cec5SDimitry Andric return opts::ModuleSubsection::CrossScopeExports;
175*0b57cec5SDimitry Andric case DebugSubsectionKind::CrossScopeImports:
176*0b57cec5SDimitry Andric return opts::ModuleSubsection::CrossScopeImports;
177*0b57cec5SDimitry Andric case DebugSubsectionKind::FileChecksums:
178*0b57cec5SDimitry Andric return opts::ModuleSubsection::FileChecksums;
179*0b57cec5SDimitry Andric case DebugSubsectionKind::InlineeLines:
180*0b57cec5SDimitry Andric return opts::ModuleSubsection::InlineeLines;
181*0b57cec5SDimitry Andric case DebugSubsectionKind::Lines:
182*0b57cec5SDimitry Andric return opts::ModuleSubsection::Lines;
183*0b57cec5SDimitry Andric case DebugSubsectionKind::Symbols:
184*0b57cec5SDimitry Andric return opts::ModuleSubsection::Symbols;
185*0b57cec5SDimitry Andric case DebugSubsectionKind::StringTable:
186*0b57cec5SDimitry Andric return opts::ModuleSubsection::StringTable;
187*0b57cec5SDimitry Andric case DebugSubsectionKind::FrameData:
188*0b57cec5SDimitry Andric return opts::ModuleSubsection::FrameData;
189*0b57cec5SDimitry Andric default:
190*0b57cec5SDimitry Andric return opts::ModuleSubsection::Unknown;
191*0b57cec5SDimitry Andric }
192*0b57cec5SDimitry Andric llvm_unreachable("Unreachable!");
193*0b57cec5SDimitry Andric }
194*0b57cec5SDimitry Andric
dumpDbiStream()195*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpDbiStream() {
196*0b57cec5SDimitry Andric if (!opts::pdb2yaml::DbiStream)
197*0b57cec5SDimitry Andric return Error::success();
198*0b57cec5SDimitry Andric
199*0b57cec5SDimitry Andric if (!File.hasPDBDbiStream())
200*0b57cec5SDimitry Andric return Error::success();
201*0b57cec5SDimitry Andric
202*0b57cec5SDimitry Andric auto DbiS = File.getPDBDbiStream();
203*0b57cec5SDimitry Andric if (!DbiS)
204*0b57cec5SDimitry Andric return DbiS.takeError();
205*0b57cec5SDimitry Andric
206*0b57cec5SDimitry Andric auto &DS = DbiS.get();
207*0b57cec5SDimitry Andric Obj.DbiStream.emplace();
208*0b57cec5SDimitry Andric Obj.DbiStream->Age = DS.getAge();
209*0b57cec5SDimitry Andric Obj.DbiStream->BuildNumber = DS.getBuildNumber();
210*0b57cec5SDimitry Andric Obj.DbiStream->Flags = DS.getFlags();
211*0b57cec5SDimitry Andric Obj.DbiStream->MachineType = DS.getMachineType();
212*0b57cec5SDimitry Andric Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld();
213*0b57cec5SDimitry Andric Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion();
214*0b57cec5SDimitry Andric Obj.DbiStream->VerHeader = DS.getDbiVersion();
215*0b57cec5SDimitry Andric if (opts::pdb2yaml::DumpModules) {
216*0b57cec5SDimitry Andric const auto &Modules = DS.modules();
217*0b57cec5SDimitry Andric for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
218*0b57cec5SDimitry Andric DbiModuleDescriptor MI = Modules.getModuleDescriptor(I);
219*0b57cec5SDimitry Andric
220*0b57cec5SDimitry Andric Obj.DbiStream->ModInfos.emplace_back();
221*0b57cec5SDimitry Andric yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back();
222*0b57cec5SDimitry Andric
223*0b57cec5SDimitry Andric DMI.Mod = MI.getModuleName();
224*0b57cec5SDimitry Andric DMI.Obj = MI.getObjFileName();
225*0b57cec5SDimitry Andric if (opts::pdb2yaml::DumpModuleFiles) {
226*0b57cec5SDimitry Andric auto Files = Modules.source_files(I);
227*0b57cec5SDimitry Andric DMI.SourceFiles.assign(Files.begin(), Files.end());
228*0b57cec5SDimitry Andric }
229*0b57cec5SDimitry Andric
230*0b57cec5SDimitry Andric uint16_t ModiStream = MI.getModuleStreamIndex();
231*0b57cec5SDimitry Andric if (ModiStream == kInvalidStreamIndex)
232*0b57cec5SDimitry Andric continue;
233*0b57cec5SDimitry Andric
234*0b57cec5SDimitry Andric auto ModStreamData = File.createIndexedStream(ModiStream);
235*0b57cec5SDimitry Andric pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData));
236*0b57cec5SDimitry Andric if (auto EC = ModS.reload())
237*0b57cec5SDimitry Andric return EC;
238*0b57cec5SDimitry Andric
239*0b57cec5SDimitry Andric auto ExpectedST = File.getStringTable();
240*0b57cec5SDimitry Andric if (!ExpectedST)
241*0b57cec5SDimitry Andric return ExpectedST.takeError();
242*0b57cec5SDimitry Andric if (!opts::pdb2yaml::DumpModuleSubsections.empty() &&
243*0b57cec5SDimitry Andric ModS.hasDebugSubsections()) {
244*0b57cec5SDimitry Andric auto ExpectedChecksums = ModS.findChecksumsSubsection();
245*0b57cec5SDimitry Andric if (!ExpectedChecksums)
246*0b57cec5SDimitry Andric return ExpectedChecksums.takeError();
247*0b57cec5SDimitry Andric
248*0b57cec5SDimitry Andric StringsAndChecksumsRef SC(ExpectedST->getStringTable(),
249*0b57cec5SDimitry Andric *ExpectedChecksums);
250*0b57cec5SDimitry Andric
251*0b57cec5SDimitry Andric for (const auto &SS : ModS.subsections()) {
252*0b57cec5SDimitry Andric opts::ModuleSubsection OptionKind = convertSubsectionKind(SS.kind());
253*0b57cec5SDimitry Andric if (!checkModuleSubsection(OptionKind))
254*0b57cec5SDimitry Andric continue;
255*0b57cec5SDimitry Andric
256*0b57cec5SDimitry Andric auto Converted =
257*0b57cec5SDimitry Andric CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection(SC, SS);
258*0b57cec5SDimitry Andric if (!Converted)
259*0b57cec5SDimitry Andric return Converted.takeError();
260*0b57cec5SDimitry Andric DMI.Subsections.push_back(*Converted);
261*0b57cec5SDimitry Andric }
262*0b57cec5SDimitry Andric }
263*0b57cec5SDimitry Andric
264*0b57cec5SDimitry Andric if (opts::pdb2yaml::DumpModuleSyms) {
265*0b57cec5SDimitry Andric DMI.Modi.emplace();
266*0b57cec5SDimitry Andric
267*0b57cec5SDimitry Andric DMI.Modi->Signature = ModS.signature();
268*0b57cec5SDimitry Andric bool HadError = false;
269*0b57cec5SDimitry Andric for (auto &Sym : ModS.symbols(&HadError)) {
270*0b57cec5SDimitry Andric auto ES = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(Sym);
271*0b57cec5SDimitry Andric if (!ES)
272*0b57cec5SDimitry Andric return ES.takeError();
273*0b57cec5SDimitry Andric
274*0b57cec5SDimitry Andric DMI.Modi->Symbols.push_back(*ES);
275*0b57cec5SDimitry Andric }
276*0b57cec5SDimitry Andric }
277*0b57cec5SDimitry Andric }
278*0b57cec5SDimitry Andric }
279*0b57cec5SDimitry Andric return Error::success();
280*0b57cec5SDimitry Andric }
281*0b57cec5SDimitry Andric
dumpTpiStream()282*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpTpiStream() {
283*0b57cec5SDimitry Andric if (!opts::pdb2yaml::TpiStream)
284*0b57cec5SDimitry Andric return Error::success();
285*0b57cec5SDimitry Andric
286*0b57cec5SDimitry Andric auto TpiS = File.getPDBTpiStream();
287*0b57cec5SDimitry Andric if (!TpiS)
288*0b57cec5SDimitry Andric return TpiS.takeError();
289*0b57cec5SDimitry Andric
290*0b57cec5SDimitry Andric auto &TS = TpiS.get();
291*0b57cec5SDimitry Andric Obj.TpiStream.emplace();
292*0b57cec5SDimitry Andric Obj.TpiStream->Version = TS.getTpiVersion();
293*0b57cec5SDimitry Andric for (auto &Record : TS.types(nullptr)) {
294*0b57cec5SDimitry Andric auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record);
295*0b57cec5SDimitry Andric if (!ExpectedRecord)
296*0b57cec5SDimitry Andric return ExpectedRecord.takeError();
297*0b57cec5SDimitry Andric Obj.TpiStream->Records.push_back(*ExpectedRecord);
298*0b57cec5SDimitry Andric }
299*0b57cec5SDimitry Andric
300*0b57cec5SDimitry Andric return Error::success();
301*0b57cec5SDimitry Andric }
302*0b57cec5SDimitry Andric
dumpIpiStream()303*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpIpiStream() {
304*0b57cec5SDimitry Andric if (!opts::pdb2yaml::IpiStream)
305*0b57cec5SDimitry Andric return Error::success();
306*0b57cec5SDimitry Andric
307*0b57cec5SDimitry Andric auto InfoS = File.getPDBInfoStream();
308*0b57cec5SDimitry Andric if (!InfoS)
309*0b57cec5SDimitry Andric return InfoS.takeError();
310*0b57cec5SDimitry Andric if (!InfoS->containsIdStream())
311*0b57cec5SDimitry Andric return Error::success();
312*0b57cec5SDimitry Andric
313*0b57cec5SDimitry Andric auto IpiS = File.getPDBIpiStream();
314*0b57cec5SDimitry Andric if (!IpiS)
315*0b57cec5SDimitry Andric return IpiS.takeError();
316*0b57cec5SDimitry Andric
317*0b57cec5SDimitry Andric auto &IS = IpiS.get();
318*0b57cec5SDimitry Andric Obj.IpiStream.emplace();
319*0b57cec5SDimitry Andric Obj.IpiStream->Version = IS.getTpiVersion();
320*0b57cec5SDimitry Andric for (auto &Record : IS.types(nullptr)) {
321*0b57cec5SDimitry Andric auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record);
322*0b57cec5SDimitry Andric if (!ExpectedRecord)
323*0b57cec5SDimitry Andric return ExpectedRecord.takeError();
324*0b57cec5SDimitry Andric
325*0b57cec5SDimitry Andric Obj.IpiStream->Records.push_back(*ExpectedRecord);
326*0b57cec5SDimitry Andric }
327*0b57cec5SDimitry Andric
328*0b57cec5SDimitry Andric return Error::success();
329*0b57cec5SDimitry Andric }
330*0b57cec5SDimitry Andric
dumpPublics()331*0b57cec5SDimitry Andric Error YAMLOutputStyle::dumpPublics() {
332*0b57cec5SDimitry Andric if (!opts::pdb2yaml::PublicsStream)
333*0b57cec5SDimitry Andric return Error::success();
334*0b57cec5SDimitry Andric
335*0b57cec5SDimitry Andric Obj.PublicsStream.emplace();
336*0b57cec5SDimitry Andric auto ExpectedPublics = File.getPDBPublicsStream();
337*0b57cec5SDimitry Andric if (!ExpectedPublics) {
338*0b57cec5SDimitry Andric llvm::consumeError(ExpectedPublics.takeError());
339*0b57cec5SDimitry Andric return Error::success();
340*0b57cec5SDimitry Andric }
341*0b57cec5SDimitry Andric
342*0b57cec5SDimitry Andric PublicsStream &Publics = *ExpectedPublics;
343*0b57cec5SDimitry Andric const GSIHashTable &PublicsTable = Publics.getPublicsTable();
344*0b57cec5SDimitry Andric
345*0b57cec5SDimitry Andric auto ExpectedSyms = File.getPDBSymbolStream();
346*0b57cec5SDimitry Andric if (!ExpectedSyms) {
347*0b57cec5SDimitry Andric llvm::consumeError(ExpectedSyms.takeError());
348*0b57cec5SDimitry Andric return Error::success();
349*0b57cec5SDimitry Andric }
350*0b57cec5SDimitry Andric
351*0b57cec5SDimitry Andric BinaryStreamRef SymStream =
352*0b57cec5SDimitry Andric ExpectedSyms->getSymbolArray().getUnderlyingStream();
353*0b57cec5SDimitry Andric for (uint32_t PubSymOff : PublicsTable) {
354*0b57cec5SDimitry Andric Expected<CVSymbol> Sym = readSymbolFromStream(SymStream, PubSymOff);
355*0b57cec5SDimitry Andric if (!Sym)
356*0b57cec5SDimitry Andric return Sym.takeError();
357*0b57cec5SDimitry Andric auto ES = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(*Sym);
358*0b57cec5SDimitry Andric if (!ES)
359*0b57cec5SDimitry Andric return ES.takeError();
360*0b57cec5SDimitry Andric
361*0b57cec5SDimitry Andric Obj.PublicsStream->PubSyms.push_back(*ES);
362*0b57cec5SDimitry Andric }
363*0b57cec5SDimitry Andric
364*0b57cec5SDimitry Andric return Error::success();
365*0b57cec5SDimitry Andric }
366*0b57cec5SDimitry Andric
flush()367*0b57cec5SDimitry Andric void YAMLOutputStyle::flush() {
368*0b57cec5SDimitry Andric Out << Obj;
369*0b57cec5SDimitry Andric outs().flush();
370*0b57cec5SDimitry Andric }
371