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