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