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