llvm.org GIT mirror llvm / b18693c
[llvm-pdbdump] Only build the TypeDatabase if necessary. Building the type database is expensive, and can take multiple minutes for large PDBs. But we only need it in certain cases depending on what command line options are specified. So only build it when we know we're about to need it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302204 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
2 changed file(s) with 81 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
608608 VerLabel = "IPI Version";
609609 }
610610
611 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
612 if (IsSilentDatabaseBuild) {
613 outs().flush();
614 errs() << "Building Type Information For " << Label << "\n";
615 }
611 if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash)
612 return Error::success();
616613
617614 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
618615 : File.getPDBIpiStream();
622619 std::unique_ptr StreamScope;
623620 std::unique_ptr RecordScope;
624621
625 if (!IsSilentDatabaseBuild) {
626 StreamScope = llvm::make_unique(P, Label);
627 P.printNumber(VerLabel, Tpi->getTpiVersion());
628 P.printNumber("Record count", Tpi->NumTypeRecords());
629 }
630
631 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
632
633 TypeDatabaseVisitor DBV(StreamDB);
634 CompactTypeDumpVisitor CTDV(StreamDB, &P);
635 TypeDumpVisitor TDV(TypeDB, &P, false);
636 if (StreamIdx == StreamIPI)
637 TDV.setItemDB(ItemDB);
638 RecordBytesVisitor RBV(P);
639 TypeDeserializer Deserializer;
622 StreamScope = llvm::make_unique(P, Label);
623 P.printNumber(VerLabel, Tpi->getTpiVersion());
624 P.printNumber("Record count", Tpi->NumTypeRecords());
625
626 Optional &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
627
628 std::vector> Visitors;
629
630 Visitors.push_back(make_unique());
631 if (!StreamDB.hasValue()) {
632 StreamDB.emplace();
633 Visitors.push_back(make_unique(*StreamDB));
634 }
635 // If we're in dump mode, add a dumper with the appropriate detail level.
636 if (DumpRecords) {
637 std::unique_ptr Dumper;
638 if (opts::raw::CompactRecords)
639 Dumper = make_unique(*StreamDB, &P);
640 else {
641 assert(TypeDB.hasValue());
642
643 auto X = make_unique(*TypeDB, &P, false);
644 if (StreamIdx == StreamIPI)
645 X->setItemDB(*ItemDB);
646 Dumper = std::move(X);
647 }
648 Visitors.push_back(std::move(Dumper));
649 }
650 if (DumpRecordBytes)
651 Visitors.push_back(make_unique(P));
640652
641653 // We always need to deserialize and add it to the type database. This is
642654 // true if even if we're not dumping anything, because we could need the
643655 // type database for the purposes of dumping symbols.
644656 TypeVisitorCallbackPipeline Pipeline;
645 Pipeline.addCallbackToPipeline(Deserializer);
646 Pipeline.addCallbackToPipeline(DBV);
647
648 // If we're in dump mode, add a dumper with the appropriate detail level.
649 if (DumpRecords) {
650 if (opts::raw::CompactRecords)
651 Pipeline.addCallbackToPipeline(CTDV);
652 else
653 Pipeline.addCallbackToPipeline(TDV);
654 }
655 if (DumpRecordBytes)
656 Pipeline.addCallbackToPipeline(RBV);
657 for (const auto &V : Visitors)
658 Pipeline.addCallbackToPipeline(*V);
657659
658660 CVTypeVisitor Visitor(Pipeline);
659661
699701 }
700702 }
701703
702 if (!IsSilentDatabaseBuild) {
703 ListScope L(P, "TypeIndexOffsets");
704 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
705 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
706 (uint32_t)IO.Offset)
707 .str());
708 }
704 ListScope L(P, "TypeIndexOffsets");
705 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
706 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
707 (uint32_t)IO.Offset)
708 .str());
709709 }
710710
711711 P.flush();
712712 return Error::success();
713 }
714
715 Error LLVMOutputStyle::buildTypeDatabase(uint32_t SN) {
716 assert(SN == StreamIPI || SN == StreamTPI);
717
718 auto &DB = (SN == StreamIPI) ? ItemDB : TypeDB;
719
720 if (DB.hasValue())
721 return Error::success();
722
723 DB.emplace();
724
725 TypeVisitorCallbackPipeline Pipeline;
726 TypeDeserializer Deserializer;
727 TypeDatabaseVisitor DBV(*DB);
728 Pipeline.addCallbackToPipeline(Deserializer);
729 Pipeline.addCallbackToPipeline(DBV);
730
731 auto Tpi =
732 (SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream();
733 if (!Tpi)
734 return Tpi.takeError();
735
736 CVTypeVisitor Visitor(Pipeline);
737 return Visitor.visitTypeStream(Tpi->types(nullptr));
713738 }
714739
715740 Error LLVMOutputStyle::dumpDbiStream() {
784809 return EC;
785810
786811 if (ShouldDumpSymbols) {
812 if (auto EC = buildTypeDatabase(StreamTPI))
813 return EC;
814
787815 ListScope SS(P, "Symbols");
788 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
816 codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false);
789817 bool HadError = false;
790818 for (auto S : ModS.symbols(&HadError)) {
791819 DictScope LL(P, "");
806834 }
807835 if (opts::raw::DumpLineInfo) {
808836 ListScope SS(P, "LineInfo");
809
810 C13RawVisitor V(P, File, ItemDB);
837 if (auto EC = buildTypeDatabase(StreamIPI))
838 return EC;
839
840 C13RawVisitor V(P, File, *ItemDB);
811841 if (auto EC = codeview::visitModuleDebugFragments(
812842 ModS.linesAndChecksums(), V))
813843 return EC;
924954 P.printList("Section Offsets", Publics->getSectionOffsets(),
925955 printSectionOffset);
926956 ListScope L(P, "Symbols");
927 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
957 if (auto EC = buildTypeDatabase(StreamTPI))
958 return EC;
959
960 codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false);
928961 bool HadError = false;
929962 for (auto S : Publics->getSymbols(&HadError)) {
930963 DictScope DD(P, "");
1111
1212 #include "OutputStyle.h"
1313
14 #include "llvm/ADT/Optional.h"
1415 #include "llvm/ADT/SmallVector.h"
1516 #include "llvm/DebugInfo/CodeView/TypeDatabase.h"
1617 #include "llvm/Support/ScopedPrinter.h"
2728 Error dump() override;
2829
2930 private:
31 Error buildTypeDatabase(uint32_t SN);
32
3033 Error dumpFileHeaders();
3134 Error dumpStreamSummary();
3235 Error dumpFreePageMap();
5053
5154 PDBFile &File;
5255 ScopedPrinter P;
53 codeview::TypeDatabase TypeDB;
54 codeview::TypeDatabase ItemDB;
56 Optional TypeDB;
57 Optional ItemDB;
5558 SmallVector StreamPurposes;
5659 };
5760 }