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