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" |
| 13 | #include "llvm-pdbdump.h" |
| 14 | |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/CodeView/Line.h" |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 16 | #include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" |
| 18 | #include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h" |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 19 | #include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" |
| 20 | #include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h" |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 23 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 26 | #include "llvm/DebugInfo/PDB/Native/RawConstants.h" |
| 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 | c6d54da | 2016-09-09 17:46:17 +0000 | [diff] [blame] | 33 | YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame] | 34 | : File(File), Out(outs()), Obj(File.getAllocator()) { |
| 35 | Out.setWriteDefaultValues(!opts::pdb2yaml::Minimal); |
| 36 | } |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 37 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 38 | Error YAMLOutputStyle::dump() { |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 39 | if (opts::pdb2yaml::StreamDirectory) |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 40 | opts::pdb2yaml::StreamMetadata = true; |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 41 | if (opts::pdb2yaml::DbiModuleSyms) |
| 42 | opts::pdb2yaml::DbiModuleInfo = true; |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 43 | |
| 44 | if (opts::pdb2yaml::DbiModuleSourceLineInfo) |
| 45 | opts::pdb2yaml::DbiModuleSourceFileInfo = true; |
| 46 | |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 47 | if (opts::pdb2yaml::DbiModuleSourceFileInfo) |
| 48 | opts::pdb2yaml::DbiModuleInfo = true; |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 49 | |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 50 | if (opts::pdb2yaml::DbiModuleInfo) |
| 51 | opts::pdb2yaml::DbiStream = true; |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 52 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 53 | if (auto EC = dumpFileHeaders()) |
| 54 | return EC; |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 55 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 56 | if (auto EC = dumpStreamMetadata()) |
| 57 | return EC; |
| 58 | |
| 59 | if (auto EC = dumpStreamDirectory()) |
| 60 | return EC; |
| 61 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 62 | if (auto EC = dumpStringTable()) |
| 63 | return EC; |
| 64 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 65 | if (auto EC = dumpPDBStream()) |
| 66 | return EC; |
| 67 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 68 | if (auto EC = dumpDbiStream()) |
| 69 | return EC; |
| 70 | |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 71 | if (auto EC = dumpTpiStream()) |
| 72 | return EC; |
| 73 | |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 74 | if (auto EC = dumpIpiStream()) |
| 75 | return EC; |
| 76 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 77 | flush(); |
| 78 | return Error::success(); |
| 79 | } |
| 80 | |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 81 | namespace { |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 82 | class C13SubstreamVisitor : public ModuleDebugFragmentVisitor { |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 83 | public: |
| 84 | C13SubstreamVisitor(llvm::pdb::yaml::PdbSourceFileInfo &Info, PDBFile &F) |
| 85 | : Info(Info), F(F) {} |
| 86 | |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 87 | Error visitUnknown(ModuleDebugUnknownFragment &Fragment) override { |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 88 | return Error::success(); |
| 89 | } |
| 90 | |
| 91 | Error |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 92 | visitFileChecksums(ModuleDebugFileChecksumFragment &Checksums) override { |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 93 | for (const auto &C : Checksums) { |
| 94 | llvm::pdb::yaml::PdbSourceFileChecksumEntry Entry; |
| 95 | if (auto Result = getGlobalString(C.FileNameOffset)) |
| 96 | Entry.FileName = *Result; |
| 97 | else |
| 98 | return Result.takeError(); |
| 99 | |
| 100 | Entry.Kind = C.Kind; |
| 101 | Entry.ChecksumBytes.Bytes = C.Checksum; |
| 102 | Info.FileChecksums.push_back(Entry); |
| 103 | } |
| 104 | return Error::success(); |
| 105 | } |
| 106 | |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 107 | Error visitLines(ModuleDebugLineFragment &Lines) override { |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 108 | |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 109 | Info.Lines.CodeSize = Lines.header()->CodeSize; |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 110 | Info.Lines.Flags = |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 111 | static_cast<codeview::LineFlags>(uint16_t(Lines.header()->Flags)); |
| 112 | Info.Lines.RelocOffset = Lines.header()->RelocOffset; |
| 113 | Info.Lines.RelocSegment = Lines.header()->RelocSegment; |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 114 | |
| 115 | for (const auto &L : Lines) { |
| 116 | llvm::pdb::yaml::PdbSourceLineBlock Block; |
| 117 | |
| 118 | if (auto Result = getDbiFileName(L.NameIndex)) |
| 119 | Block.FileName = *Result; |
| 120 | else |
| 121 | return Result.takeError(); |
| 122 | |
| 123 | for (const auto &N : L.LineNumbers) { |
| 124 | llvm::pdb::yaml::PdbSourceLineEntry Line; |
| 125 | Line.Offset = N.Offset; |
| 126 | codeview::LineInfo LI(N.Flags); |
| 127 | Line.LineStart = LI.getStartLine(); |
| 128 | Line.EndDelta = LI.getEndLine(); |
| 129 | Line.IsStatement = LI.isStatement(); |
| 130 | Block.Lines.push_back(Line); |
| 131 | } |
| 132 | |
| 133 | if (Info.Lines.Flags & codeview::LineFlags::HaveColumns) { |
| 134 | for (const auto &C : L.Columns) { |
| 135 | llvm::pdb::yaml::PdbSourceColumnEntry Column; |
| 136 | Column.StartColumn = C.StartColumn; |
| 137 | Column.EndColumn = C.EndColumn; |
| 138 | Block.Columns.push_back(Column); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | Info.Lines.LineInfo.push_back(Block); |
| 143 | } |
| 144 | return Error::success(); |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | Expected<StringRef> getGlobalString(uint32_t Offset) { |
| 149 | auto ST = F.getStringTable(); |
| 150 | if (!ST) |
| 151 | return ST.takeError(); |
| 152 | |
| 153 | return ST->getStringForID(Offset); |
| 154 | } |
| 155 | Expected<StringRef> getDbiFileName(uint32_t Offset) { |
| 156 | auto DS = F.getPDBDbiStream(); |
| 157 | if (!DS) |
| 158 | return DS.takeError(); |
| 159 | return DS->getFileNameForIndex(Offset); |
| 160 | } |
| 161 | |
| 162 | llvm::pdb::yaml::PdbSourceFileInfo &Info; |
| 163 | PDBFile &F; |
| 164 | }; |
| 165 | } |
| 166 | |
| 167 | Expected<Optional<llvm::pdb::yaml::PdbSourceFileInfo>> |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 168 | YAMLOutputStyle::getFileLineInfo(const pdb::ModuleDebugStream &ModS) { |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 169 | if (!ModS.hasLineInfo()) |
| 170 | return None; |
| 171 | |
| 172 | yaml::PdbSourceFileInfo Info; |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 173 | C13SubstreamVisitor Visitor(Info, File); |
Zachary Turner | c37cb0c | 2017-04-27 16:12:16 +0000 | [diff] [blame^] | 174 | for (auto &Frag : ModS.linesAndChecksums()) { |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 175 | if (auto E = codeview::visitModuleDebugFragment(Frag, Visitor)) |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 176 | return std::move(E); |
| 177 | } |
| 178 | |
| 179 | return Info; |
| 180 | } |
| 181 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 182 | Error YAMLOutputStyle::dumpFileHeaders() { |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 183 | if (opts::pdb2yaml::NoFileHeaders) |
| 184 | return Error::success(); |
| 185 | |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 186 | yaml::MSFHeaders Headers; |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 187 | Obj.Headers.emplace(); |
| 188 | Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount(); |
| 189 | Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 190 | Obj.Headers->SuperBlock.BlockSize = File.getBlockSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 191 | auto Blocks = File.getDirectoryBlockArray(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 192 | Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); |
| 193 | Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks(); |
| 194 | Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes(); |
| 195 | Obj.Headers->NumStreams = |
Zachary Turner | ab58ae8 | 2016-06-30 17:43:00 +0000 | [diff] [blame] | 196 | opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0; |
Zachary Turner | b927e02 | 2016-07-15 22:17:19 +0000 | [diff] [blame] | 197 | Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock(); |
Zachary Turner | f6b9382 | 2016-07-11 21:45:09 +0000 | [diff] [blame] | 198 | Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1(); |
| 199 | Obj.Headers->FileSize = File.getFileSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 200 | |
| 201 | return Error::success(); |
| 202 | } |
| 203 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 204 | Error YAMLOutputStyle::dumpStringTable() { |
| 205 | if (!opts::pdb2yaml::StringTable) |
| 206 | return Error::success(); |
| 207 | |
| 208 | Obj.StringTable.emplace(); |
| 209 | auto ExpectedST = File.getStringTable(); |
| 210 | if (!ExpectedST) |
| 211 | return ExpectedST.takeError(); |
| 212 | |
| 213 | const auto &ST = ExpectedST.get(); |
| 214 | for (auto ID : ST.name_ids()) { |
| 215 | StringRef S = ST.getStringForID(ID); |
| 216 | if (!S.empty()) |
| 217 | Obj.StringTable->push_back(S); |
| 218 | } |
| 219 | return Error::success(); |
| 220 | } |
| 221 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 222 | Error YAMLOutputStyle::dumpStreamMetadata() { |
| 223 | if (!opts::pdb2yaml::StreamMetadata) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 224 | return Error::success(); |
| 225 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 226 | Obj.StreamSizes.emplace(); |
| 227 | Obj.StreamSizes->assign(File.getStreamSizes().begin(), |
| 228 | File.getStreamSizes().end()); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 229 | return Error::success(); |
| 230 | } |
| 231 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 232 | Error YAMLOutputStyle::dumpStreamDirectory() { |
| 233 | if (!opts::pdb2yaml::StreamDirectory) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 234 | return Error::success(); |
| 235 | |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 236 | auto StreamMap = File.getStreamMap(); |
| 237 | Obj.StreamMap.emplace(); |
| 238 | for (auto &Stream : StreamMap) { |
| 239 | pdb::yaml::StreamBlockList BlockList; |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 240 | BlockList.Blocks.assign(Stream.begin(), Stream.end()); |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 241 | Obj.StreamMap->push_back(BlockList); |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 242 | } |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 243 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 244 | return Error::success(); |
| 245 | } |
| 246 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 247 | Error YAMLOutputStyle::dumpPDBStream() { |
| 248 | if (!opts::pdb2yaml::PdbStream) |
| 249 | return Error::success(); |
| 250 | |
| 251 | auto IS = File.getPDBInfoStream(); |
| 252 | if (!IS) |
| 253 | return IS.takeError(); |
| 254 | |
| 255 | auto &InfoS = IS.get(); |
| 256 | Obj.PdbStream.emplace(); |
| 257 | Obj.PdbStream->Age = InfoS.getAge(); |
| 258 | Obj.PdbStream->Guid = InfoS.getGuid(); |
| 259 | Obj.PdbStream->Signature = InfoS.getSignature(); |
| 260 | Obj.PdbStream->Version = InfoS.getVersion(); |
Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 261 | Obj.PdbStream->Features = InfoS.getFeatureSignatures(); |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 262 | |
| 263 | return Error::success(); |
| 264 | } |
| 265 | |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 266 | Error YAMLOutputStyle::dumpDbiStream() { |
| 267 | if (!opts::pdb2yaml::DbiStream) |
| 268 | return Error::success(); |
| 269 | |
| 270 | auto DbiS = File.getPDBDbiStream(); |
| 271 | if (!DbiS) |
| 272 | return DbiS.takeError(); |
| 273 | |
| 274 | auto &DS = DbiS.get(); |
| 275 | Obj.DbiStream.emplace(); |
| 276 | Obj.DbiStream->Age = DS.getAge(); |
| 277 | Obj.DbiStream->BuildNumber = DS.getBuildNumber(); |
| 278 | Obj.DbiStream->Flags = DS.getFlags(); |
| 279 | Obj.DbiStream->MachineType = DS.getMachineType(); |
| 280 | Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld(); |
| 281 | Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion(); |
| 282 | Obj.DbiStream->VerHeader = DS.getDbiVersion(); |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 283 | if (opts::pdb2yaml::DbiModuleInfo) { |
| 284 | for (const auto &MI : DS.modules()) { |
| 285 | yaml::PdbDbiModuleInfo DMI; |
| 286 | DMI.Mod = MI.Info.getModuleName(); |
| 287 | DMI.Obj = MI.Info.getObjFileName(); |
| 288 | if (opts::pdb2yaml::DbiModuleSourceFileInfo) |
| 289 | DMI.SourceFiles = MI.SourceFiles; |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 290 | |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 291 | auto ModStreamData = msf::MappedBlockStream::createIndexedStream( |
| 292 | File.getMsfLayout(), File.getMsfBuffer(), |
| 293 | MI.Info.getModuleStreamIndex()); |
| 294 | |
Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame] | 295 | pdb::ModuleDebugStream ModS(MI.Info, std::move(ModStreamData)); |
Zachary Turner | ee3b9c2 | 2017-04-25 20:22:02 +0000 | [diff] [blame] | 296 | if (auto EC = ModS.reload()) |
| 297 | return EC; |
| 298 | |
| 299 | if (opts::pdb2yaml::DbiModuleSourceLineInfo) { |
| 300 | auto ExpectedInfo = getFileLineInfo(ModS); |
| 301 | if (!ExpectedInfo) |
| 302 | return ExpectedInfo.takeError(); |
| 303 | DMI.FileLineInfo = *ExpectedInfo; |
| 304 | } |
| 305 | |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 306 | if (opts::pdb2yaml::DbiModuleSyms && |
| 307 | MI.Info.getModuleStreamIndex() != kInvalidStreamIndex) { |
| 308 | DMI.Modi.emplace(); |
Zachary Turner | 3b14764 | 2016-10-08 01:12:01 +0000 | [diff] [blame] | 309 | |
| 310 | DMI.Modi->Signature = ModS.signature(); |
| 311 | bool HadError = false; |
| 312 | for (auto &Sym : ModS.symbols(&HadError)) { |
| 313 | pdb::yaml::PdbSymbolRecord Record{Sym}; |
| 314 | DMI.Modi->Symbols.push_back(Record); |
| 315 | } |
| 316 | } |
Zachary Turner | d218c26 | 2016-07-22 15:46:37 +0000 | [diff] [blame] | 317 | Obj.DbiStream->ModInfos.push_back(DMI); |
| 318 | } |
| 319 | } |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 320 | return Error::success(); |
| 321 | } |
| 322 | |
Zachary Turner | ac5763e | 2016-08-18 16:49:29 +0000 | [diff] [blame] | 323 | Error YAMLOutputStyle::dumpTpiStream() { |
| 324 | if (!opts::pdb2yaml::TpiStream) |
| 325 | return Error::success(); |
| 326 | |
| 327 | auto TpiS = File.getPDBTpiStream(); |
| 328 | if (!TpiS) |
| 329 | return TpiS.takeError(); |
| 330 | |
| 331 | auto &TS = TpiS.get(); |
| 332 | Obj.TpiStream.emplace(); |
| 333 | Obj.TpiStream->Version = TS.getTpiVersion(); |
| 334 | for (auto &Record : TS.types(nullptr)) { |
| 335 | yaml::PdbTpiRecord R; |
| 336 | // It's not necessary to set R.RecordData here. That only exists as a |
| 337 | // way to have the `PdbTpiRecord` structure own the memory that `R.Record` |
| 338 | // references. In the case of reading an existing PDB though, that memory |
| 339 | // is owned by the backing stream. |
| 340 | R.Record = Record; |
| 341 | Obj.TpiStream->Records.push_back(R); |
| 342 | } |
| 343 | |
| 344 | return Error::success(); |
| 345 | } |
| 346 | |
Zachary Turner | de9ba15 | 2016-09-15 18:22:31 +0000 | [diff] [blame] | 347 | Error YAMLOutputStyle::dumpIpiStream() { |
| 348 | if (!opts::pdb2yaml::IpiStream) |
| 349 | return Error::success(); |
| 350 | |
| 351 | auto IpiS = File.getPDBIpiStream(); |
| 352 | if (!IpiS) |
| 353 | return IpiS.takeError(); |
| 354 | |
| 355 | auto &IS = IpiS.get(); |
| 356 | Obj.IpiStream.emplace(); |
| 357 | Obj.IpiStream->Version = IS.getTpiVersion(); |
| 358 | for (auto &Record : IS.types(nullptr)) { |
| 359 | yaml::PdbTpiRecord R; |
| 360 | R.Record = Record; |
| 361 | Obj.IpiStream->Records.push_back(R); |
| 362 | } |
| 363 | |
| 364 | return Error::success(); |
| 365 | } |
| 366 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 367 | void YAMLOutputStyle::flush() { |
| 368 | Out << Obj; |
| 369 | outs().flush(); |
| 370 | } |