Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 1 | //===- LLVMOutputStyle.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 "LLVMOutputStyle.h" |
| 11 | |
| 12 | #include "llvm-pdbdump.h" |
| 13 | #include "llvm/DebugInfo/CodeView/EnumTables.h" |
| 14 | #include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h" |
| 15 | #include "llvm/DebugInfo/CodeView/SymbolDumper.h" |
| 16 | #include "llvm/DebugInfo/PDB/PDBExtras.h" |
| 17 | #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" |
| 18 | #include "llvm/DebugInfo/PDB/Raw/EnumTables.h" |
| 19 | #include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h" |
Zachary Turner | d844799 | 2016-06-07 05:28:55 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
| 22 | #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" |
| 23 | #include "llvm/DebugInfo/PDB/Raw/ModStream.h" |
| 24 | #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" |
| 25 | #include "llvm/DebugInfo/PDB/Raw/PublicsStream.h" |
| 26 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
| 27 | #include "llvm/DebugInfo/PDB/Raw/TpiStream.h" |
| 28 | #include "llvm/Object/COFF.h" |
| 29 | |
| 30 | #include <unordered_map> |
| 31 | |
| 32 | using namespace llvm; |
| 33 | using namespace llvm::codeview; |
| 34 | using namespace llvm::pdb; |
| 35 | |
| 36 | static void printSectionOffset(llvm::raw_ostream &OS, |
| 37 | const SectionOffset &Off) { |
| 38 | OS << Off.Off << ", " << Off.Isect; |
| 39 | } |
| 40 | |
| 41 | LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) |
| 42 | : File(File), P(outs()), TD(&P, false) {} |
| 43 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 44 | Error LLVMOutputStyle::dump() { |
| 45 | if (auto EC = dumpFileHeaders()) |
| 46 | return EC; |
| 47 | |
| 48 | if (auto EC = dumpStreamSummary()) |
| 49 | return EC; |
| 50 | |
| 51 | if (auto EC = dumpStreamBlocks()) |
| 52 | return EC; |
| 53 | |
| 54 | if (auto EC = dumpStreamData()) |
| 55 | return EC; |
| 56 | |
| 57 | if (auto EC = dumpInfoStream()) |
| 58 | return EC; |
| 59 | |
| 60 | if (auto EC = dumpNamedStream()) |
| 61 | return EC; |
| 62 | |
| 63 | if (auto EC = dumpTpiStream(StreamTPI)) |
| 64 | return EC; |
| 65 | |
| 66 | if (auto EC = dumpTpiStream(StreamIPI)) |
| 67 | return EC; |
| 68 | |
| 69 | if (auto EC = dumpDbiStream()) |
| 70 | return EC; |
| 71 | |
| 72 | if (auto EC = dumpSectionContribs()) |
| 73 | return EC; |
| 74 | |
| 75 | if (auto EC = dumpSectionMap()) |
| 76 | return EC; |
| 77 | |
| 78 | if (auto EC = dumpPublicsStream()) |
| 79 | return EC; |
| 80 | |
| 81 | if (auto EC = dumpSectionHeaders()) |
| 82 | return EC; |
| 83 | |
| 84 | if (auto EC = dumpFpoStream()) |
| 85 | return EC; |
| 86 | |
| 87 | flush(); |
| 88 | |
| 89 | return Error::success(); |
| 90 | } |
| 91 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 92 | Error LLVMOutputStyle::dumpFileHeaders() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 93 | if (!opts::raw::DumpHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 94 | return Error::success(); |
| 95 | |
| 96 | DictScope D(P, "FileHeaders"); |
| 97 | P.printNumber("BlockSize", File.getBlockSize()); |
| 98 | P.printNumber("Unknown0", File.getUnknown0()); |
| 99 | P.printNumber("NumBlocks", File.getBlockCount()); |
| 100 | P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes()); |
| 101 | P.printNumber("Unknown1", File.getUnknown1()); |
| 102 | P.printNumber("BlockMapAddr", File.getBlockMapIndex()); |
| 103 | P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks()); |
| 104 | P.printNumber("BlockMapOffset", File.getBlockMapOffset()); |
| 105 | |
| 106 | // The directory is not contiguous. Instead, the block map contains a |
| 107 | // contiguous list of block numbers whose contents, when concatenated in |
| 108 | // order, make up the directory. |
| 109 | P.printList("DirectoryBlocks", File.getDirectoryBlockArray()); |
| 110 | P.printNumber("NumStreams", File.getNumStreams()); |
| 111 | return Error::success(); |
| 112 | } |
| 113 | |
| 114 | Error LLVMOutputStyle::dumpStreamSummary() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 115 | if (!opts::raw::DumpStreamSummary) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 116 | return Error::success(); |
| 117 | |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 118 | // It's OK if we fail to load some of these streams, we still attempt to print |
| 119 | // what we can. |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 120 | auto Dbi = File.getPDBDbiStream(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 121 | auto Tpi = File.getPDBTpiStream(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 122 | auto Ipi = File.getPDBIpiStream(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 123 | auto Info = File.getPDBInfoStream(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 124 | |
| 125 | ListScope L(P, "Streams"); |
| 126 | uint32_t StreamCount = File.getNumStreams(); |
| 127 | std::unordered_map<uint16_t, const ModuleInfoEx *> ModStreams; |
| 128 | std::unordered_map<uint16_t, std::string> NamedStreams; |
| 129 | |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 130 | if (Dbi) { |
| 131 | for (auto &ModI : Dbi->modules()) { |
| 132 | uint16_t SN = ModI.Info.getModuleStreamIndex(); |
| 133 | ModStreams[SN] = &ModI; |
| 134 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 135 | } |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 136 | if (Info) { |
| 137 | for (auto &NSE : Info->named_streams()) { |
| 138 | NamedStreams[NSE.second] = NSE.first(); |
| 139 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { |
| 143 | std::string Label("Stream "); |
| 144 | Label += to_string(StreamIdx); |
| 145 | std::string Value; |
| 146 | if (StreamIdx == OldMSFDirectory) |
| 147 | Value = "Old MSF Directory"; |
| 148 | else if (StreamIdx == StreamPDB) |
| 149 | Value = "PDB Stream"; |
| 150 | else if (StreamIdx == StreamDBI) |
| 151 | Value = "DBI Stream"; |
| 152 | else if (StreamIdx == StreamTPI) |
| 153 | Value = "TPI Stream"; |
| 154 | else if (StreamIdx == StreamIPI) |
| 155 | Value = "IPI Stream"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 156 | else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 157 | Value = "Global Symbol Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 158 | else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 159 | Value = "Public Symbol Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 160 | else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 161 | Value = "Public Symbol Records"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 162 | else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 163 | Value = "TPI Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 164 | else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 165 | Value = "TPI Aux Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 166 | else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 167 | Value = "IPI Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 168 | else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 169 | Value = "IPI Aux Hash"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 170 | else if (Dbi && |
| 171 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 172 | Value = "Exception Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 173 | else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 174 | Value = "Fixup Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 175 | else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 176 | Value = "FPO Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 177 | else if (Dbi && |
| 178 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 179 | Value = "New FPO Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 180 | else if (Dbi && |
| 181 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 182 | Value = "Omap From Source Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 183 | else if (Dbi && |
| 184 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 185 | Value = "Omap To Source Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 186 | else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 187 | Value = "Pdata"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 188 | else if (Dbi && |
| 189 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 190 | Value = "Section Header Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 191 | else if (Dbi && |
| 192 | StreamIdx == |
| 193 | Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 194 | Value = "Section Header Original Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 195 | else if (Dbi && |
| 196 | StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 197 | Value = "Token Rid Data"; |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 198 | else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 199 | Value = "Xdata"; |
| 200 | else { |
| 201 | auto ModIter = ModStreams.find(StreamIdx); |
| 202 | auto NSIter = NamedStreams.find(StreamIdx); |
| 203 | if (ModIter != ModStreams.end()) { |
| 204 | Value = "Module \""; |
| 205 | Value += ModIter->second->Info.getModuleName().str(); |
| 206 | Value += "\""; |
| 207 | } else if (NSIter != NamedStreams.end()) { |
| 208 | Value = "Named Stream \""; |
| 209 | Value += NSIter->second; |
| 210 | Value += "\""; |
| 211 | } else { |
| 212 | Value = "???"; |
| 213 | } |
| 214 | } |
| 215 | Value = "[" + Value + "]"; |
| 216 | Value = |
| 217 | Value + " (" + to_string(File.getStreamByteSize(StreamIdx)) + " bytes)"; |
| 218 | |
| 219 | P.printString(Label, Value); |
| 220 | } |
Reid Kleckner | 11582c5 | 2016-06-17 20:38:01 +0000 | [diff] [blame] | 221 | |
| 222 | // Consume errors from missing streams. |
| 223 | if (!Dbi) |
| 224 | consumeError(Dbi.takeError()); |
| 225 | if (!Tpi) |
| 226 | consumeError(Tpi.takeError()); |
| 227 | if (!Ipi) |
| 228 | consumeError(Ipi.takeError()); |
| 229 | if (!Info) |
| 230 | consumeError(Info.takeError()); |
| 231 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 232 | P.flush(); |
| 233 | return Error::success(); |
| 234 | } |
| 235 | |
| 236 | Error LLVMOutputStyle::dumpStreamBlocks() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 237 | if (!opts::raw::DumpStreamBlocks) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 238 | return Error::success(); |
| 239 | |
| 240 | ListScope L(P, "StreamBlocks"); |
| 241 | uint32_t StreamCount = File.getNumStreams(); |
| 242 | for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) { |
| 243 | std::string Name("Stream "); |
| 244 | Name += to_string(StreamIdx); |
| 245 | auto StreamBlocks = File.getStreamBlockList(StreamIdx); |
| 246 | P.printList(Name, StreamBlocks); |
| 247 | } |
| 248 | return Error::success(); |
| 249 | } |
| 250 | |
| 251 | Error LLVMOutputStyle::dumpStreamData() { |
| 252 | uint32_t StreamCount = File.getNumStreams(); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 253 | StringRef DumpStreamStr = opts::raw::DumpStreamDataIdx; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 254 | uint32_t DumpStreamNum; |
Zachary Turner | d2b2bfe | 2016-06-08 00:25:08 +0000 | [diff] [blame] | 255 | if (DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum)) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 256 | return Error::success(); |
| 257 | |
Zachary Turner | d2b2bfe | 2016-06-08 00:25:08 +0000 | [diff] [blame] | 258 | if (DumpStreamNum >= StreamCount) |
| 259 | return make_error<RawError>(raw_error_code::no_stream); |
| 260 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 261 | auto S = MappedBlockStream::createIndexedStream(DumpStreamNum, File); |
| 262 | if (!S) |
| 263 | return S.takeError(); |
| 264 | codeview::StreamReader R(**S); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 265 | while (R.bytesRemaining() > 0) { |
| 266 | ArrayRef<uint8_t> Data; |
| 267 | uint32_t BytesToReadInBlock = std::min( |
| 268 | R.bytesRemaining(), static_cast<uint32_t>(File.getBlockSize())); |
| 269 | if (auto EC = R.readBytes(Data, BytesToReadInBlock)) |
| 270 | return EC; |
| 271 | P.printBinaryBlock( |
| 272 | "Data", |
| 273 | StringRef(reinterpret_cast<const char *>(Data.begin()), Data.size())); |
| 274 | } |
| 275 | return Error::success(); |
| 276 | } |
| 277 | |
| 278 | Error LLVMOutputStyle::dumpInfoStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 279 | if (!opts::raw::DumpHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 280 | return Error::success(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 281 | auto IS = File.getPDBInfoStream(); |
| 282 | if (!IS) |
| 283 | return IS.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 284 | |
| 285 | DictScope D(P, "PDB Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 286 | P.printNumber("Version", IS->getVersion()); |
| 287 | P.printHex("Signature", IS->getSignature()); |
| 288 | P.printNumber("Age", IS->getAge()); |
| 289 | P.printObject("Guid", IS->getGuid()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 290 | return Error::success(); |
| 291 | } |
| 292 | |
| 293 | Error LLVMOutputStyle::dumpNamedStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 294 | if (opts::raw::DumpStreamDataName.empty()) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 295 | return Error::success(); |
| 296 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 297 | auto IS = File.getPDBInfoStream(); |
| 298 | if (!IS) |
| 299 | return IS.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 300 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 301 | uint32_t NameStreamIndex = |
| 302 | IS->getNamedStreamIndex(opts::raw::DumpStreamDataName); |
Zachary Turner | d2b2bfe | 2016-06-08 00:25:08 +0000 | [diff] [blame] | 303 | if (NameStreamIndex == 0 || NameStreamIndex >= File.getNumStreams()) |
| 304 | return make_error<RawError>(raw_error_code::no_stream); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 305 | |
| 306 | if (NameStreamIndex != 0) { |
| 307 | std::string Name("Stream '"); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 308 | Name += opts::raw::DumpStreamDataName; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 309 | Name += "'"; |
| 310 | DictScope D(P, Name); |
| 311 | P.printNumber("Index", NameStreamIndex); |
| 312 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 313 | auto NameStream = |
| 314 | MappedBlockStream::createIndexedStream(NameStreamIndex, File); |
| 315 | if (!NameStream) |
| 316 | return NameStream.takeError(); |
| 317 | codeview::StreamReader Reader(**NameStream); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 318 | |
| 319 | NameHashTable NameTable; |
| 320 | if (auto EC = NameTable.load(Reader)) |
| 321 | return EC; |
| 322 | |
| 323 | P.printHex("Signature", NameTable.getSignature()); |
| 324 | P.printNumber("Version", NameTable.getHashVersion()); |
| 325 | P.printNumber("Name Count", NameTable.getNameCount()); |
| 326 | ListScope L(P, "Names"); |
| 327 | for (uint32_t ID : NameTable.name_ids()) { |
| 328 | StringRef Str = NameTable.getStringForID(ID); |
| 329 | if (!Str.empty()) |
| 330 | P.printString(to_string(ID), Str); |
| 331 | } |
| 332 | } |
| 333 | return Error::success(); |
| 334 | } |
| 335 | |
Rui Ueyama | fd97bf1 | 2016-06-03 20:48:51 +0000 | [diff] [blame] | 336 | static void printTypeIndexOffset(raw_ostream &OS, |
| 337 | const TypeIndexOffset &TIOff) { |
| 338 | OS << "{" << TIOff.Type.getIndex() << ", " << TIOff.Offset << "}"; |
| 339 | } |
| 340 | |
| 341 | static void dumpTpiHash(ScopedPrinter &P, TpiStream &Tpi) { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 342 | if (!opts::raw::DumpTpiHash) |
Rui Ueyama | fd97bf1 | 2016-06-03 20:48:51 +0000 | [diff] [blame] | 343 | return; |
| 344 | DictScope DD(P, "Hash"); |
Rui Ueyama | f14a74c | 2016-06-07 23:53:43 +0000 | [diff] [blame] | 345 | P.printNumber("Number of Hash Buckets", Tpi.NumHashBuckets()); |
Rui Ueyama | d833917 | 2016-06-07 23:44:27 +0000 | [diff] [blame] | 346 | P.printNumber("Hash Key Size", Tpi.getHashKeySize()); |
Rui Ueyama | fd97bf1 | 2016-06-03 20:48:51 +0000 | [diff] [blame] | 347 | P.printList("Values", Tpi.getHashValues()); |
| 348 | P.printList("Type Index Offsets", Tpi.getTypeIndexOffsets(), |
| 349 | printTypeIndexOffset); |
| 350 | P.printList("Hash Adjustments", Tpi.getHashAdjustments(), |
| 351 | printTypeIndexOffset); |
| 352 | } |
| 353 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 354 | Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { |
| 355 | assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI); |
| 356 | |
| 357 | bool DumpRecordBytes = false; |
| 358 | bool DumpRecords = false; |
| 359 | StringRef Label; |
| 360 | StringRef VerLabel; |
| 361 | if (StreamIdx == StreamTPI) { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 362 | DumpRecordBytes = opts::raw::DumpTpiRecordBytes; |
| 363 | DumpRecords = opts::raw::DumpTpiRecords; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 364 | Label = "Type Info Stream (TPI)"; |
| 365 | VerLabel = "TPI Version"; |
| 366 | } else if (StreamIdx == StreamIPI) { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 367 | DumpRecordBytes = opts::raw::DumpIpiRecordBytes; |
| 368 | DumpRecords = opts::raw::DumpIpiRecords; |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 369 | Label = "Type Info Stream (IPI)"; |
| 370 | VerLabel = "IPI Version"; |
| 371 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 372 | if (!DumpRecordBytes && !DumpRecords && !opts::raw::DumpModuleSyms) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 373 | return Error::success(); |
| 374 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 375 | auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream() |
| 376 | : File.getPDBIpiStream(); |
| 377 | if (!Tpi) |
| 378 | return Tpi.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 379 | |
| 380 | if (DumpRecords || DumpRecordBytes) { |
| 381 | DictScope D(P, Label); |
| 382 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 383 | P.printNumber(VerLabel, Tpi->getTpiVersion()); |
| 384 | P.printNumber("Record count", Tpi->NumTypeRecords()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 385 | |
| 386 | ListScope L(P, "Records"); |
| 387 | |
| 388 | bool HadError = false; |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 389 | for (auto &Type : Tpi->types(&HadError)) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 390 | DictScope DD(P, ""); |
| 391 | |
Zachary Turner | 01ee3dae | 2016-06-16 18:22:27 +0000 | [diff] [blame] | 392 | if (DumpRecords) { |
| 393 | if (auto EC = TD.dump(Type)) |
| 394 | return EC; |
| 395 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 396 | |
| 397 | if (DumpRecordBytes) |
| 398 | P.printBinaryBlock("Bytes", Type.Data); |
| 399 | } |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 400 | dumpTpiHash(P, *Tpi); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 401 | if (HadError) |
| 402 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 403 | "TPI stream contained corrupt record"); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 404 | } else if (opts::raw::DumpModuleSyms) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 405 | // Even if the user doesn't want to dump type records, we still need to |
| 406 | // iterate them in order to build the list of types so that we can print |
| 407 | // them when dumping module symbols. So when they want to dump symbols |
| 408 | // but not types, use a null output stream. |
| 409 | ScopedPrinter *OldP = TD.getPrinter(); |
| 410 | TD.setPrinter(nullptr); |
| 411 | |
| 412 | bool HadError = false; |
Zachary Turner | 01ee3dae | 2016-06-16 18:22:27 +0000 | [diff] [blame] | 413 | for (auto &Type : Tpi->types(&HadError)) { |
| 414 | if (auto EC = TD.dump(Type)) |
| 415 | return EC; |
| 416 | } |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 417 | |
| 418 | TD.setPrinter(OldP); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 419 | dumpTpiHash(P, *Tpi); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 420 | if (HadError) |
| 421 | return make_error<RawError>(raw_error_code::corrupt_file, |
| 422 | "TPI stream contained corrupt record"); |
| 423 | } |
| 424 | P.flush(); |
| 425 | return Error::success(); |
| 426 | } |
| 427 | |
| 428 | Error LLVMOutputStyle::dumpDbiStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 429 | bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms || |
| 430 | opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo; |
| 431 | if (!opts::raw::DumpHeaders && !DumpModules) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 432 | return Error::success(); |
| 433 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 434 | auto DS = File.getPDBDbiStream(); |
| 435 | if (!DS) |
| 436 | return DS.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 437 | |
| 438 | DictScope D(P, "DBI Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 439 | P.printNumber("Dbi Version", DS->getDbiVersion()); |
| 440 | P.printNumber("Age", DS->getAge()); |
| 441 | P.printBoolean("Incremental Linking", DS->isIncrementallyLinked()); |
| 442 | P.printBoolean("Has CTypes", DS->hasCTypes()); |
| 443 | P.printBoolean("Is Stripped", DS->isStripped()); |
| 444 | P.printObject("Machine Type", DS->getMachineType()); |
| 445 | P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex()); |
| 446 | P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex()); |
| 447 | P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 448 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 449 | uint16_t Major = DS->getBuildMajorVersion(); |
| 450 | uint16_t Minor = DS->getBuildMinorVersion(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 451 | P.printVersion("Toolchain Version", Major, Minor); |
| 452 | |
| 453 | std::string DllName; |
| 454 | raw_string_ostream DllStream(DllName); |
| 455 | DllStream << "mspdb" << Major << Minor << ".dll version"; |
| 456 | DllStream.flush(); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 457 | P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 458 | |
| 459 | if (DumpModules) { |
| 460 | ListScope L(P, "Modules"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 461 | for (auto &Modi : DS->modules()) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 462 | DictScope DD(P); |
| 463 | P.printString("Name", Modi.Info.getModuleName().str()); |
| 464 | P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex()); |
| 465 | P.printString("Object File Name", Modi.Info.getObjFileName().str()); |
| 466 | P.printNumber("Num Files", Modi.Info.getNumberOfFiles()); |
| 467 | P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex()); |
| 468 | P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex()); |
| 469 | P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize()); |
| 470 | P.printNumber("C13 Line Info Byte Size", |
| 471 | Modi.Info.getC13LineInfoByteSize()); |
| 472 | P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize()); |
| 473 | P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex()); |
| 474 | P.printBoolean("Has EC Info", Modi.Info.hasECInfo()); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 475 | if (opts::raw::DumpModuleFiles) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 476 | std::string FileListName = |
| 477 | to_string(Modi.SourceFiles.size()) + " Contributing Source Files"; |
| 478 | ListScope LL(P, FileListName); |
| 479 | for (auto File : Modi.SourceFiles) |
| 480 | P.printString(File.str()); |
| 481 | } |
| 482 | bool HasModuleDI = |
| 483 | (Modi.Info.getModuleStreamIndex() < File.getNumStreams()); |
| 484 | bool ShouldDumpSymbols = |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 485 | (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes); |
| 486 | if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 487 | auto ModStreamData = MappedBlockStream::createIndexedStream( |
| 488 | Modi.Info.getModuleStreamIndex(), File); |
| 489 | if (!ModStreamData) |
| 490 | return ModStreamData.takeError(); |
| 491 | ModStream ModS(Modi.Info, std::move(*ModStreamData)); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 492 | if (auto EC = ModS.reload()) |
| 493 | return EC; |
| 494 | |
| 495 | if (ShouldDumpSymbols) { |
| 496 | ListScope SS(P, "Symbols"); |
| 497 | codeview::CVSymbolDumper SD(P, TD, nullptr, false); |
| 498 | bool HadError = false; |
| 499 | for (const auto &S : ModS.symbols(&HadError)) { |
| 500 | DictScope DD(P, ""); |
| 501 | |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 502 | if (opts::raw::DumpModuleSyms) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 503 | SD.dump(S); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 504 | if (opts::raw::DumpSymRecordBytes) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 505 | P.printBinaryBlock("Bytes", S.Data); |
| 506 | } |
| 507 | if (HadError) |
| 508 | return make_error<RawError>( |
| 509 | raw_error_code::corrupt_file, |
| 510 | "DBI stream contained corrupt symbol record"); |
| 511 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 512 | if (opts::raw::DumpLineInfo) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 513 | ListScope SS(P, "LineInfo"); |
| 514 | bool HadError = false; |
| 515 | // Define a locally scoped visitor to print the different |
| 516 | // substream types types. |
| 517 | class RecordVisitor : public codeview::IModuleSubstreamVisitor { |
| 518 | public: |
| 519 | RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {} |
| 520 | Error visitUnknown(ModuleSubstreamKind Kind, |
| 521 | StreamRef Stream) override { |
| 522 | DictScope DD(P, "Unknown"); |
| 523 | ArrayRef<uint8_t> Data; |
| 524 | StreamReader R(Stream); |
| 525 | if (auto EC = R.readBytes(Data, R.bytesRemaining())) { |
| 526 | return make_error<RawError>( |
| 527 | raw_error_code::corrupt_file, |
| 528 | "DBI stream contained corrupt line info record"); |
| 529 | } |
| 530 | P.printBinaryBlock("Data", Data); |
| 531 | return Error::success(); |
| 532 | } |
| 533 | Error |
| 534 | visitFileChecksums(StreamRef Data, |
| 535 | const FileChecksumArray &Checksums) override { |
| 536 | DictScope DD(P, "FileChecksums"); |
| 537 | for (const auto &C : Checksums) { |
| 538 | DictScope DDD(P, "Checksum"); |
| 539 | if (auto Result = getFileNameForOffset(C.FileNameOffset)) |
| 540 | P.printString("FileName", Result.get()); |
| 541 | else |
| 542 | return Result.takeError(); |
| 543 | P.flush(); |
| 544 | P.printEnum("Kind", uint8_t(C.Kind), getFileChecksumNames()); |
| 545 | P.printBinaryBlock("Checksum", C.Checksum); |
| 546 | } |
| 547 | return Error::success(); |
| 548 | } |
| 549 | |
| 550 | Error visitLines(StreamRef Data, const LineSubstreamHeader *Header, |
| 551 | const LineInfoArray &Lines) override { |
| 552 | DictScope DD(P, "Lines"); |
| 553 | for (const auto &L : Lines) { |
| 554 | if (auto Result = getFileNameForOffset2(L.NameIndex)) |
| 555 | P.printString("FileName", Result.get()); |
| 556 | else |
| 557 | return Result.takeError(); |
| 558 | P.flush(); |
| 559 | for (const auto &N : L.LineNumbers) { |
| 560 | DictScope DDD(P, "Line"); |
| 561 | LineInfo LI(N.Flags); |
| 562 | P.printNumber("Offset", N.Offset); |
| 563 | if (LI.isAlwaysStepInto()) |
| 564 | P.printString("StepInto", StringRef("Always")); |
| 565 | else if (LI.isNeverStepInto()) |
| 566 | P.printString("StepInto", StringRef("Never")); |
| 567 | else |
| 568 | P.printNumber("LineNumberStart", LI.getStartLine()); |
| 569 | P.printNumber("EndDelta", LI.getLineDelta()); |
| 570 | P.printBoolean("IsStatement", LI.isStatement()); |
| 571 | } |
| 572 | for (const auto &C : L.Columns) { |
| 573 | DictScope DDD(P, "Column"); |
| 574 | P.printNumber("Start", C.StartColumn); |
| 575 | P.printNumber("End", C.EndColumn); |
| 576 | } |
| 577 | } |
| 578 | return Error::success(); |
| 579 | } |
| 580 | |
| 581 | private: |
| 582 | Expected<StringRef> getFileNameForOffset(uint32_t Offset) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 583 | auto ST = F.getStringTable(); |
| 584 | if (!ST) |
| 585 | return ST.takeError(); |
| 586 | |
| 587 | return ST->getStringForID(Offset); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 588 | } |
| 589 | Expected<StringRef> getFileNameForOffset2(uint32_t Offset) { |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 590 | auto DS = F.getPDBDbiStream(); |
| 591 | if (!DS) |
| 592 | return DS.takeError(); |
| 593 | return DS->getFileNameForIndex(Offset); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 594 | } |
| 595 | ScopedPrinter &P; |
| 596 | PDBFile &F; |
| 597 | }; |
| 598 | |
| 599 | RecordVisitor V(P, File); |
| 600 | for (const auto &L : ModS.lines(&HadError)) { |
| 601 | if (auto EC = codeview::visitModuleSubstream(L, V)) |
| 602 | return EC; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | return Error::success(); |
| 609 | } |
| 610 | |
| 611 | Error LLVMOutputStyle::dumpSectionContribs() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 612 | if (!opts::raw::DumpSectionContribs) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 613 | return Error::success(); |
| 614 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 615 | auto Dbi = File.getPDBDbiStream(); |
| 616 | if (!Dbi) |
| 617 | return Dbi.takeError(); |
| 618 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 619 | ListScope L(P, "Section Contributions"); |
| 620 | class Visitor : public ISectionContribVisitor { |
| 621 | public: |
| 622 | Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {} |
| 623 | void visit(const SectionContrib &SC) override { |
| 624 | DictScope D(P, "Contribution"); |
| 625 | P.printNumber("ISect", SC.ISect); |
| 626 | P.printNumber("Off", SC.Off); |
| 627 | P.printNumber("Size", SC.Size); |
| 628 | P.printFlags("Characteristics", SC.Characteristics, |
| 629 | codeview::getImageSectionCharacteristicNames(), |
| 630 | COFF::SectionCharacteristics(0x00F00000)); |
| 631 | { |
| 632 | DictScope DD(P, "Module"); |
| 633 | P.printNumber("Index", SC.Imod); |
| 634 | auto M = DS.modules(); |
| 635 | if (M.size() > SC.Imod) { |
| 636 | P.printString("Name", M[SC.Imod].Info.getModuleName()); |
| 637 | } |
| 638 | } |
| 639 | P.printNumber("Data CRC", SC.DataCrc); |
| 640 | P.printNumber("Reloc CRC", SC.RelocCrc); |
| 641 | P.flush(); |
| 642 | } |
| 643 | void visit(const SectionContrib2 &SC) override { |
| 644 | visit(SC.Base); |
| 645 | P.printNumber("ISect Coff", SC.ISectCoff); |
| 646 | P.flush(); |
| 647 | } |
| 648 | |
| 649 | private: |
| 650 | ScopedPrinter &P; |
| 651 | DbiStream &DS; |
| 652 | }; |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 653 | Visitor V(P, *Dbi); |
| 654 | Dbi->visitSectionContributions(V); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 655 | return Error::success(); |
| 656 | } |
| 657 | |
| 658 | Error LLVMOutputStyle::dumpSectionMap() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 659 | if (!opts::raw::DumpSectionMap) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 660 | return Error::success(); |
| 661 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 662 | auto Dbi = File.getPDBDbiStream(); |
| 663 | if (!Dbi) |
| 664 | return Dbi.takeError(); |
| 665 | |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 666 | ListScope L(P, "Section Map"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 667 | for (auto &M : Dbi->getSectionMap()) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 668 | DictScope D(P, "Entry"); |
| 669 | P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames()); |
| 670 | P.printNumber("Flags", M.Flags); |
| 671 | P.printNumber("Ovl", M.Ovl); |
| 672 | P.printNumber("Group", M.Group); |
| 673 | P.printNumber("Frame", M.Frame); |
| 674 | P.printNumber("SecName", M.SecName); |
| 675 | P.printNumber("ClassName", M.ClassName); |
| 676 | P.printNumber("Offset", M.Offset); |
| 677 | P.printNumber("SecByteLength", M.SecByteLength); |
| 678 | P.flush(); |
| 679 | } |
| 680 | return Error::success(); |
| 681 | } |
| 682 | |
| 683 | Error LLVMOutputStyle::dumpPublicsStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 684 | if (!opts::raw::DumpPublics) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 685 | return Error::success(); |
| 686 | |
| 687 | DictScope D(P, "Publics Stream"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 688 | auto Publics = File.getPDBPublicsStream(); |
| 689 | if (!Publics) |
| 690 | return Publics.takeError(); |
| 691 | |
| 692 | auto Dbi = File.getPDBDbiStream(); |
| 693 | if (!Dbi) |
| 694 | return Dbi.takeError(); |
| 695 | |
| 696 | P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex()); |
| 697 | P.printNumber("SymHash", Publics->getSymHash()); |
| 698 | P.printNumber("AddrMap", Publics->getAddrMap()); |
| 699 | P.printNumber("Number of buckets", Publics->getNumBuckets()); |
| 700 | P.printList("Hash Buckets", Publics->getHashBuckets()); |
| 701 | P.printList("Address Map", Publics->getAddressMap()); |
| 702 | P.printList("Thunk Map", Publics->getThunkMap()); |
| 703 | P.printList("Section Offsets", Publics->getSectionOffsets(), |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 704 | printSectionOffset); |
| 705 | ListScope L(P, "Symbols"); |
| 706 | codeview::CVSymbolDumper SD(P, TD, nullptr, false); |
| 707 | bool HadError = false; |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 708 | for (auto S : Publics->getSymbols(&HadError)) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 709 | DictScope DD(P, ""); |
| 710 | |
| 711 | SD.dump(S); |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 712 | if (opts::raw::DumpSymRecordBytes) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 713 | P.printBinaryBlock("Bytes", S.Data); |
| 714 | } |
| 715 | if (HadError) |
| 716 | return make_error<RawError>( |
| 717 | raw_error_code::corrupt_file, |
| 718 | "Public symbol stream contained corrupt record"); |
| 719 | |
| 720 | return Error::success(); |
| 721 | } |
| 722 | |
| 723 | Error LLVMOutputStyle::dumpSectionHeaders() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 724 | if (!opts::raw::DumpSectionHeaders) |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 725 | return Error::success(); |
| 726 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 727 | auto Dbi = File.getPDBDbiStream(); |
| 728 | if (!Dbi) |
| 729 | return Dbi.takeError(); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 730 | |
| 731 | ListScope D(P, "Section Headers"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 732 | for (const object::coff_section &Section : Dbi->getSectionHeaders()) { |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 733 | DictScope DD(P, ""); |
| 734 | |
| 735 | // If a name is 8 characters long, there is no NUL character at end. |
| 736 | StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name))); |
| 737 | P.printString("Name", Name); |
| 738 | P.printNumber("Virtual Size", Section.VirtualSize); |
| 739 | P.printNumber("Virtual Address", Section.VirtualAddress); |
| 740 | P.printNumber("Size of Raw Data", Section.SizeOfRawData); |
| 741 | P.printNumber("File Pointer to Raw Data", Section.PointerToRawData); |
| 742 | P.printNumber("File Pointer to Relocations", Section.PointerToRelocations); |
| 743 | P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers); |
| 744 | P.printNumber("Number of Relocations", Section.NumberOfRelocations); |
| 745 | P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers); |
Rui Ueyama | 2c5384a | 2016-06-06 21:34:55 +0000 | [diff] [blame] | 746 | P.printFlags("Characteristics", Section.Characteristics, |
| 747 | getImageSectionCharacteristicNames()); |
Zachary Turner | d311739 | 2016-06-03 19:28:33 +0000 | [diff] [blame] | 748 | } |
| 749 | return Error::success(); |
| 750 | } |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 751 | |
| 752 | Error LLVMOutputStyle::dumpFpoStream() { |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 753 | if (!opts::raw::DumpFpo) |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 754 | return Error::success(); |
| 755 | |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 756 | auto Dbi = File.getPDBDbiStream(); |
| 757 | if (!Dbi) |
| 758 | return Dbi.takeError(); |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 759 | |
| 760 | ListScope D(P, "New FPO"); |
Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 761 | for (const object::FpoData &Fpo : Dbi->getFpoRecords()) { |
Rui Ueyama | ef2b488 | 2016-06-06 18:39:21 +0000 | [diff] [blame] | 762 | DictScope DD(P, ""); |
| 763 | P.printNumber("Offset", Fpo.Offset); |
| 764 | P.printNumber("Size", Fpo.Size); |
| 765 | P.printNumber("Number of locals", Fpo.NumLocals); |
| 766 | P.printNumber("Number of params", Fpo.NumParams); |
| 767 | P.printNumber("Size of Prolog", Fpo.getPrologSize()); |
| 768 | P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs()); |
| 769 | P.printBoolean("Has SEH", Fpo.hasSEH()); |
| 770 | P.printBoolean("Use BP", Fpo.useBP()); |
| 771 | P.printNumber("Frame Pointer", Fpo.getFP()); |
| 772 | } |
| 773 | return Error::success(); |
| 774 | } |
Zachary Turner | a30bd1a | 2016-06-30 17:42:48 +0000 | [diff] [blame] | 775 | |
Zachary Turner | 7120a47 | 2016-06-06 20:37:05 +0000 | [diff] [blame] | 776 | void LLVMOutputStyle::flush() { P.flush(); } |