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