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