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