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