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 | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame^] | 15 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" |
Zachary Turner | ab58ae8 | 2016-06-30 17:43:00 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | using namespace llvm::pdb; |
| 21 | |
| 22 | YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {} |
| 23 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 24 | Error YAMLOutputStyle::dump() { |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame^] | 25 | if (opts::pdb2yaml::StreamDirectory || opts::pdb2yaml::PdbStream) |
| 26 | opts::pdb2yaml::StreamMetadata = true; |
| 27 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 28 | if (auto EC = dumpFileHeaders()) |
| 29 | return EC; |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 30 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 31 | if (auto EC = dumpStreamMetadata()) |
| 32 | return EC; |
| 33 | |
| 34 | if (auto EC = dumpStreamDirectory()) |
| 35 | return EC; |
| 36 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame^] | 37 | if (auto EC = dumpPDBStream()) |
| 38 | return EC; |
| 39 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 40 | flush(); |
| 41 | return Error::success(); |
| 42 | } |
| 43 | |
| 44 | Error YAMLOutputStyle::dumpFileHeaders() { |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 45 | yaml::MsfHeaders Headers; |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 46 | Obj.Headers.SuperBlock.NumBlocks = File.getBlockCount(); |
| 47 | Obj.Headers.SuperBlock.BlockMapAddr = File.getBlockMapIndex(); |
| 48 | Obj.Headers.BlockMapOffset = File.getBlockMapOffset(); |
| 49 | Obj.Headers.SuperBlock.BlockSize = File.getBlockSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 50 | auto Blocks = File.getDirectoryBlockArray(); |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 51 | Obj.Headers.DirectoryBlocks.assign(Blocks.begin(), Blocks.end()); |
| 52 | Obj.Headers.NumDirectoryBlocks = File.getNumDirectoryBlocks(); |
| 53 | Obj.Headers.SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes(); |
Zachary Turner | ab58ae8 | 2016-06-30 17:43:00 +0000 | [diff] [blame] | 54 | Obj.Headers.NumStreams = |
| 55 | opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0; |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 56 | Obj.Headers.SuperBlock.Unknown0 = File.getUnknown0(); |
| 57 | Obj.Headers.SuperBlock.Unknown1 = File.getUnknown1(); |
| 58 | Obj.Headers.FileSize = File.getFileSize(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 59 | |
| 60 | return Error::success(); |
| 61 | } |
| 62 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 63 | Error YAMLOutputStyle::dumpStreamMetadata() { |
| 64 | if (!opts::pdb2yaml::StreamMetadata) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 65 | return Error::success(); |
| 66 | |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 67 | Obj.StreamSizes = File.getStreamSizes(); |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 68 | return Error::success(); |
| 69 | } |
| 70 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 71 | Error YAMLOutputStyle::dumpStreamDirectory() { |
| 72 | if (!opts::pdb2yaml::StreamDirectory) |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 73 | return Error::success(); |
| 74 | |
Zachary Turner | 1dc9fd3 | 2016-06-14 20:48:36 +0000 | [diff] [blame] | 75 | auto StreamMap = File.getStreamMap(); |
| 76 | Obj.StreamMap.emplace(); |
| 77 | for (auto &Stream : StreamMap) { |
| 78 | pdb::yaml::StreamBlockList BlockList; |
| 79 | BlockList.Blocks = Stream; |
| 80 | Obj.StreamMap->push_back(BlockList); |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 81 | } |
Zachary Turner | 25e8b05 | 2016-06-06 20:37:17 +0000 | [diff] [blame] | 82 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 83 | return Error::success(); |
| 84 | } |
| 85 | |
Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame^] | 86 | Error YAMLOutputStyle::dumpPDBStream() { |
| 87 | if (!opts::pdb2yaml::PdbStream) |
| 88 | return Error::success(); |
| 89 | |
| 90 | auto IS = File.getPDBInfoStream(); |
| 91 | if (!IS) |
| 92 | return IS.takeError(); |
| 93 | |
| 94 | auto &InfoS = IS.get(); |
| 95 | Obj.PdbStream.emplace(); |
| 96 | Obj.PdbStream->Age = InfoS.getAge(); |
| 97 | Obj.PdbStream->Guid = InfoS.getGuid(); |
| 98 | Obj.PdbStream->Signature = InfoS.getSignature(); |
| 99 | Obj.PdbStream->Version = InfoS.getVersion(); |
| 100 | |
| 101 | return Error::success(); |
| 102 | } |
| 103 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 104 | void YAMLOutputStyle::flush() { |
| 105 | Out << Obj; |
| 106 | outs().flush(); |
| 107 | } |