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