Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 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" |
Zachary Turner | bd336e4 | 2017-06-09 20:46:17 +0000 | [diff] [blame] | 13 | #include "llvm-pdbutil.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 14 | |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" |
| 16 | #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" |
| 17 | #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" |
| 18 | #include "llvm/DebugInfo/CodeView/DebugSubsection.h" |
Zachary Turner | 8c099fe | 2017-05-30 16:36:15 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h" |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/Line.h" |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 24 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 27 | #include "llvm/DebugInfo/PDB/Native/RawConstants.h" |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo/PDB/Native/RawError.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 29 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 30 | |
| 31 | using namespace llvm; |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame] | 32 | using namespace llvm::codeview; |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 33 | using namespace llvm::pdb; |
| 34 | |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 35 | static bool checkModuleSubsection(opts::ModuleSubsection MS) { |
| 36 | return any_of(opts::pdb2yaml::DumpModuleSubsections, |
| 37 | [=](opts::ModuleSubsection M) { |
| 38 | return M == MS || M == opts::ModuleSubsection::All; |
| 39 | }); |
| 40 | } |
| 41 | |
Zachary Turner | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 42 | YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame] | 43 | : File(File), Out(outs()), Obj(File.getAllocator()) { |
| 44 | Out.setWriteDefaultValues(!opts::pdb2yaml::Minimal); |
| 45 | } |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 46 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 47 | Error YAMLOutputStyle::dump() { |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 48 | if (opts::pdb2yaml::StreamDirectory) |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 49 | opts::pdb2yaml::StreamMetadata = true; |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 50 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 51 | if (auto EC = dumpFileHeaders()) |
| 52 | return EC; |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 53 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 54 | if (auto EC = dumpStreamMetadata()) |
| 55 | return EC; |
| 56 | |
| 57 | if (auto EC = dumpStreamDirectory()) |
| 58 | return EC; |
| 59 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 60 | if (auto EC = dumpStringTable()) |
| 61 | return EC; |
| 62 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 63 | if (auto EC = dumpPDBStream()) |
| 64 | return EC; |
| 65 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 66 | if (auto EC = dumpDbiStream()) |
| 67 | return EC; |
| 68 | |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 69 | if (auto EC = dumpTpiStream()) |
| 70 | return EC; |
| 71 | |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 72 | if (auto EC = dumpIpiStream()) |
| 73 | return EC; |
| 74 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 75 | flush(); |
| 76 | return Error::success(); |
| 77 | } |
| 78 | |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 79 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 80 | Error YAMLOutputStyle::dumpFileHeaders() { |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 81 | if (opts::pdb2yaml::NoFileHeaders) |
| 82 | return Error::success(); |
| 83 | |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 84 | yaml::MSFHeaders Headers; |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 85 | Obj.Headers.emplace(); |
| 86 | Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount(); |
| 87 | Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 88 | Obj.Headers->SuperBlock.BlockSize = File.getBlockSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 89 | auto Blocks = File.getDirectoryBlockArray(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 90 | Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); |
| 91 | Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks(); |
| 92 | Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes(); |
| 93 | Obj.Headers->NumStreams = |
Zachary Turner | ab58ae8 | 2016-06-30 17:43:00 +0000 | [diff] [blame] | 94 | opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0; |
Zachary Turner | b927e02 | 2016-07-15 22:17:19 +0000 | [diff] [blame] | 95 | Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 96 | Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1(); |
| 97 | Obj.Headers->FileSize = File.getFileSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 98 | |
| 99 | return Error::success(); |
| 100 | } |
| 101 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 102 | Error YAMLOutputStyle::dumpStringTable() { |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 103 | bool RequiresStringTable = opts::pdb2yaml::DumpModuleFiles || |
| 104 | !opts::pdb2yaml::DumpModuleSubsections.empty(); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 105 | bool RequestedStringTable = opts::pdb2yaml::StringTable; |
| 106 | if (!RequiresStringTable && !RequestedStringTable) |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 107 | return Error::success(); |
| 108 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 109 | auto ExpectedST = File.getStringTable(); |
| 110 | if (!ExpectedST) |
| 111 | return ExpectedST.takeError(); |
| 112 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 113 | Obj.StringTable.emplace(); |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 114 | const auto &ST = ExpectedST.get(); |
| 115 | for (auto ID : ST.name_ids()) { |
Zachary Turner | 2d5c2cd | 2017-05-03 17:11:11 +0000 | [diff] [blame] | 116 | auto S = ST.getStringForID(ID); |
| 117 | if (!S) |
| 118 | return S.takeError(); |
| 119 | if (S->empty()) |
| 120 | continue; |
| 121 | Obj.StringTable->push_back(*S); |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 122 | } |
| 123 | return Error::success(); |
| 124 | } |
| 125 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 126 | Error YAMLOutputStyle::dumpStreamMetadata() { |
| 127 | if (!opts::pdb2yaml::StreamMetadata) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 128 | return Error::success(); |
| 129 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 130 | Obj.StreamSizes.emplace(); |
| 131 | Obj.StreamSizes->assign(File.getStreamSizes().begin(), |
| 132 | File.getStreamSizes().end()); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 133 | return Error::success(); |
| 134 | } |
| 135 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 136 | Error YAMLOutputStyle::dumpStreamDirectory() { |
| 137 | if (!opts::pdb2yaml::StreamDirectory) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 138 | return Error::success(); |
| 139 | |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 140 | auto StreamMap = File.getStreamMap(); |
| 141 | Obj.StreamMap.emplace(); |
| 142 | for (auto &Stream : StreamMap) { |
| 143 | pdb::yaml::StreamBlockList BlockList; |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 144 | BlockList.Blocks.assign(Stream.begin(), Stream.end()); |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 145 | Obj.StreamMap->push_back(BlockList); |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 146 | } |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 147 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 148 | return Error::success(); |
| 149 | } |
| 150 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 151 | Error YAMLOutputStyle::dumpPDBStream() { |
| 152 | if (!opts::pdb2yaml::PdbStream) |
| 153 | return Error::success(); |
| 154 | |
| 155 | auto IS = File.getPDBInfoStream(); |
| 156 | if (!IS) |
| 157 | return IS.takeError(); |
| 158 | |
| 159 | auto &InfoS = IS.get(); |
| 160 | Obj.PdbStream.emplace(); |
| 161 | Obj.PdbStream->Age = InfoS.getAge(); |
| 162 | Obj.PdbStream->Guid = InfoS.getGuid(); |
| 163 | Obj.PdbStream->Signature = InfoS.getSignature(); |
| 164 | Obj.PdbStream->Version = InfoS.getVersion(); |
Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 165 | Obj.PdbStream->Features = InfoS.getFeatureSignatures(); |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 166 | |
| 167 | return Error::success(); |
| 168 | } |
| 169 | |
Zachary Turner | 3eedd16 | 2017-06-08 23:39:33 +0000 | [diff] [blame] | 170 | static opts::ModuleSubsection convertSubsectionKind(DebugSubsectionKind K) { |
| 171 | switch (K) { |
| 172 | case DebugSubsectionKind::CrossScopeExports: |
| 173 | return opts::ModuleSubsection::CrossScopeExports; |
| 174 | case DebugSubsectionKind::CrossScopeImports: |
| 175 | return opts::ModuleSubsection::CrossScopeImports; |
| 176 | case DebugSubsectionKind::FileChecksums: |
| 177 | return opts::ModuleSubsection::FileChecksums; |
| 178 | case DebugSubsectionKind::InlineeLines: |
| 179 | return opts::ModuleSubsection::InlineeLines; |
| 180 | case DebugSubsectionKind::Lines: |
| 181 | return opts::ModuleSubsection::Lines; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 182 | case DebugSubsectionKind::Symbols: |
| 183 | return opts::ModuleSubsection::Symbols; |
| 184 | case DebugSubsectionKind::StringTable: |
| 185 | return opts::ModuleSubsection::StringTable; |
| 186 | case DebugSubsectionKind::FrameData: |
| 187 | return opts::ModuleSubsection::FrameData; |
Zachary Turner | 3eedd16 | 2017-06-08 23:39:33 +0000 | [diff] [blame] | 188 | default: |
| 189 | return opts::ModuleSubsection::Unknown; |
| 190 | } |
| 191 | llvm_unreachable("Unreachable!"); |
| 192 | } |
| 193 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 194 | Error YAMLOutputStyle::dumpDbiStream() { |
| 195 | if (!opts::pdb2yaml::DbiStream) |
| 196 | return Error::success(); |
| 197 | |
| 198 | auto DbiS = File.getPDBDbiStream(); |
| 199 | if (!DbiS) |
| 200 | return DbiS.takeError(); |
| 201 | |
| 202 | auto &DS = DbiS.get(); |
| 203 | Obj.DbiStream.emplace(); |
| 204 | Obj.DbiStream->Age = DS.getAge(); |
| 205 | Obj.DbiStream->BuildNumber = DS.getBuildNumber(); |
| 206 | Obj.DbiStream->Flags = DS.getFlags(); |
| 207 | Obj.DbiStream->MachineType = DS.getMachineType(); |
| 208 | Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld(); |
| 209 | Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion(); |
| 210 | Obj.DbiStream->VerHeader = DS.getDbiVersion(); |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 211 | if (opts::pdb2yaml::DumpModules) { |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 212 | const auto &Modules = DS.modules(); |
| 213 | for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) { |
| 214 | DbiModuleDescriptor MI = Modules.getModuleDescriptor(I); |
| 215 | |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 216 | Obj.DbiStream->ModInfos.emplace_back(); |
| 217 | yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back(); |
| 218 | |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 219 | DMI.Mod = MI.getModuleName(); |
| 220 | DMI.Obj = MI.getObjFileName(); |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 221 | if (opts::pdb2yaml::DumpModuleFiles) { |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 222 | auto Files = Modules.source_files(I); |
| 223 | DMI.SourceFiles.assign(Files.begin(), Files.end()); |
| 224 | } |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 225 | |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 226 | uint16_t ModiStream = MI.getModuleStreamIndex(); |
Zachary Turner | 5b6e4e0 | 2017-04-29 01:13:21 +0000 | [diff] [blame] | 227 | if (ModiStream == kInvalidStreamIndex) |
| 228 | continue; |
| 229 | |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 230 | auto ModStreamData = msf::MappedBlockStream::createIndexedStream( |
Zachary Turner | 5b74ff3 | 2017-06-03 00:33:35 +0000 | [diff] [blame] | 231 | File.getMsfLayout(), File.getMsfBuffer(), ModiStream, |
| 232 | File.getAllocator()); |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 233 | |
Zachary Turner | 1eb9a02 | 2017-05-04 23:53:29 +0000 | [diff] [blame] | 234 | pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData)); |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 235 | if (auto EC = ModS.reload()) |
| 236 | return EC; |
| 237 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 238 | auto ExpectedST = File.getStringTable(); |
| 239 | if (!ExpectedST) |
| 240 | return ExpectedST.takeError(); |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 241 | if (!opts::pdb2yaml::DumpModuleSubsections.empty() && |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 242 | ModS.hasDebugSubsections()) { |
| 243 | auto ExpectedChecksums = ModS.findChecksumsSubsection(); |
| 244 | if (!ExpectedChecksums) |
| 245 | return ExpectedChecksums.takeError(); |
| 246 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 247 | StringsAndChecksumsRef SC(ExpectedST->getStringTable(), |
| 248 | *ExpectedChecksums); |
| 249 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 250 | for (const auto &SS : ModS.subsections()) { |
Zachary Turner | 3eedd16 | 2017-06-08 23:39:33 +0000 | [diff] [blame] | 251 | opts::ModuleSubsection OptionKind = convertSubsectionKind(SS.kind()); |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 252 | if (!checkModuleSubsection(OptionKind)) |
Zachary Turner | 3eedd16 | 2017-06-08 23:39:33 +0000 | [diff] [blame] | 253 | continue; |
| 254 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 255 | auto Converted = |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 256 | CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection(SC, SS); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 257 | if (!Converted) |
| 258 | return Converted.takeError(); |
| 259 | DMI.Subsections.push_back(*Converted); |
| 260 | } |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Zachary Turner | 6305545 | 2017-06-15 22:24:24 +0000 | [diff] [blame^] | 263 | if (opts::pdb2yaml::DumpModuleSyms) { |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 264 | DMI.Modi.emplace(); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 265 | |
| 266 | DMI.Modi->Signature = ModS.signature(); |
| 267 | bool HadError = false; |
| 268 | for (auto &Sym : ModS.symbols(&HadError)) { |
Zachary Turner | 1e4d369 | 2017-05-30 23:50:44 +0000 | [diff] [blame] | 269 | auto ES = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(Sym); |
| 270 | if (!ES) |
| 271 | return ES.takeError(); |
| 272 | |
| 273 | DMI.Modi->Symbols.push_back(*ES); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 274 | } |
| 275 | } |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 278 | return Error::success(); |
| 279 | } |
| 280 | |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 281 | Error YAMLOutputStyle::dumpTpiStream() { |
| 282 | if (!opts::pdb2yaml::TpiStream) |
| 283 | return Error::success(); |
| 284 | |
| 285 | auto TpiS = File.getPDBTpiStream(); |
| 286 | if (!TpiS) |
| 287 | return TpiS.takeError(); |
| 288 | |
| 289 | auto &TS = TpiS.get(); |
| 290 | Obj.TpiStream.emplace(); |
| 291 | Obj.TpiStream->Version = TS.getTpiVersion(); |
| 292 | for (auto &Record : TS.types(nullptr)) { |
Zachary Turner | d427383 | 2017-05-30 21:53:05 +0000 | [diff] [blame] | 293 | auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record); |
| 294 | if (!ExpectedRecord) |
| 295 | return ExpectedRecord.takeError(); |
| 296 | Obj.TpiStream->Records.push_back(*ExpectedRecord); |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | return Error::success(); |
| 300 | } |
| 301 | |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 302 | Error YAMLOutputStyle::dumpIpiStream() { |
| 303 | if (!opts::pdb2yaml::IpiStream) |
| 304 | return Error::success(); |
| 305 | |
Zachary Turner | 990d0c8 | 2017-06-12 21:34:53 +0000 | [diff] [blame] | 306 | auto InfoS = File.getPDBInfoStream(); |
| 307 | if (!InfoS) |
| 308 | return InfoS.takeError(); |
| 309 | if (!InfoS->containsIdStream()) |
| 310 | return Error::success(); |
| 311 | |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 312 | auto IpiS = File.getPDBIpiStream(); |
| 313 | if (!IpiS) |
| 314 | return IpiS.takeError(); |
| 315 | |
| 316 | auto &IS = IpiS.get(); |
| 317 | Obj.IpiStream.emplace(); |
| 318 | Obj.IpiStream->Version = IS.getTpiVersion(); |
| 319 | for (auto &Record : IS.types(nullptr)) { |
Zachary Turner | d427383 | 2017-05-30 21:53:05 +0000 | [diff] [blame] | 320 | auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record); |
| 321 | if (!ExpectedRecord) |
| 322 | return ExpectedRecord.takeError(); |
| 323 | |
| 324 | Obj.IpiStream->Records.push_back(*ExpectedRecord); |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | return Error::success(); |
| 328 | } |
| 329 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 330 | void YAMLOutputStyle::flush() { |
| 331 | Out << Obj; |
| 332 | outs().flush(); |
| 333 | } |