llvm.org GIT mirror llvm / a20f3bc
[llvm-pdbdump] Dump line table information. This patch adds the -lines command line option which will dump source/line information for each compiland and source file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262962 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 4 years ago
4 changed file(s) with 93 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: llvm-pdbdump -lines %p/../Inputs/symbolformat.pdb | FileCheck --check-prefix=LINE_NUMS %s
1
2 ; LINE_NUMS: llvm\test\debuginfo\pdb\inputs\symbolformat-fpo.cpp
3 ; LINE_NUMS: Line 5, Address: [0x000011a0 - 0x000011a5] (6 bytes)
4 ; LINE_NUMS: Line 6, Address: [0x000011a6 - 0x000011a6] (1 bytes)
5 ; LINE_NUMS: llvm\test\debuginfo\pdb\inputs\symbolformat.cpp
6 ; LINE_NUMS: Line 6, Address: [0x00001060 - 0x00001066] (7 bytes)
7 ; LINE_NUMS: Line 72, Address: [0x000010d0 - 0x000010d1] (2 bytes)
8 ; LINE_NUMS: Line 73, Address: [0x000010d2 - 0x000010d5] (4 bytes)
9 ; LINE_NUMS: Line 28, Address: [0x00001170 - 0x0000117a] (11 bytes)
10 ; LINE_NUMS: Line 21, Address: [0x00001180 - 0x0000118a] (11 bytes)
11 ; LINE_NUMS: Line 20, Address: [0x00001190 - 0x0000119a] (11 bytes)
1111 #include "llvm-pdbdump.h"
1212
1313 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
1415 #include "llvm/DebugInfo/PDB/IPDBSession.h"
16 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
1517 #include "llvm/DebugInfo/PDB/PDBExtras.h"
1618 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
1719 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
4143
4244 void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol) {}
4345
44 void CompilandDumper::start(const PDBSymbolCompiland &Symbol, bool Children) {
46 void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
47 CompilandDumpFlags opts) {
4548 std::string FullName = Symbol.getName();
4649 if (Printer.IsCompilandExcluded(FullName))
4750 return;
4851
4952 Printer.NewLine();
5053 WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
51 if (!Children)
52 return;
5354
54 auto ChildrenEnum = Symbol.findAllChildren();
55 Printer.Indent();
56 while (auto Child = ChildrenEnum->getNext())
57 Child->dump(*this);
58 Printer.Unindent();
55 if (opts & Flags::Lines) {
56 const IPDBSession &Session = Symbol.getSession();
57 auto Files = Session.getSourceFilesForCompiland(Symbol);
58 Printer.Indent();
59 while (auto File = Files->getNext()) {
60 Printer.NewLine();
61 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
62
63 auto Lines = Session.findLineNumbers(Symbol, *File);
64 Printer.Indent();
65 while (auto Line = Lines->getNext()) {
66 Printer.NewLine();
67 uint32_t LineStart = Line->getLineNumber();
68 uint32_t LineEnd = Line->getLineNumberEnd();
69
70 Printer << "Line ";
71 PDB_ColorItem StatementColor = Line->isStatement()
72 ? PDB_ColorItem::Keyword
73 : PDB_ColorItem::LiteralValue;
74 WithColor(Printer, StatementColor).get() << LineStart;
75 if (LineStart != LineEnd)
76 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
77
78 Printer << ", Address: ";
79 if (Line->getLength() > 0) {
80 uint64_t AddrStart = Line->getVirtualAddress();
81 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
82 WithColor(Printer, PDB_ColorItem::Address).get()
83 << "[" << format_hex(AddrStart, 10) << " - "
84 << format_hex(AddrEnd, 10) << "]";
85 Printer << " (" << Line->getLength() << " bytes)";
86 } else {
87 uint64_t AddrStart = Line->getVirtualAddress();
88 WithColor(Printer, PDB_ColorItem::Address).get()
89 << "[" << format_hex(AddrStart, 10) << "] ";
90 Printer << "(0 bytes)";
91 }
92 }
93 Printer.Unindent();
94 }
95 Printer.Unindent();
96 }
97
98 if (opts & Flags::Children) {
99 auto ChildrenEnum = Symbol.findAllChildren();
100 Printer.Indent();
101 while (auto Child = ChildrenEnum->getNext())
102 Child->dump(*this);
103 Printer.Unindent();
104 }
59105 }
60106
61107 void CompilandDumper::dump(const PDBSymbolData &Symbol) {
1515
1616 class LinePrinter;
1717
18 typedef int CompilandDumpFlags;
1819 class CompilandDumper : public PDBSymDumper {
1920 public:
21 enum Flags { None = 0x0, Children = 0x1, Symbols = 0x2, Lines = 0x4 };
22
2023 CompilandDumper(LinePrinter &P);
2124
22 void start(const PDBSymbolCompiland &Symbol, bool Children);
25 void start(const PDBSymbolCompiland &Symbol, CompilandDumpFlags flags);
2326
2427 void dump(const PDBSymbolCompilandDetails &Symbol) override;
2528 void dump(const PDBSymbolCompilandEnv &Symbol) override;
7575 cl::opt Externals("externals", cl::desc("Dump external symbols"),
7676 cl::cat(TypeCategory));
7777 cl::opt Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
78 cl::opt Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory));
7879 cl::opt
7980 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
8081 cl::cat(TypeCategory));
683684 Printer.Indent();
684685 auto Compilands = GlobalScope->findAllChildren();
685686 CompilandDumper Dumper(Printer);
687 CompilandDumpFlags options = CompilandDumper::Flags::None;
688 if (opts::Lines)
689 options = options | CompilandDumper::Flags::Lines;
686690 while (auto Compiland = Compilands->getNext())
687 Dumper.start(*Compiland, false);
691 Dumper.start(*Compiland, options);
688692 Printer.Unindent();
689693 }
690694
741745 ExternalSymbolDumper Dumper(Printer);
742746 Dumper.start(*GlobalScope);
743747 }
748 if (opts::Lines) {
749 Printer.NewLine();
750 }
744751 outs().flush();
745752 }
746753
761768 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
762769
763770 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
771 if (opts::Lines)
772 opts::Compilands = true;
773
764774 if (opts::All) {
765775 opts::Compilands = true;
766776 opts::Symbols = true;
767777 opts::Globals = true;
768778 opts::Types = true;
769779 opts::Externals = true;
770 }
780 opts::Lines = true;
781 }
782
783 // When adding filters for excluded compilands and types, we need to remember
784 // that these are regexes. So special characters such as * and \ need to be
785 // escaped in the regex. In the case of a literal \, this means it needs to
786 // be escaped again in the C++. So matching a single \ in the input requires
787 // 4 \es in the C++.
771788 if (opts::ExcludeCompilerGenerated) {
772789 opts::ExcludeTypes.push_back("__vc_attributes");
773 opts::ExcludeCompilands.push_back("* Linker *");
790 opts::ExcludeCompilands.push_back("\\* Linker \\*");
774791 }
775792 if (opts::ExcludeSystemLibraries) {
776793 opts::ExcludeCompilands.push_back(
777 "f:\\binaries\\Intermediate\\vctools\\crt_bld");
794 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
795 opts::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
796 opts::ExcludeCompilands.push_back("d:\\\\th.obj.x86fre\\\\minkernel");
778797 }
779798
780799 #if defined(HAVE_DIA_SDK)