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