]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp
Update llvm, clang, lld and lldb to release_39 branch r288513.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / YAMLOutputStyle.cpp
1 //===- YAMLOutputStyle.cpp ------------------------------------ *- 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 "YAMLOutputStyle.h"
11
12 #include "PdbYaml.h"
13 #include "llvm-pdbdump.h"
14
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"
19
20 using namespace llvm;
21 using namespace llvm::pdb;
22
23 YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
24
25 Error YAMLOutputStyle::dump() {
26   if (opts::pdb2yaml::StreamDirectory)
27     opts::pdb2yaml::StreamMetadata = true;
28
29   if (auto EC = dumpFileHeaders())
30     return EC;
31
32   if (auto EC = dumpStreamMetadata())
33     return EC;
34
35   if (auto EC = dumpStreamDirectory())
36     return EC;
37
38   if (auto EC = dumpPDBStream())
39     return EC;
40
41   if (auto EC = dumpDbiStream())
42     return EC;
43
44   flush();
45   return Error::success();
46 }
47
48 Error YAMLOutputStyle::dumpFileHeaders() {
49   if (opts::pdb2yaml::NoFileHeaders)
50     return Error::success();
51
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();
66
67   return Error::success();
68 }
69
70 Error YAMLOutputStyle::dumpStreamMetadata() {
71   if (!opts::pdb2yaml::StreamMetadata)
72     return Error::success();
73
74   Obj.StreamSizes.emplace();
75   Obj.StreamSizes->assign(File.getStreamSizes().begin(),
76                           File.getStreamSizes().end());
77   return Error::success();
78 }
79
80 Error YAMLOutputStyle::dumpStreamDirectory() {
81   if (!opts::pdb2yaml::StreamDirectory)
82     return Error::success();
83
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);
90   }
91
92   return Error::success();
93 }
94
95 Error YAMLOutputStyle::dumpPDBStream() {
96   if (!opts::pdb2yaml::PdbStream)
97     return Error::success();
98
99   auto IS = File.getPDBInfoStream();
100   if (!IS)
101     return IS.takeError();
102
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);
114   }
115
116   return Error::success();
117 }
118
119 Error YAMLOutputStyle::dumpDbiStream() {
120   if (!opts::pdb2yaml::DbiStream)
121     return Error::success();
122
123   auto DbiS = File.getPDBDbiStream();
124   if (!DbiS)
125     return DbiS.takeError();
126
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();
137 }
138
139 void YAMLOutputStyle::flush() {
140   Out << Obj;
141   outs().flush();
142 }