llvm.org GIT mirror llvm / fabcc79
[llvm-pdbutil] Support PDBs without a DBI stream Differential Revision: https://reviews.llvm.org/D50258 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339045 91177308-0d34-0410-b5e6-96231b3b80d8 Alexandre Ganea 1 year, 1 month ago
8 changed file(s) with 215 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
400400 return 4;
401401 }
402402
403 bool PDBFile::hasPDBDbiStream() const { return StreamDBI < getNumStreams(); }
403 bool PDBFile::hasPDBDbiStream() const {
404 return StreamDBI < getNumStreams() && getStreamByteSize(StreamDBI) > 0;
405 }
404406
405407 bool PDBFile::hasPDBGlobalsStream() {
406408 auto DbiS = getPDBDbiStream();
0 // Compile with "cl /c /Zi TypeServerTest.cpp /FdTypeServerTest.pdb"
1
2 int main(void)
3 {
4 return 0;
5 }
0
1 RUN: llvm-pdbutil dump -all %p/Inputs/TypeServerTest.pdb | FileCheck %s --check-prefix=NO-DBI
2 RUN: llvm-pdbutil pdb2yaml -all %p/Inputs/TypeServerTest.pdb > %t
3 RUN: FileCheck --input-file=%t %s --check-prefix=NO-DBI-YAML
4
5 NO-DBI-NOT: Native PDB Error: The specified stream could not be loaded.
6
7 NO-DBI: Module Stats
8 NO-DBI-NEXT: ============================================================
9 NO-DBI-NEXT: DBI stream not present
10
11 NO-DBI: S_UDT Record Stats
12 NO-DBI-NEXT: ============================================================
13 NO-DBI-NEXT: Globals stream not present
14
15 NO-DBI: Modules
16 NO-DBI-NEXT: ============================================================
17 NO-DBI-NEXT: DBI stream not present
18
19 NO-DBI: Files
20 NO-DBI-NEXT: ============================================================
21 NO-DBI-NEXT: DBI stream not present
22
23 NO-DBI: Lines
24 NO-DBI-NEXT: ============================================================
25 NO-DBI-NEXT: DBI stream not present
26
27 NO-DBI: Inlinee Lines
28 NO-DBI-NEXT: ============================================================
29 NO-DBI-NEXT: DBI stream not present
30
31 NO-DBI: Cross Module Imports
32 NO-DBI-NEXT: ============================================================
33 NO-DBI-NEXT: DBI stream not present
34
35 NO-DBI: Cross Module Exports
36 NO-DBI-NEXT: ============================================================
37 NO-DBI-NEXT: DBI stream not present
38
39
40 NO-DBI-YAML-NOT: Native PDB Error: The specified stream could not be loaded.
41
42 NO-DBI-YAML: TpiStream:
43 NO-DBI-YAML-NEXT: Version: VC80
44 NO-DBI-YAML-NEXT: Records:
45 NO-DBI-YAML-NEXT: - Kind: LF_ARGLIST
6464 PDBFile &DumpOutputStyle::getPdb() { return File.pdb(); }
6565 object::COFFObjectFile &DumpOutputStyle::getObj() { return File.obj(); }
6666
67 void DumpOutputStyle::printStreamNotValidForObj() {
68 AutoIndent Indent(P, 4);
69 P.formatLine("Dumping this stream is not valid for object files");
70 }
71
72 void DumpOutputStyle::printStreamNotPresent(StringRef StreamName) {
73 AutoIndent Indent(P, 4);
74 P.formatLine("{0} stream not present", StreamName);
75 }
76
6777 Error DumpOutputStyle::dump() {
6878 if (opts::dump::DumpSummary) {
6979 if (auto EC = dumpFileSummary())
198208 Error DumpOutputStyle::dumpFileSummary() {
199209 printHeader(P, "Summary");
200210
211 if (File.isObj()) {
212 printStreamNotValidForObj();
213 return Error::success();
214 }
215
216 AutoIndent Indent(P);
201217 ExitOnError Err("Invalid PDB Format: ");
202
203 AutoIndent Indent(P);
204 if (File.isObj()) {
205 P.formatLine("Dumping File summary is not valid for object files");
206 return Error::success();
207 }
208218
209219 P.formatLine("Block Size: {0}", getPdb().getBlockSize());
210220 P.formatLine("Number of blocks: {0}", getPdb().getBlockCount());
325335 Error DumpOutputStyle::dumpStreamSummary() {
326336 printHeader(P, "Streams");
327337
338 if (File.isObj()) {
339 printStreamNotValidForObj();
340 return Error::success();
341 }
342
328343 AutoIndent Indent(P);
329 if (File.isObj()) {
330 P.formatLine("Dumping streams is not valid for object files");
331 return Error::success();
332 }
333344
334345 if (StreamPurposes.empty())
335346 discoverStreamPurposes(getPdb(), StreamPurposes);
526537
527538 Error DumpOutputStyle::dumpModules() {
528539 printHeader(P, "Modules");
540
541 if (File.isObj()) {
542 printStreamNotValidForObj();
543 return Error::success();
544 }
545
546 if (!getPdb().hasPDBDbiStream()) {
547 printStreamNotPresent("DBI");
548 return Error::success();
549 }
550
529551 AutoIndent Indent(P);
530
531 if (File.isObj()) {
532 P.formatLine("Dumping modules is not supported for object files");
533 return Error::success();
534 }
535
536 if (!getPdb().hasPDBDbiStream()) {
537 P.formatLine("DBI Stream not present");
538 return Error::success();
539 }
540
541552 ExitOnError Err("Unexpected error processing modules: ");
542553
543554 auto &Stream = Err(getPdb().getPDBDbiStream());
569580 printHeader(P, "Files");
570581
571582 if (File.isObj()) {
572 P.formatLine("Dumping files is not valid for object files");
583 printStreamNotValidForObj();
584 return Error::success();
585 }
586
587 if (!getPdb().hasPDBDbiStream()) {
588 printStreamNotPresent("DBI");
573589 return Error::success();
574590 }
575591
589605
590606 Error DumpOutputStyle::dumpSymbolStats() {
591607 printHeader(P, "Module Stats");
608
609 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
610 printStreamNotPresent("DBI");
611 return Error::success();
612 }
592613
593614 ExitOnError Err("Unexpected error processing modules: ");
594615
624645 }
625646 });
626647
627 P.printLine(" Summary |");
628 AutoIndent Indent(P, 4);
629648 if (SymStats.Totals.Count > 0) {
649 P.printLine(" Summary |");
650 AutoIndent Indent(P, 4);
630651 printModuleDetailStats(P, "Symbols", SymStats);
631652 printModuleDetailStats(P, "Chunks", ChunkStats);
632653 }
678699
679700 Error DumpOutputStyle::dumpUdtStats() {
680701 printHeader(P, "S_UDT Record Stats");
702
703 if (File.isPdb() && !getPdb().hasPDBGlobalsStream()) {
704 printStreamNotPresent("Globals");
705 return Error::success();
706 }
681707
682708 StatCollection UdtStats;
683709 StatCollection UdtTargetStats;
725751 P.NewLine();
726752
727753 if (File.isPdb()) {
728 if (!getPdb().hasPDBGlobalsStream()) {
729 P.printLine("- Error: globals stream not present");
730 return Error::success();
731 }
732
733754 auto &SymbolRecords = cantFail(getPdb().getPDBSymbolStream());
734755 auto ExpGlobals = getPdb().getPDBGlobalsStream();
735756 if (!ExpGlobals)
838859 Error DumpOutputStyle::dumpLines() {
839860 printHeader(P, "Lines");
840861
862 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
863 printStreamNotPresent("DBI");
864 return Error::success();
865 }
866
841867 uint32_t LastModi = UINT32_MAX;
842868 uint32_t LastNameIndex = UINT32_MAX;
843869 iterateModuleSubsections(
874900 Error DumpOutputStyle::dumpInlineeLines() {
875901 printHeader(P, "Inlinee Lines");
876902
903 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
904 printStreamNotPresent("DBI");
905 return Error::success();
906 }
907
877908 iterateModuleSubsections(
878909 File, PrintScope{P, 2},
879910 [this](uint32_t Modi, const SymbolGroup &Strings,
892923
893924 Error DumpOutputStyle::dumpXmi() {
894925 printHeader(P, "Cross Module Imports");
926
927 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
928 printStreamNotPresent("DBI");
929 return Error::success();
930 }
931
895932 iterateModuleSubsections(
896933 File, PrintScope{P, 2},
897934 [this](uint32_t Modi, const SymbolGroup &Strings,
928965 Error DumpOutputStyle::dumpXme() {
929966 printHeader(P, "Cross Module Exports");
930967
968 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
969 printStreamNotPresent("DBI");
970 return Error::success();
971 }
972
931973 iterateModuleSubsections(
932974 File, PrintScope{P, 2},
933975 [this](uint32_t Modi, const SymbolGroup &Strings,
10361078
10371079 Error DumpOutputStyle::dumpNamedStreams() {
10381080 printHeader(P, "Named Streams");
1039 AutoIndent Indent(P, 2);
10401081
10411082 if (File.isObj()) {
1042 P.formatLine("Dumping Named Streams is only supported for PDB files.");
1043 return Error::success();
1044 }
1083 printStreamNotValidForObj();
1084 return Error::success();
1085 }
1086
1087 AutoIndent Indent(P);
10451088 ExitOnError Err("Invalid PDB File: ");
10461089
10471090 auto &IS = Err(File.pdb().getPDBInfoStream());
12031246 printHeader(P, "Types (IPI Stream)");
12041247 }
12051248
1206 AutoIndent Indent(P);
12071249 assert(!File.isObj());
12081250
12091251 bool Present = false;
12281270 }
12291271
12301272 if (!Present) {
1231 P.formatLine("Stream not present");
1232 return Error::success();
1233 }
1234
1273 printStreamNotPresent(StreamIdx == StreamTPI ? "TPI" : "IPI");
1274 return Error::success();
1275 }
1276
1277 AutoIndent Indent(P);
12351278 ExitOnError Err("Unexpected error processing types: ");
12361279
12371280 auto &Stream = Err((StreamIdx == StreamTPI) ? getPdb().getPDBTpiStream()
13201363 Error DumpOutputStyle::dumpModuleSymsForPdb() {
13211364 printHeader(P, "Symbols");
13221365
1366 if (File.isPdb() && !getPdb().hasPDBDbiStream()) {
1367 printStreamNotPresent("DBI");
1368 return Error::success();
1369 }
1370
13231371 AutoIndent Indent(P);
1324 if (!getPdb().hasPDBDbiStream()) {
1325 P.formatLine("DBI Stream not present");
1326 return Error::success();
1327 }
1328
13291372 ExitOnError Err("Unexpected error processing symbols: ");
13301373
13311374 auto &Ids = File.ids();
13631406
13641407 Error DumpOutputStyle::dumpGSIRecords() {
13651408 printHeader(P, "GSI Records");
1409
1410 if (File.isObj()) {
1411 printStreamNotValidForObj();
1412 return Error::success();
1413 }
1414
1415 if (!getPdb().hasPDBSymbolStream()) {
1416 printStreamNotPresent("GSI Common Symbol");
1417 return Error::success();
1418 }
1419
13661420 AutoIndent Indent(P);
1367
1368 if (File.isObj()) {
1369 P.formatLine("Dumping Globals is not supported for object files");
1370 return Error::success();
1371 }
1372
1373 if (!getPdb().hasPDBSymbolStream()) {
1374 P.formatLine("GSI Common Symbol Stream not present");
1375 return Error::success();
1376 }
13771421
13781422 auto &Records = cantFail(getPdb().getPDBSymbolStream());
13791423 auto &Types = File.types();
13961440
13971441 Error DumpOutputStyle::dumpGlobals() {
13981442 printHeader(P, "Global Symbols");
1443
1444 if (File.isObj()) {
1445 printStreamNotValidForObj();
1446 return Error::success();
1447 }
1448
1449 if (!getPdb().hasPDBGlobalsStream()) {
1450 printStreamNotPresent("Globals");
1451 return Error::success();
1452 }
1453
13991454 AutoIndent Indent(P);
1400
1401 if (File.isObj()) {
1402 P.formatLine("Dumping Globals is not supported for object files");
1403 return Error::success();
1404 }
1405
1406 if (!getPdb().hasPDBGlobalsStream()) {
1407 P.formatLine("Globals stream not present");
1408 return Error::success();
1409 }
14101455 ExitOnError Err("Error dumping globals stream: ");
14111456 auto &Globals = Err(getPdb().getPDBGlobalsStream());
14121457
14171462
14181463 Error DumpOutputStyle::dumpPublics() {
14191464 printHeader(P, "Public Symbols");
1465
1466 if (File.isObj()) {
1467 printStreamNotValidForObj();
1468 return Error::success();
1469 }
1470
1471 if (!getPdb().hasPDBPublicsStream()) {
1472 printStreamNotPresent("Publics");
1473 return Error::success();
1474 }
1475
14201476 AutoIndent Indent(P);
1421
1422 if (File.isObj()) {
1423 P.formatLine("Dumping Globals is not supported for object files");
1424 return Error::success();
1425 }
1426
1427 if (!getPdb().hasPDBPublicsStream()) {
1428 P.formatLine("Publics stream not present");
1429 return Error::success();
1430 }
14311477 ExitOnError Err("Error dumping publics stream: ");
14321478 auto &Publics = Err(getPdb().getPDBPublicsStream());
14331479
15591605 void DumpOutputStyle::dumpSectionHeaders(StringRef Label, DbgHeaderType Type) {
15601606 printHeader(P, Label);
15611607
1608 if (File.isObj()) {
1609 printStreamNotValidForObj();
1610 return;
1611 }
1612
1613 if (!getPdb().hasPDBDbiStream()) {
1614 printStreamNotPresent("DBI");
1615 return;
1616 }
1617
15621618 AutoIndent Indent(P);
1563 if (File.isObj()) {
1564 P.formatLine("Dumping Section Headers is not supported for object files");
1565 return;
1566 }
1567
15681619 ExitOnError Err("Error dumping section headers: ");
15691620 std::unique_ptr Stream;
15701621 ArrayRef Headers;
16051656 Error DumpOutputStyle::dumpSectionContribs() {
16061657 printHeader(P, "Section Contributions");
16071658
1659 if (File.isObj()) {
1660 printStreamNotValidForObj();
1661 return Error::success();
1662 }
1663
1664 if (!getPdb().hasPDBDbiStream()) {
1665 printStreamNotPresent("DBI");
1666 return Error::success();
1667 }
1668
16081669 AutoIndent Indent(P);
1609 if (File.isObj()) {
1610 P.formatLine(
1611 "Dumping section contributions is not supported for object files");
1612 return Error::success();
1613 }
1614
16151670 ExitOnError Err("Error dumping section contributions: ");
1616 if (!getPdb().hasPDBDbiStream()) {
1617 P.formatLine(
1618 "Section contribs require a DBI Stream, which could not be loaded");
1619 return Error::success();
1620 }
16211671
16221672 auto &Dbi = Err(getPdb().getPDBDbiStream());
16231673
16501700
16511701 Error DumpOutputStyle::dumpSectionMap() {
16521702 printHeader(P, "Section Map");
1703
1704 if (File.isObj()) {
1705 printStreamNotValidForObj();
1706 return Error::success();
1707 }
1708
1709 if (!getPdb().hasPDBDbiStream()) {
1710 printStreamNotPresent("DBI");
1711 return Error::success();
1712 }
1713
16531714 AutoIndent Indent(P);
1654
1655 if (File.isObj()) {
1656 P.formatLine("Dumping section map is not supported for object files");
1657 return Error::success();
1658 }
1659
16601715 ExitOnError Err("Error dumping section map: ");
1661
1662 if (!getPdb().hasPDBDbiStream()) {
1663 P.formatLine("Dumping the section map requires a DBI Stream, which could "
1664 "not be loaded");
1665 return Error::success();
1666 }
16671716
16681717 auto &Dbi = Err(getPdb().getPDBDbiStream());
16691718
6969 PDBFile &getPdb();
7070 object::COFFObjectFile &getObj();
7171
72 void printStreamNotValidForObj();
73 void printStreamNotPresent(StringRef StreamName);
74
7275 Error dumpFileSummary();
7376 Error dumpStreamSummary();
7477 Error dumpSymbolStats();
4040
4141 auto &Dbi = Err(File.getPDBDbiStream());
4242 const auto &Modules = Dbi.modules();
43 if (Index >= Modules.getModuleCount())
44 return make_error(raw_error_code::index_out_of_bounds,
45 "Invalid module index");
46
4347 auto Modi = Modules.getModuleDescriptor(Index);
4448
4549 ModuleName = Modi.getModuleName();
190190 if (!opts::pdb2yaml::DbiStream)
191191 return Error::success();
192192
193 if (!File.hasPDBDbiStream())
194 return Error::success();
195
193196 auto DbiS = File.getPDBDbiStream();
194197 if (!DbiS)
195198 return DbiS.takeError();