1 //===- YAMLOutputStyle.cpp ------------------------------------ *- C++ --*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "YAMLOutputStyle.h"
13 #include "llvm-pdbdump.h"
15 #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
16 #include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
17 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
18 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
21 using namespace llvm::pdb;
23 YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
25 Error YAMLOutputStyle::dump() {
26 if (opts::pdb2yaml::StreamDirectory)
27 opts::pdb2yaml::StreamMetadata = true;
29 if (auto EC = dumpFileHeaders())
32 if (auto EC = dumpStreamMetadata())
35 if (auto EC = dumpStreamDirectory())
38 if (auto EC = dumpPDBStream())
41 if (auto EC = dumpDbiStream())
45 return Error::success();
48 Error YAMLOutputStyle::dumpFileHeaders() {
49 if (opts::pdb2yaml::NoFileHeaders)
50 return Error::success();
52 yaml::MsfHeaders Headers;
53 Obj.Headers.emplace();
54 Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount();
55 Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex();
56 Obj.Headers->SuperBlock.BlockSize = File.getBlockSize();
57 auto Blocks = File.getDirectoryBlockArray();
58 Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
59 Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks();
60 Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
61 Obj.Headers->NumStreams =
62 opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
63 Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock();
64 Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1();
65 Obj.Headers->FileSize = File.getFileSize();
67 return Error::success();
70 Error YAMLOutputStyle::dumpStreamMetadata() {
71 if (!opts::pdb2yaml::StreamMetadata)
72 return Error::success();
74 Obj.StreamSizes.emplace();
75 Obj.StreamSizes->assign(File.getStreamSizes().begin(),
76 File.getStreamSizes().end());
77 return Error::success();
80 Error YAMLOutputStyle::dumpStreamDirectory() {
81 if (!opts::pdb2yaml::StreamDirectory)
82 return Error::success();
84 auto StreamMap = File.getStreamMap();
85 Obj.StreamMap.emplace();
86 for (auto &Stream : StreamMap) {
87 pdb::yaml::StreamBlockList BlockList;
88 BlockList.Blocks.assign(Stream.begin(), Stream.end());
89 Obj.StreamMap->push_back(BlockList);
92 return Error::success();
95 Error YAMLOutputStyle::dumpPDBStream() {
96 if (!opts::pdb2yaml::PdbStream)
97 return Error::success();
99 auto IS = File.getPDBInfoStream();
101 return IS.takeError();
103 auto &InfoS = IS.get();
104 Obj.PdbStream.emplace();
105 Obj.PdbStream->Age = InfoS.getAge();
106 Obj.PdbStream->Guid = InfoS.getGuid();
107 Obj.PdbStream->Signature = InfoS.getSignature();
108 Obj.PdbStream->Version = InfoS.getVersion();
109 for (auto &NS : InfoS.named_streams()) {
110 yaml::NamedStreamMapping Mapping;
111 Mapping.StreamName = NS.getKey();
112 Mapping.StreamNumber = NS.getValue();
113 Obj.PdbStream->NamedStreams.push_back(Mapping);
116 return Error::success();
119 Error YAMLOutputStyle::dumpDbiStream() {
120 if (!opts::pdb2yaml::DbiStream)
121 return Error::success();
123 auto DbiS = File.getPDBDbiStream();
125 return DbiS.takeError();
127 auto &DS = DbiS.get();
128 Obj.DbiStream.emplace();
129 Obj.DbiStream->Age = DS.getAge();
130 Obj.DbiStream->BuildNumber = DS.getBuildNumber();
131 Obj.DbiStream->Flags = DS.getFlags();
132 Obj.DbiStream->MachineType = DS.getMachineType();
133 Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld();
134 Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion();
135 Obj.DbiStream->VerHeader = DS.getDbiVersion();
136 return Error::success();
139 void YAMLOutputStyle::flush() {