llvm.org GIT mirror llvm / 3a4681d
Update llvm-pdbdump to use subcommands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274247 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
21 changed file(s) with 426 addition(s) and 491 deletion(s). Raw diff Collapse all Expand all
None ; RUN: llvm-pdbdump %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=NO_ARGS
1 ; RUN: llvm-pdbdump -types %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=TYPES
2 ; RUN: llvm-pdbdump -compilands %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=COMPILANDS
3 ; RUN: llvm-pdbdump -types -compilands %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=MULTIPLE
0 ; RUN: llvm-pdbdump pretty %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=NO_ARGS
1 ; RUN: llvm-pdbdump pretty -types %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=TYPES
2 ; RUN: llvm-pdbdump pretty -compilands %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=COMPILANDS
3 ; RUN: llvm-pdbdump pretty -types -compilands %p/../Inputs/empty.pdb | FileCheck %s -check-prefix=MULTIPLE
44
55 ; Check that neither symbols nor compilands are dumped when neither argument specified.
66 ; NO_ARGS: empty.pdb
None ; RUN: llvm-pdbdump -lines %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=LINE_NUMS %s
0 ; RUN: llvm-pdbdump pretty -lines %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=LINE_NUMS %s
11
22 ; LINE_NUMS: llvm\test\debuginfo\pdb\inputs\symbolformat-fpo.cpp
33 ; LINE_NUMS: Line 5, Address: [0x000011a0 - 0x000011a5] (6 bytes)
None ; RUN: llvm-pdbdump -symbols %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=SYM_FORMAT %s
1 ; RUN: llvm-pdbdump -types %p/../Inputs/symbolformat.pdb > %t.types
0 ; RUN: llvm-pdbdump pretty -symbols %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=SYM_FORMAT %s
1 ; RUN: llvm-pdbdump pretty -types %p/../Inputs/symbolformat.pdb > %t.types
22 ; RUN: FileCheck --check-prefix=TYPES_FORMAT %s < %t.types
33 ; RUN: FileCheck --check-prefix=TYPES_1 %s < %t.types
44 ; RUN: FileCheck --check-prefix=TYPES_2 %s < %t.types
5 ; RUN: llvm-pdbdump -types %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=TYPES_FORMAT %s
6 ; RUN: llvm-pdbdump -globals %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=GLOBALS %s
5 ; RUN: llvm-pdbdump pretty -types %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=TYPES_FORMAT %s
6 ; RUN: llvm-pdbdump pretty -globals %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=GLOBALS %s
77
88 ; The format is func [0x+ - 0x-]
99 ; SYM_FORMAT: ---SYMBOLS---
None ; RUN: llvm-pdbdump -raw-headers -raw-tpi-records -raw-tpi-record-bytes -raw-module-syms \
1 ; RUN: -raw-sym-record-bytes -raw-publics -raw-module-files -raw-stream-name=/names \
2 ; RUN: -raw-stream-summary -raw-stream-blocks -raw-ipi-records -raw-ipi-record-bytes \
3 ; RUN: -raw-section-contribs -raw-section-map -raw-section-headers -raw-line-info \
4 ; RUN: -raw-tpi-hash -raw-fpo %p/Inputs/empty.pdb | FileCheck -check-prefix=EMPTY %s
5 ; RUN: llvm-pdbdump -raw-all %p/Inputs/empty.pdb | FileCheck -check-prefix=ALL %s
6 ; RUN: llvm-pdbdump -raw-headers -raw-stream-name=/names -raw-modules -raw-module-files \
0 ; RUN: llvm-pdbdump raw -headers -tpi-records -tpi-record-bytes -module-syms \
1 ; RUN: -sym-record-bytes -publics -module-files -stream-name=/names \
2 ; RUN: -stream-summary -stream-blocks -ipi-records -ipi-record-bytes \
3 ; RUN: -section-contribs -section-map -section-headers -line-info \
4 ; RUN: -tpi-hash -fpo %p/Inputs/empty.pdb | FileCheck -check-prefix=EMPTY %s
5 ; RUN: llvm-pdbdump raw -all %p/Inputs/empty.pdb | FileCheck -check-prefix=ALL %s
6 ; RUN: llvm-pdbdump raw -headers -stream-name=/names -modules -module-files \
77 ; RUN: %p/Inputs/big-read.pdb | FileCheck -check-prefix=BIG %s
8 ; RUN: not llvm-pdbdump -raw-headers %p/Inputs/bad-block-size.pdb 2>&1 | FileCheck -check-prefix=BAD-BLOCK-SIZE %s
8 ; RUN: not llvm-pdbdump raw -headers %p/Inputs/bad-block-size.pdb 2>&1 | FileCheck -check-prefix=BAD-BLOCK-SIZE %s
99
1010 ; EMPTY: FileHeaders {
1111 ; EMPTY-NEXT: BlockSize: 4096
None ; RUN: llvm-pdbdump -raw-headers -raw-output-style=YAML %p/Inputs/empty.pdb \
1 ; RUN: | FileCheck -check-prefix=YAML %s
0 ; RUN: llvm-pdbdump pdb2yaml -stream-metadata %p/Inputs/empty.pdb | FileCheck -check-prefix=YAML %s
21
32 ; YAML: ---
43 ; YAML-NEXT: MSF:
1514 ; YAML-NEXT: - 23
1615 ; YAML-NEXT: NumStreams: 17
1716 ; YAML-NEXT: FileSize: 102400
18 ; YAML-NEXT: ...
17 ; YAML: ...
None ; RUN: llvm-pdbdump -all %p/Inputs/ClassLayoutTest.pdb > %t
0 ; RUN: llvm-pdbdump pretty -all %p/Inputs/ClassLayoutTest.pdb > %t
11 ; RUN: FileCheck -input-file=%t %s -check-prefix=GLOBALS_TEST
22 ; RUN: FileCheck -input-file=%t %s -check-prefix=MEMBERS_TEST
33 ; RUN: FileCheck -input-file=%t %s -check-prefix=BASE_CLASS_A
None ; RUN: llvm-pdbdump -types %p/Inputs/ClassLayoutTest.pdb > %t
0 ; RUN: llvm-pdbdump pretty -types %p/Inputs/ClassLayoutTest.pdb > %t
11 ; RUN: FileCheck -input-file=%t %s -check-prefix=GLOBAL_ENUM
22 ; RUN: FileCheck -input-file=%t %s -check-prefix=MEMBER_ENUM
33
None ; RUN: llvm-pdbdump -externals %p/Inputs/LoadAddressTest.pdb \
0 ; RUN: llvm-pdbdump pretty -externals %p/Inputs/LoadAddressTest.pdb \
11 ; RUN: | FileCheck --check-prefix=RVA %s
2 ; RUN: llvm-pdbdump -externals -load-address=0x40000000 \
2 ; RUN: llvm-pdbdump pretty -externals -load-address=0x40000000 \
33 ; RUN: %p/Inputs/LoadAddressTest.pdb | FileCheck --check-prefix=VA %s
44
55 ; RVA: ---EXTERNALS---
None ; RUN: llvm-pdbdump -symbols -globals -types %p/Inputs/FilterTest.pdb \
0 ; RUN: llvm-pdbdump pretty -symbols -globals -types %p/Inputs/FilterTest.pdb \
11 ; RUN: | FileCheck --check-prefix=NO_FILTER %s
2 ; RUN: llvm-pdbdump -types -exclude-types="GlobalTypedef|NestedTypedef" \
2 ; RUN: llvm-pdbdump pretty -types -exclude-types="GlobalTypedef|NestedTypedef" \
33 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_TYPEDEFS %s
4 ; RUN: llvm-pdbdump -types -exclude-types="GlobalEnum|NestedEnum" \
4 ; RUN: llvm-pdbdump pretty -types -exclude-types="GlobalEnum|NestedEnum" \
55 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_ENUMS %s
6 ; RUN: llvm-pdbdump -types -symbols -globals -exclude-symbols="MemberVar|GlobalVar" \
6 ; RUN: llvm-pdbdump pretty -types -symbols -globals -exclude-symbols="MemberVar|GlobalVar" \
77 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_VARS %s
8 ; RUN: llvm-pdbdump -types -exclude-types="FilterTestClass" \
8 ; RUN: llvm-pdbdump pretty -types -exclude-types="FilterTestClass" \
99 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_WHOLE_CLASS %s
10 ; RUN: llvm-pdbdump -symbols -globals -exclude-compilands="FilterTest.obj" \
10 ; RUN: llvm-pdbdump pretty -symbols -globals -exclude-compilands="FilterTest.obj" \
1111 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_COMPILAND %s
12 ; RUN: llvm-pdbdump -types -include-types="FilterTestClass" \
12 ; RUN: llvm-pdbdump pretty -types -include-types="FilterTestClass" \
1313 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=INCLUDE_ONLY_TYPES %s
14 ; RUN: llvm-pdbdump -types -symbols -globals -include-symbols="[[:<:]](IntGlobalVar|DoubleGlobalVar)[[:>:]]" \
14 ; RUN: llvm-pdbdump pretty -types -symbols -globals -include-symbols="[[:<:]](IntGlobalVar|DoubleGlobalVar)[[:>:]]" \
1515 ; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=INCLUDE_ONLY_VARS %s
1616
1717 ; NO_FILTER: ---TYPES---
8484 auto &AccessGroup = Groups.find((int)Access)->second;
8585
8686 if (auto Func = dyn_cast(Child.get())) {
87 if (Func->isCompilerGenerated() && opts::ExcludeCompilerGenerated)
87 if (Func->isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
8888 continue;
8989 if (Func->getLength() == 0 && !Func->isPureVirtual() &&
9090 !Func->isIntroVirtualFunction())
2424 void EnumDumper::start(const PDBSymbolTypeEnum &Symbol) {
2525 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
2626 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
27 if (!opts::NoEnumDefs) {
27 if (!opts::pretty::NoEnumDefs) {
2828 auto BuiltinType = Symbol.getUnderlyingType();
2929 if (BuiltinType->getBuiltinType() != PDB_BuiltinType::Int ||
3030 BuiltinType->getLength() != 4) {
4040 LLVMOutputStyle::LLVMOutputStyle(PDBFile &File)
4141 : File(File), P(outs()), TD(&P, false) {}
4242
43 Error LLVMOutputStyle::dump() {
44 if (auto EC = dumpFileHeaders())
45 return EC;
46
47 if (auto EC = dumpStreamSummary())
48 return EC;
49
50 if (auto EC = dumpStreamBlocks())
51 return EC;
52
53 if (auto EC = dumpStreamData())
54 return EC;
55
56 if (auto EC = dumpInfoStream())
57 return EC;
58
59 if (auto EC = dumpNamedStream())
60 return EC;
61
62 if (auto EC = dumpTpiStream(StreamTPI))
63 return EC;
64
65 if (auto EC = dumpTpiStream(StreamIPI))
66 return EC;
67
68 if (auto EC = dumpDbiStream())
69 return EC;
70
71 if (auto EC = dumpSectionContribs())
72 return EC;
73
74 if (auto EC = dumpSectionMap())
75 return EC;
76
77 if (auto EC = dumpPublicsStream())
78 return EC;
79
80 if (auto EC = dumpSectionHeaders())
81 return EC;
82
83 if (auto EC = dumpFpoStream())
84 return EC;
85
86 flush();
87
88 return Error::success();
89 }
90
4391 Error LLVMOutputStyle::dumpFileHeaders() {
44 if (!opts::DumpHeaders)
92 if (!opts::raw::DumpHeaders)
4593 return Error::success();
4694
4795 DictScope D(P, "FileHeaders");
63111 }
64112
65113 Error LLVMOutputStyle::dumpStreamSummary() {
66 if (!opts::DumpStreamSummary)
114 if (!opts::raw::DumpStreamSummary)
67115 return Error::success();
68116
69117 // It's OK if we fail to load some of these streams, we still attempt to print
185233 }
186234
187235 Error LLVMOutputStyle::dumpStreamBlocks() {
188 if (!opts::DumpStreamBlocks)
236 if (!opts::raw::DumpStreamBlocks)
189237 return Error::success();
190238
191239 ListScope L(P, "StreamBlocks");
201249
202250 Error LLVMOutputStyle::dumpStreamData() {
203251 uint32_t StreamCount = File.getNumStreams();
204 StringRef DumpStreamStr = opts::DumpStreamDataIdx;
252 StringRef DumpStreamStr = opts::raw::DumpStreamDataIdx;
205253 uint32_t DumpStreamNum;
206254 if (DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum))
207255 return Error::success();
227275 }
228276
229277 Error LLVMOutputStyle::dumpInfoStream() {
230 if (!opts::DumpHeaders)
278 if (!opts::raw::DumpHeaders)
231279 return Error::success();
232280 auto IS = File.getPDBInfoStream();
233281 if (!IS)
242290 }
243291
244292 Error LLVMOutputStyle::dumpNamedStream() {
245 if (opts::DumpStreamDataName.empty())
293 if (opts::raw::DumpStreamDataName.empty())
246294 return Error::success();
247295
248296 auto IS = File.getPDBInfoStream();
249297 if (!IS)
250298 return IS.takeError();
251299
252 uint32_t NameStreamIndex = IS->getNamedStreamIndex(opts::DumpStreamDataName);
300 uint32_t NameStreamIndex =
301 IS->getNamedStreamIndex(opts::raw::DumpStreamDataName);
253302 if (NameStreamIndex == 0 || NameStreamIndex >= File.getNumStreams())
254303 return make_error(raw_error_code::no_stream);
255304
256305 if (NameStreamIndex != 0) {
257306 std::string Name("Stream '");
258 Name += opts::DumpStreamDataName;
307 Name += opts::raw::DumpStreamDataName;
259308 Name += "'";
260309 DictScope D(P, Name);
261310 P.printNumber("Index", NameStreamIndex);
289338 }
290339
291340 static void dumpTpiHash(ScopedPrinter &P, TpiStream &Tpi) {
292 if (!opts::DumpTpiHash)
341 if (!opts::raw::DumpTpiHash)
293342 return;
294343 DictScope DD(P, "Hash");
295344 P.printNumber("Number of Hash Buckets", Tpi.NumHashBuckets());
310359 StringRef Label;
311360 StringRef VerLabel;
312361 if (StreamIdx == StreamTPI) {
313 DumpRecordBytes = opts::DumpTpiRecordBytes;
314 DumpRecords = opts::DumpTpiRecords;
362 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
363 DumpRecords = opts::raw::DumpTpiRecords;
315364 Label = "Type Info Stream (TPI)";
316365 VerLabel = "TPI Version";
317366 } else if (StreamIdx == StreamIPI) {
318 DumpRecordBytes = opts::DumpIpiRecordBytes;
319 DumpRecords = opts::DumpIpiRecords;
367 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
368 DumpRecords = opts::raw::DumpIpiRecords;
320369 Label = "Type Info Stream (IPI)";
321370 VerLabel = "IPI Version";
322371 }
323 if (!DumpRecordBytes && !DumpRecords && !opts::DumpModuleSyms)
372 if (!DumpRecordBytes && !DumpRecords && !opts::raw::DumpModuleSyms)
324373 return Error::success();
325374
326375 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
352401 if (HadError)
353402 return make_error(raw_error_code::corrupt_file,
354403 "TPI stream contained corrupt record");
355 } else if (opts::DumpModuleSyms) {
404 } else if (opts::raw::DumpModuleSyms) {
356405 // Even if the user doesn't want to dump type records, we still need to
357406 // iterate them in order to build the list of types so that we can print
358407 // them when dumping module symbols. So when they want to dump symbols
377426 }
378427
379428 Error LLVMOutputStyle::dumpDbiStream() {
380 bool DumpModules = opts::DumpModules || opts::DumpModuleSyms ||
381 opts::DumpModuleFiles || opts::DumpLineInfo;
382 if (!opts::DumpHeaders && !DumpModules)
429 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
430 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
431 if (!opts::raw::DumpHeaders && !DumpModules)
383432 return Error::success();
384433
385434 auto DS = File.getPDBDbiStream();
423472 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
424473 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
425474 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
426 if (opts::DumpModuleFiles) {
475 if (opts::raw::DumpModuleFiles) {
427476 std::string FileListName =
428477 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
429478 ListScope LL(P, FileListName);
433482 bool HasModuleDI =
434483 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
435484 bool ShouldDumpSymbols =
436 (opts::DumpModuleSyms || opts::DumpSymRecordBytes);
437 if (HasModuleDI && (ShouldDumpSymbols || opts::DumpLineInfo)) {
485 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
486 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
438487 auto ModStreamData = MappedBlockStream::createIndexedStream(
439488 Modi.Info.getModuleStreamIndex(), File);
440489 if (!ModStreamData)
450499 for (const auto &S : ModS.symbols(&HadError)) {
451500 DictScope DD(P, "");
452501
453 if (opts::DumpModuleSyms)
502 if (opts::raw::DumpModuleSyms)
454503 SD.dump(S);
455 if (opts::DumpSymRecordBytes)
504 if (opts::raw::DumpSymRecordBytes)
456505 P.printBinaryBlock("Bytes", S.Data);
457506 }
458507 if (HadError)
460509 raw_error_code::corrupt_file,
461510 "DBI stream contained corrupt symbol record");
462511 }
463 if (opts::DumpLineInfo) {
512 if (opts::raw::DumpLineInfo) {
464513 ListScope SS(P, "LineInfo");
465514 bool HadError = false;
466515 // Define a locally scoped visitor to print the different
560609 }
561610
562611 Error LLVMOutputStyle::dumpSectionContribs() {
563 if (!opts::DumpSectionContribs)
612 if (!opts::raw::DumpSectionContribs)
564613 return Error::success();
565614
566615 auto Dbi = File.getPDBDbiStream();
607656 }
608657
609658 Error LLVMOutputStyle::dumpSectionMap() {
610 if (!opts::DumpSectionMap)
659 if (!opts::raw::DumpSectionMap)
611660 return Error::success();
612661
613662 auto Dbi = File.getPDBDbiStream();
632681 }
633682
634683 Error LLVMOutputStyle::dumpPublicsStream() {
635 if (!opts::DumpPublics)
684 if (!opts::raw::DumpPublics)
636685 return Error::success();
637686
638687 DictScope D(P, "Publics Stream");
660709 DictScope DD(P, "");
661710
662711 SD.dump(S);
663 if (opts::DumpSymRecordBytes)
712 if (opts::raw::DumpSymRecordBytes)
664713 P.printBinaryBlock("Bytes", S.Data);
665714 }
666715 if (HadError)
672721 }
673722
674723 Error LLVMOutputStyle::dumpSectionHeaders() {
675 if (!opts::DumpSectionHeaders)
724 if (!opts::raw::DumpSectionHeaders)
676725 return Error::success();
677726
678727 auto Dbi = File.getPDBDbiStream();
701750 }
702751
703752 Error LLVMOutputStyle::dumpFpoStream() {
704 if (!opts::DumpFpo)
753 if (!opts::raw::DumpFpo)
705754 return Error::success();
706755
707756 auto Dbi = File.getPDBDbiStream();
723772 }
724773 return Error::success();
725774 }
775
726776 void LLVMOutputStyle::flush() { P.flush(); }
2020 public:
2121 LLVMOutputStyle(PDBFile &File);
2222
23 Error dumpFileHeaders() override;
24 Error dumpStreamSummary() override;
25 Error dumpStreamBlocks() override;
26 Error dumpStreamData() override;
27 Error dumpInfoStream() override;
28 Error dumpNamedStream() override;
29 Error dumpTpiStream(uint32_t StreamIdx) override;
30 Error dumpDbiStream() override;
31 Error dumpSectionContribs() override;
32 Error dumpSectionMap() override;
33 Error dumpPublicsStream() override;
34 Error dumpSectionHeaders() override;
35 Error dumpFpoStream() override;
36
37 void flush() override;
23 Error dump() override;
3824
3925 private:
26 Error dumpFileHeaders();
27 Error dumpStreamSummary();
28 Error dumpStreamBlocks();
29 Error dumpStreamData();
30 Error dumpInfoStream();
31 Error dumpNamedStream();
32 Error dumpTpiStream(uint32_t StreamIdx);
33 Error dumpDbiStream();
34 Error dumpSectionContribs();
35 Error dumpSectionMap();
36 Error dumpPublicsStream();
37 Error dumpSectionHeaders();
38 Error dumpFpoStream();
39
40 void flush();
41
4042 PDBFile &File;
4143 ScopedPrinter P;
4244 codeview::CVTypeDumper TD;
4343
4444 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
4545 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
46 SetFilters(ExcludeTypeFilters, opts::ExcludeTypes.begin(),
47 opts::ExcludeTypes.end());
48 SetFilters(ExcludeSymbolFilters, opts::ExcludeSymbols.begin(),
49 opts::ExcludeSymbols.end());
50 SetFilters(ExcludeCompilandFilters, opts::ExcludeCompilands.begin(),
51 opts::ExcludeCompilands.end());
46 SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(),
47 opts::pretty::ExcludeTypes.end());
48 SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(),
49 opts::pretty::ExcludeSymbols.end());
50 SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(),
51 opts::pretty::ExcludeCompilands.end());
5252
53 SetFilters(IncludeTypeFilters, opts::IncludeTypes.begin(),
54 opts::IncludeTypes.end());
55 SetFilters(IncludeSymbolFilters, opts::IncludeSymbols.begin(),
56 opts::IncludeSymbols.end());
57 SetFilters(IncludeCompilandFilters, opts::IncludeCompilands.begin(),
58 opts::IncludeCompilands.end());
53 SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(),
54 opts::pretty::IncludeTypes.end());
55 SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(),
56 opts::pretty::IncludeSymbols.end());
57 SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(),
58 opts::pretty::IncludeCompilands.end());
5959 }
6060
6161 void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
1818 class OutputStyle {
1919 public:
2020 virtual ~OutputStyle() {}
21 virtual Error dumpFileHeaders() = 0;
22 virtual Error dumpStreamSummary() = 0;
23 virtual Error dumpStreamBlocks() = 0;
24 virtual Error dumpStreamData() = 0;
25 virtual Error dumpInfoStream() = 0;
26 virtual Error dumpNamedStream() = 0;
27 virtual Error dumpTpiStream(uint32_t StreamIdx) = 0;
28 virtual Error dumpDbiStream() = 0;
29 virtual Error dumpSectionContribs() = 0;
30 virtual Error dumpSectionMap() = 0;
31 virtual Error dumpPublicsStream() = 0;
32 virtual Error dumpSectionHeaders() = 0;
33 virtual Error dumpFpoStream() = 0;
3421
35 virtual void flush() = 0;
22 virtual Error dump() = 0;
3623 };
3724 }
3825 }
8787
8888 Printer.NewLine();
8989
90 if (opts::NoClassDefs) {
90 if (opts::pretty::NoClassDefs) {
9191 WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
9292 WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
9393 } else {
3232 : PDBSymDumper(true), Printer(P) {}
3333
3434 void VariableDumper::start(const PDBSymbolData &Var) {
35 if (Var.isCompilerGenerated() && opts::ExcludeCompilerGenerated)
35 if (Var.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
3636 return;
3737 if (Printer.IsSymbolExcluded(Var.getName()))
3838 return;
1111 #include "PdbYaml.h"
1212 #include "llvm-pdbdump.h"
1313
14 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
1415 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
1516
1617 using namespace llvm;
1819
1920 YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
2021
22 Error YAMLOutputStyle::dump() {
23 if (auto EC = dumpFileHeaders())
24 return EC;
25
26 if (auto EC = dumpStreamMetadata())
27 return EC;
28
29 if (auto EC = dumpStreamDirectory())
30 return EC;
31
32 flush();
33 return Error::success();
34 }
35
2136 Error YAMLOutputStyle::dumpFileHeaders() {
22 if (!opts::DumpHeaders)
23 return Error::success();
24
2537 yaml::MsfHeaders Headers;
2638 Obj.Headers.SuperBlock.NumBlocks = File.getBlockCount();
2739 Obj.Headers.SuperBlock.BlockMapAddr = File.getBlockMapIndex();
3143 Obj.Headers.DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
3244 Obj.Headers.NumDirectoryBlocks = File.getNumDirectoryBlocks();
3345 Obj.Headers.SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
34 Obj.Headers.NumStreams = File.getNumStreams();
46 Obj.Headers.NumStreams = opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
3547 Obj.Headers.SuperBlock.Unknown0 = File.getUnknown0();
3648 Obj.Headers.SuperBlock.Unknown1 = File.getUnknown1();
3749 Obj.Headers.FileSize = File.getFileSize();
3951 return Error::success();
4052 }
4153
42 Error YAMLOutputStyle::dumpStreamSummary() {
43 if (!opts::DumpStreamSummary)
54 Error YAMLOutputStyle::dumpStreamMetadata() {
55 if (!opts::pdb2yaml::StreamMetadata)
4456 return Error::success();
4557
4658 Obj.StreamSizes = File.getStreamSizes();
4759 return Error::success();
4860 }
4961
50 Error YAMLOutputStyle::dumpStreamBlocks() {
51 if (!opts::DumpStreamBlocks)
62 Error YAMLOutputStyle::dumpStreamDirectory() {
63 if (!opts::pdb2yaml::StreamDirectory)
5264 return Error::success();
5365
5466 auto StreamMap = File.getStreamMap();
6274 return Error::success();
6375 }
6476
65 Error YAMLOutputStyle::dumpStreamData() {
66 uint32_t StreamCount = File.getNumStreams();
67 StringRef DumpStreamStr = opts::DumpStreamDataIdx;
68 uint32_t DumpStreamNum;
69 if (DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) ||
70 DumpStreamNum >= StreamCount)
71 return Error::success();
72
73 return Error::success();
74 }
75
76 Error YAMLOutputStyle::dumpInfoStream() {
77 if (!opts::DumpHeaders)
78 return Error::success();
79 return Error::success();
80 }
81
82 Error YAMLOutputStyle::dumpNamedStream() {
83 if (opts::DumpStreamDataName.empty())
84 return Error::success();
85
86 return Error::success();
87 }
88
89 Error YAMLOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
90 return Error::success();
91 }
92
93 Error YAMLOutputStyle::dumpDbiStream() { return Error::success(); }
94
95 Error YAMLOutputStyle::dumpSectionContribs() {
96 if (!opts::DumpSectionContribs)
97 return Error::success();
98
99 return Error::success();
100 }
101
102 Error YAMLOutputStyle::dumpSectionMap() {
103 if (!opts::DumpSectionMap)
104 return Error::success();
105
106 return Error::success();
107 }
108
109 Error YAMLOutputStyle::dumpPublicsStream() {
110 if (!opts::DumpPublics)
111 return Error::success();
112
113 return Error::success();
114 }
115
116 Error YAMLOutputStyle::dumpSectionHeaders() {
117 if (!opts::DumpSectionHeaders)
118 return Error::success();
119
120 return Error::success();
121 }
122
123 Error YAMLOutputStyle::dumpFpoStream() {
124 if (!opts::DumpFpo)
125 return Error::success();
126
127 return Error::success();
128 }
129
13077 void YAMLOutputStyle::flush() {
13178 Out << Obj;
13279 outs().flush();
2222 public:
2323 YAMLOutputStyle(PDBFile &File);
2424
25 Error dumpFileHeaders() override;
26 Error dumpStreamSummary() override;
27 Error dumpStreamBlocks() override;
28 Error dumpStreamData() override;
29 Error dumpInfoStream() override;
30 Error dumpNamedStream() override;
31 Error dumpTpiStream(uint32_t StreamIdx) override;
32 Error dumpDbiStream() override;
33 Error dumpSectionContribs() override;
34 Error dumpSectionMap() override;
35 Error dumpPublicsStream() override;
36 Error dumpSectionHeaders() override;
37 Error dumpFpoStream() override;
38
39 void flush() override;
25 Error dump() override;
4026
4127 private:
28
29 Error dumpFileHeaders();
30 Error dumpStreamMetadata();
31 Error dumpStreamDirectory();
32
33 void flush();
34
4235 PDBFile &File;
4336 llvm::yaml::Output Out;
4437
7878
7979 namespace opts {
8080
81 enum class PDB_DumpType { ByType, ByObjFile, Both };
82
83 cl::list InputFilenames(cl::Positional,
84 cl::desc(""),
85 cl::OneOrMore);
81 cl::SubCommand RawSubcommand("raw", "Dump raw structure of the PDB file");
82 cl::SubCommand
83 PrettySubcommand("pretty",
84 "Dump semantic information about types and symbols");
85 cl::SubCommand YamlToPdbSubcommand("yaml2pdb", "Generate a PDB file from a YAML description");
86 cl::SubCommand
87 PdbToYamlSubcommand("pdb2yaml",
88 "Generate a detailed YAML description of a PDB File");
8689
8790 cl::OptionCategory TypeCategory("Symbol Type Options");
8891 cl::OptionCategory FilterCategory("Filtering Options");
8992 cl::OptionCategory OtherOptions("Other Options");
90 cl::OptionCategory NativeOptions("Native Options");
93
94 namespace pretty {
95 cl::list InputFilenames(cl::Positional,
96 cl::desc(""),
97 cl::OneOrMore, cl::sub(PrettySubcommand));
9198
9299 cl::opt Compilands("compilands", cl::desc("Display compilands"),
93 cl::cat(TypeCategory));
100 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
94101 cl::opt Symbols("symbols", cl::desc("Display symbols for each compiland"),
95 cl::cat(TypeCategory));
102 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
96103 cl::opt Globals("globals", cl::desc("Dump global symbols"),
97 cl::cat(TypeCategory));
104 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
98105 cl::opt Externals("externals", cl::desc("Dump external symbols"),
99 cl::cat(TypeCategory));
100 cl::opt Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
101 cl::opt Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory));
106 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
107 cl::opt Types("types", cl::desc("Display types"), cl::cat(TypeCategory),
108 cl::sub(PrettySubcommand));
109 cl::opt Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
110 cl::sub(PrettySubcommand));
102111 cl::opt
103112 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
104 cl::cat(TypeCategory));
113 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
105114
106115 cl::opt LoadAddress(
107116 "load-address",
108117 cl::desc("Assume the module is loaded at the specified address"),
109 cl::cat(OtherOptions));
110
111 cl::opt
112 RawOutputStyle("raw-output-style", cl::desc("Specify dump outpout style"),
113 cl::values(clEnumVal(LLVM, "LLVM default style"),
114 clEnumVal(YAML, "YAML style"), clEnumValEnd),
115 cl::init(LLVM), cl::cat(NativeOptions));
116
117 cl::opt DumpHeaders("raw-headers", cl::desc("dump PDB headers"),
118 cl::cat(NativeOptions));
119 cl::opt DumpStreamBlocks("raw-stream-blocks",
120 cl::desc("dump PDB stream blocks"),
121 cl::cat(NativeOptions));
122 cl::opt DumpStreamSummary("raw-stream-summary",
123 cl::desc("dump summary of the PDB streams"),
124 cl::cat(NativeOptions));
125 cl::opt
126 DumpTpiRecords("raw-tpi-records",
127 cl::desc("dump CodeView type records from TPI stream"),
128 cl::cat(NativeOptions));
129 cl::opt DumpTpiRecordBytes(
130 "raw-tpi-record-bytes",
131 cl::desc("dump CodeView type record raw bytes from TPI stream"),
132 cl::cat(NativeOptions));
133 cl::opt DumpTpiHash("raw-tpi-hash",
134 cl::desc("dump CodeView TPI hash stream"),
135 cl::cat(NativeOptions));
136 cl::opt
137 DumpIpiRecords("raw-ipi-records",
138 cl::desc("dump CodeView type records from IPI stream"),
139 cl::cat(NativeOptions));
140 cl::opt DumpIpiRecordBytes(
141 "raw-ipi-record-bytes",
142 cl::desc("dump CodeView type record raw bytes from IPI stream"),
143 cl::cat(NativeOptions));
144 cl::opt DumpStreamDataIdx("raw-stream",
145 cl::desc("dump stream data"),
146 cl::cat(NativeOptions));
147 cl::opt DumpStreamDataName("raw-stream-name",
148 cl::desc("dump stream data"),
149 cl::cat(NativeOptions));
150 cl::opt DumpModules("raw-modules", cl::desc("dump compiland information"),
151 cl::cat(NativeOptions));
152 cl::opt DumpModuleFiles("raw-module-files",
153 cl::desc("dump file information"),
154 cl::cat(NativeOptions));
155 cl::opt DumpModuleSyms("raw-module-syms", cl::desc("dump module symbols"),
156 cl::cat(NativeOptions));
157 cl::opt DumpPublics("raw-publics", cl::desc("dump Publics stream data"),
158 cl::cat(NativeOptions));
159 cl::opt DumpSectionContribs("raw-section-contribs",
160 cl::desc("dump section contributions"),
161 cl::cat(NativeOptions));
162 cl::opt DumpLineInfo("raw-line-info",
163 cl::desc("dump file and line information"),
164 cl::cat(NativeOptions));
165 cl::opt DumpSectionMap("raw-section-map", cl::desc("dump section map"),
166 cl::cat(NativeOptions));
167 cl::opt
168 DumpSymRecordBytes("raw-sym-record-bytes",
169 cl::desc("dump CodeView symbol record raw bytes"),
170 cl::cat(NativeOptions));
171 cl::opt DumpSectionHeaders("raw-section-headers",
172 cl::desc("dump section headers"),
173 cl::cat(NativeOptions));
174 cl::opt DumpFpo("raw-fpo", cl::desc("dump FPO records"),
175 cl::cat(NativeOptions));
176
177 cl::opt
178 RawAll("raw-all",
179 cl::desc("Implies most other options in 'Native Options' category"),
180 cl::cat(NativeOptions));
181
182 cl::opt
183 YamlToPdb("yaml-to-pdb",
184 cl::desc("The input file is yaml, and the tool outputs a pdb"),
185 cl::cat(NativeOptions));
186 cl::opt YamlPdbOutputFile(
187 "pdb-output", cl::desc("When yaml-to-pdb is specified, the output file"),
188 cl::cat(NativeOptions));
189
190 cl::list
191 ExcludeTypes("exclude-types",
192 cl::desc("Exclude types by regular expression"),
193 cl::ZeroOrMore, cl::cat(FilterCategory));
194 cl::list
195 ExcludeSymbols("exclude-symbols",
196 cl::desc("Exclude symbols by regular expression"),
197 cl::ZeroOrMore, cl::cat(FilterCategory));
198 cl::list
199 ExcludeCompilands("exclude-compilands",
200 cl::desc("Exclude compilands by regular expression"),
201 cl::ZeroOrMore, cl::cat(FilterCategory));
118 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
119 cl::list ExcludeTypes(
120 "exclude-types", cl::desc("Exclude types by regular expression"),
121 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
122 cl::list ExcludeSymbols(
123 "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
124 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
125 cl::list ExcludeCompilands(
126 "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
127 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
202128
203129 cl::list IncludeTypes(
204130 "include-types",
205131 cl::desc("Include only types which match a regular expression"),
206 cl::ZeroOrMore, cl::cat(FilterCategory));
132 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
207133 cl::list IncludeSymbols(
208134 "include-symbols",
209135 cl::desc("Include only symbols which match a regular expression"),
210 cl::ZeroOrMore, cl::cat(FilterCategory));
136 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
211137 cl::list IncludeCompilands(
212138 "include-compilands",
213139 cl::desc("Include only compilands those which match a regular expression"),
214 cl::ZeroOrMore, cl::cat(FilterCategory));
140 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
215141
216142 cl::opt ExcludeCompilerGenerated(
217143 "no-compiler-generated",
218144 cl::desc("Don't show compiler generated types and symbols"),
219 cl::cat(FilterCategory));
145 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
220146 cl::opt
221147 ExcludeSystemLibraries("no-system-libs",
222148 cl::desc("Don't show symbols from system libraries"),
223 cl::cat(FilterCategory));
149 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
224150 cl::opt NoClassDefs("no-class-definitions",
225151 cl::desc("Don't display full class definitions"),
226 cl::cat(FilterCategory));
152 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
227153 cl::opt NoEnumDefs("no-enum-definitions",
228154 cl::desc("Don't display full enum definitions"),
229 cl::cat(FilterCategory));
155 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
156 }
157
158 namespace raw {
159
160 cl::OptionCategory MsfOptions("MSF Container Options");
161 cl::OptionCategory TypeOptions("Type Record Options");
162 cl::OptionCategory FileOptions("Module & File Options");
163 cl::OptionCategory SymbolOptions("Symbol Options");
164 cl::OptionCategory MiscOptions("Miscellaneous Options");
165
166 // MSF OPTIONS
167 cl::opt DumpHeaders("headers", cl::desc("dump PDB headers"),
168 cl::cat(MsfOptions), cl::sub(RawSubcommand));
169 cl::opt DumpStreamBlocks("stream-blocks",
170 cl::desc("dump PDB stream blocks"),
171 cl::cat(MsfOptions), cl::sub(RawSubcommand));
172 cl::opt DumpStreamSummary("stream-summary",
173 cl::desc("dump summary of the PDB streams"),
174 cl::cat(MsfOptions), cl::sub(RawSubcommand));
175
176 // TYPE OPTIONS
177 cl::opt
178 DumpTpiRecords("tpi-records",
179 cl::desc("dump CodeView type records from TPI stream"),
180 cl::cat(TypeOptions), cl::sub(RawSubcommand));
181 cl::opt DumpTpiRecordBytes(
182 "tpi-record-bytes",
183 cl::desc("dump CodeView type record raw bytes from TPI stream"),
184 cl::cat(TypeOptions), cl::sub(RawSubcommand));
185 cl::opt DumpTpiHash("tpi-hash", cl::desc("dump CodeView TPI hash stream"),
186 cl::cat(TypeOptions), cl::sub(RawSubcommand));
187 cl::opt
188 DumpIpiRecords("ipi-records",
189 cl::desc("dump CodeView type records from IPI stream"),
190 cl::cat(TypeOptions), cl::sub(RawSubcommand));
191 cl::opt DumpIpiRecordBytes(
192 "ipi-record-bytes",
193 cl::desc("dump CodeView type record raw bytes from IPI stream"),
194 cl::cat(TypeOptions), cl::sub(RawSubcommand));
195
196 // MODULE & FILE OPTIONS
197 cl::opt DumpModules("modules", cl::desc("dump compiland information"),
198 cl::cat(FileOptions), cl::sub(RawSubcommand));
199 cl::opt DumpModuleFiles("module-files", cl::desc("dump file information"),
200 cl::cat(FileOptions), cl::sub(RawSubcommand));
201 cl::opt DumpLineInfo("line-info",
202 cl::desc("dump file and line information"),
203 cl::cat(FileOptions), cl::sub(RawSubcommand));
204
205 // SYMBOL OPTIONS
206 cl::opt DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
207 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
208 cl::opt DumpPublics("publics", cl::desc("dump Publics stream data"),
209 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
210 cl::opt
211 DumpSymRecordBytes("sym-record-bytes",
212 cl::desc("dump CodeView symbol record raw bytes"),
213 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
214
215 // MISCELLANEOUS OPTIONS
216 cl::opt DumpSectionContribs("section-contribs",
217 cl::desc("dump section contributions"),
218 cl::cat(MiscOptions),
219 cl::sub(RawSubcommand));
220 cl::opt DumpSectionMap("section-map", cl::desc("dump section map"),
221 cl::cat(MiscOptions), cl::sub(RawSubcommand));
222 cl::opt DumpSectionHeaders("section-headers",
223 cl::desc("dump section headers"),
224 cl::cat(MiscOptions),
225 cl::sub(RawSubcommand));
226 cl::opt DumpFpo("fpo", cl::desc("dump FPO records"),
227 cl::cat(MiscOptions), cl::sub(RawSubcommand));
228
229 cl::opt DumpStreamDataIdx("stream", cl::desc("dump stream data"),
230 cl::cat(MiscOptions),
231 cl::sub(RawSubcommand));
232 cl::opt DumpStreamDataName("stream-name",
233 cl::desc("dump stream data"),
234 cl::cat(MiscOptions),
235 cl::sub(RawSubcommand));
236
237 cl::opt
238 RawAll("all",
239 cl::desc("Implies most other options."),
240 cl::cat(MiscOptions), cl::sub(RawSubcommand));
241
242 cl::list InputFilenames(cl::Positional,
243 cl::desc(""),
244 cl::OneOrMore, cl::sub(RawSubcommand));
245 }
246
247 namespace yaml2pdb {
248 cl::opt
249 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
250 cl::sub(YamlToPdbSubcommand));
251
252 cl::list InputFilename(cl::Positional,
253 cl::desc(""), cl::Required,
254 cl::sub(YamlToPdbSubcommand));
255 }
256
257 namespace pdb2yaml {
258 cl::opt StreamMetadata("stream-metadata", cl::desc("Dump the number of streams and each stream's size"), cl::sub(PdbToYamlSubcommand));
259 cl::opt StreamDirectory("stream-directory", cl::desc("Dump each stream's block map (implies -stream-metadata)"), cl::sub(PdbToYamlSubcommand));
260
261 cl::list InputFilename(cl::Positional,
262 cl::desc(""), cl::Required,
263 cl::sub(PdbToYamlSubcommand));
264 }
230265 }
231266
232267 static ExitOnError ExitOnErr;
233
234 static Error dumpStructure(RawSession &RS) {
235 PDBFile &File = RS.getPDBFile();
236 std::unique_ptr O;
237 if (opts::RawOutputStyle == opts::OutputStyleTy::LLVM)
238 O = llvm::make_unique(File);
239 else if (opts::RawOutputStyle == opts::OutputStyleTy::YAML)
240 O = llvm::make_unique(File);
241 else
242 return make_error(raw_error_code::feature_unsupported,
243 "Requested output style unsupported");
244
245 if (auto EC = O->dumpFileHeaders())
246 return EC;
247
248 if (auto EC = O->dumpStreamSummary())
249 return EC;
250
251 if (auto EC = O->dumpStreamBlocks())
252 return EC;
253
254 if (auto EC = O->dumpStreamData())
255 return EC;
256
257 if (auto EC = O->dumpInfoStream())
258 return EC;
259
260 if (auto EC = O->dumpNamedStream())
261 return EC;
262
263 if (auto EC = O->dumpTpiStream(StreamTPI))
264 return EC;
265
266 if (auto EC = O->dumpTpiStream(StreamIPI))
267 return EC;
268
269 if (auto EC = O->dumpDbiStream())
270 return EC;
271
272 if (auto EC = O->dumpSectionContribs())
273 return EC;
274
275 if (auto EC = O->dumpSectionMap())
276 return EC;
277
278 if (auto EC = O->dumpPublicsStream())
279 return EC;
280
281 if (auto EC = O->dumpSectionHeaders())
282 return EC;
283
284 if (auto EC = O->dumpFpoStream())
285 return EC;
286 O->flush();
287 return Error::success();
288 }
289
290 bool isRawDumpEnabled() {
291 if (opts::DumpHeaders)
292 return true;
293 if (opts::DumpModules)
294 return true;
295 if (opts::DumpModuleFiles)
296 return true;
297 if (opts::DumpModuleSyms)
298 return true;
299 if (!opts::DumpStreamDataIdx.empty())
300 return true;
301 if (!opts::DumpStreamDataName.empty())
302 return true;
303 if (opts::DumpPublics)
304 return true;
305 if (opts::DumpStreamSummary)
306 return true;
307 if (opts::DumpStreamBlocks)
308 return true;
309 if (opts::DumpSymRecordBytes)
310 return true;
311 if (opts::DumpTpiRecordBytes)
312 return true;
313 if (opts::DumpTpiRecords)
314 return true;
315 if (opts::DumpTpiHash)
316 return true;
317 if (opts::DumpIpiRecords)
318 return true;
319 if (opts::DumpIpiRecordBytes)
320 return true;
321 if (opts::DumpSectionHeaders)
322 return true;
323 if (opts::DumpSectionContribs)
324 return true;
325 if (opts::DumpSectionMap)
326 return true;
327 if (opts::DumpLineInfo)
328 return true;
329 if (opts::DumpFpo)
330 return true;
331 return false;
332 }
333268
334269 static void yamlToPdb(StringRef Path) {
335270 ErrorOr> ErrorOrBuffer =
346281 pdb::yaml::PdbObject YamlObj;
347282 In >> YamlObj;
348283
349 auto OutFileOrError = FileOutputBuffer::create(opts::YamlPdbOutputFile,
350 YamlObj.Headers.FileSize);
284 auto OutFileOrError = FileOutputBuffer::create(
285 opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers.FileSize);
351286 if (OutFileOrError.getError())
352287 ExitOnErr(make_error(generic_error_code::invalid_path,
353 opts::YamlPdbOutputFile));
288 opts::yaml2pdb::YamlPdbOutputFile));
354289
355290 auto FileByteStream =
356291 llvm::make_unique(std::move(*OutFileOrError));
370305 Pdb.commit();
371306 }
372307
373 static void dumpInput(StringRef Path) {
308 static void dumpRaw(StringRef Path) {
374309 std::unique_ptr Session;
375 if (isRawDumpEnabled()) {
376 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
377
378 RawSession *RS = static_cast(Session.get());
379 ExitOnErr(dumpStructure(*RS));
380 return;
381 }
310 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
311
312 RawSession *RS = static_cast(Session.get());
313 PDBFile &File = RS->getPDBFile();
314 std::unique_ptr O;
315 if (opts::PdbToYamlSubcommand)
316 O = llvm::make_unique(File);
317 else
318 O = llvm::make_unique(File);
319
320 ExitOnErr(O->dump());
321 }
322
323 static void dumpPretty(StringRef Path) {
324 std::unique_ptr Session;
382325
383326 ExitOnErr(loadDataForPDB(PDB_ReaderType::DIA, Path, Session));
384327
385 if (opts::LoadAddress)
386 Session->setLoadAddress(opts::LoadAddress);
328 if (opts::pretty::LoadAddress)
329 Session->setLoadAddress(opts::pretty::LoadAddress);
387330
388331 LinePrinter Printer(2, outs());
389332
420363 outs() << "HasPrivateSymbols ";
421364 Printer.Unindent();
422365
423 if (opts::Compilands) {
366 if (opts::pretty::Compilands) {
424367 Printer.NewLine();
425368 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
426369 << "---COMPILANDS---";
428371 auto Compilands = GlobalScope->findAllChildren();
429372 CompilandDumper Dumper(Printer);
430373 CompilandDumpFlags options = CompilandDumper::Flags::None;
431 if (opts::Lines)
374 if (opts::pretty::Lines)
432375 options = options | CompilandDumper::Flags::Lines;
433376 while (auto Compiland = Compilands->getNext())
434377 Dumper.start(*Compiland, options);
435378 Printer.Unindent();
436379 }
437380
438 if (opts::Types) {
381 if (opts::pretty::Types) {
439382 Printer.NewLine();
440383 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
441384 Printer.Indent();
444387 Printer.Unindent();
445388 }
446389
447 if (opts::Symbols) {
390 if (opts::pretty::Symbols) {
448391 Printer.NewLine();
449392 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
450393 Printer.Indent();
455398 Printer.Unindent();
456399 }
457400
458 if (opts::Globals) {
401 if (opts::pretty::Globals) {
459402 Printer.NewLine();
460403 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
461404 Printer.Indent();
481424 }
482425 Printer.Unindent();
483426 }
484 if (opts::Externals) {
427 if (opts::pretty::Externals) {
485428 Printer.NewLine();
486429 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
487430 Printer.Indent();
488431 ExternalSymbolDumper Dumper(Printer);
489432 Dumper.start(*GlobalScope);
490433 }
491 if (opts::Lines) {
434 if (opts::pretty::Lines) {
492435 Printer.NewLine();
493436 }
494437 outs().flush();
509452 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
510453
511454 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
512 if (opts::Lines)
513 opts::Compilands = true;
514
515 if (opts::All) {
516 opts::Compilands = true;
517 opts::Symbols = true;
518 opts::Globals = true;
519 opts::Types = true;
520 opts::Externals = true;
521 opts::Lines = true;
522 }
523
524 if (opts::RawAll) {
525 opts::DumpHeaders = true;
526 opts::DumpModules = true;
527 opts::DumpModuleFiles = true;
528 opts::DumpModuleSyms = true;
529 opts::DumpPublics = true;
530 opts::DumpSectionHeaders = true;
531 opts::DumpStreamSummary = true;
532 opts::DumpStreamBlocks = true;
533 opts::DumpTpiRecords = true;
534 opts::DumpTpiHash = true;
535 opts::DumpIpiRecords = true;
536 opts::DumpSectionMap = true;
537 opts::DumpSectionContribs = true;
538 opts::DumpLineInfo = true;
539 opts::DumpFpo = true;
540 }
541
542 // When adding filters for excluded compilands and types, we need to remember
543 // that these are regexes. So special characters such as * and \ need to be
544 // escaped in the regex. In the case of a literal \, this means it needs to
545 // be escaped again in the C++. So matching a single \ in the input requires
546 // 4 \es in the C++.
547 if (opts::ExcludeCompilerGenerated) {
548 opts::ExcludeTypes.push_back("__vc_attributes");
549 opts::ExcludeCompilands.push_back("\\* Linker \\*");
550 }
551 if (opts::ExcludeSystemLibraries) {
552 opts::ExcludeCompilands.push_back(
553 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
554 opts::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
555 opts::ExcludeCompilands.push_back("d:\\\\th.obj.x86fre\\\\minkernel");
455
456 // These options are shared by two subcommands.
457 if ((opts::PdbToYamlSubcommand || opts::RawSubcommand) && opts::raw::RawAll) {
458 opts::raw::DumpHeaders = true;
459 opts::raw::DumpModules = true;
460 opts::raw::DumpModuleFiles = true;
461 opts::raw::DumpModuleSyms = true;
462 opts::raw::DumpPublics = true;
463 opts::raw::DumpSectionHeaders = true;
464 opts::raw::DumpStreamSummary = true;
465 opts::raw::DumpStreamBlocks = true;
466 opts::raw::DumpTpiRecords = true;
467 opts::raw::DumpTpiHash = true;
468 opts::raw::DumpIpiRecords = true;
469 opts::raw::DumpSectionMap = true;
470 opts::raw::DumpSectionContribs = true;
471 opts::raw::DumpLineInfo = true;
472 opts::raw::DumpFpo = true;
556473 }
557474
558475 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
559476
560 if (opts::YamlToPdb) {
561 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
562 yamlToPdb);
563 } else {
564 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
565 dumpInput);
477 if (opts::PdbToYamlSubcommand) {
478 dumpRaw(opts::pdb2yaml::InputFilename.front());
479 } else if (opts::YamlToPdbSubcommand) {
480 yamlToPdb(opts::yaml2pdb::InputFilename.front());
481 } else if (opts::PrettySubcommand) {
482 if (opts::pretty::Lines)
483 opts::pretty::Compilands = true;
484
485 if (opts::pretty::All) {
486 opts::pretty::Compilands = true;
487 opts::pretty::Symbols = true;
488 opts::pretty::Globals = true;
489 opts::pretty::Types = true;
490 opts::pretty::Externals = true;
491 opts::pretty::Lines = true;
492 }
493
494 // When adding filters for excluded compilands and types, we need to
495 // remember
496 // that these are regexes. So special characters such as * and \ need to be
497 // escaped in the regex. In the case of a literal \, this means it needs to
498 // be escaped again in the C++. So matching a single \ in the input
499 // requires
500 // 4 \es in the C++.
501 if (opts::pretty::ExcludeCompilerGenerated) {
502 opts::pretty::ExcludeTypes.push_back("__vc_attributes");
503 opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
504 }
505 if (opts::pretty::ExcludeSystemLibraries) {
506 opts::pretty::ExcludeCompilands.push_back(
507 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
508 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
509 opts::pretty::ExcludeCompilands.push_back(
510 "d:\\\\th.obj.x86fre\\\\minkernel");
511 }
512 std::for_each(opts::pretty::InputFilenames.begin(),
513 opts::pretty::InputFilenames.end(), dumpPretty);
514 } else if (opts::RawSubcommand) {
515 std::for_each(opts::raw::InputFilenames.begin(),
516 opts::raw::InputFilenames.end(), dumpRaw);
566517 }
567518
568519 outs().flush();
1414
1515 namespace opts {
1616
17 enum OutputStyleTy { LLVM, YAML };
18
17 namespace pretty {
1918 extern llvm::cl::opt Compilands;
2019 extern llvm::cl::opt Symbols;
2120 extern llvm::cl::opt Globals;
2221 extern llvm::cl::opt Types;
2322 extern llvm::cl::opt All;
23 extern llvm::cl::opt ExcludeCompilerGenerated;
2424
25 extern llvm::cl::opt<OutputStyleTy> RawOutputStyle;
25 extern llvm::cl::opt<bool> NoClassDefs;
26 extern llvm::cl::opt NoEnumDefs;
27 extern llvm::cl::list ExcludeTypes;
28 extern llvm::cl::list ExcludeSymbols;
29 extern llvm::cl::list ExcludeCompilands;
30 extern llvm::cl::list IncludeTypes;
31 extern llvm::cl::list IncludeSymbols;
32 extern llvm::cl::list IncludeCompilands;
33 }
34
35 namespace raw {
2636 extern llvm::cl::opt DumpHeaders;
2737 extern llvm::cl::opt DumpStreamBlocks;
2838 extern llvm::cl::opt DumpStreamSummary;
4353 extern llvm::cl::opt DumpSymRecordBytes;
4454 extern llvm::cl::opt DumpSectionHeaders;
4555 extern llvm::cl::opt DumpFpo;
56 }
4657
47 extern llvm::cl::opt ExcludeCompilerGenerated;
48
49 extern llvm::cl::opt NoClassDefs;
50 extern llvm::cl::opt NoEnumDefs;
51 extern llvm::cl::list ExcludeTypes;
52 extern llvm::cl::list ExcludeSymbols;
53 extern llvm::cl::list ExcludeCompilands;
54 extern llvm::cl::list IncludeTypes;
55 extern llvm::cl::list IncludeSymbols;
56 extern llvm::cl::list IncludeCompilands;
58 namespace pdb2yaml {
59 extern llvm::cl::opt StreamMetadata;
60 extern llvm::cl::opt StreamDirectory;
61 extern llvm::cl::list InputFilename;
62 }
5763 }
5864
5965 #endif