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