llvm.org GIT mirror llvm / 71e93df
[llvm-pdbdump] Add guard for null pointers and remove unused code Summary: This avoids crashing when a user tries to dump a pdb with the `-native` option. Reviewers: zturner, llvm-commits, rnk Reviewed By: zturner Subscribers: mgrang Differential Revision: https://reviews.llvm.org/D44117 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326863 91177308-0d34-0410-b5e6-96231b3b80d8 Aaron Smith 1 year, 8 months ago
4 changed file(s) with 108 addition(s) and 95 deletion(s). Raw diff Collapse all Expand all
5454
5555 if (opts & Flags::Lines) {
5656 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);
57 if (auto Files = Session.getSourceFilesForCompiland(Symbol)) {
6458 Printer.Indent();
65 while (auto Line = Lines->getNext()) {
59 while (auto File = Files->getNext()) {
6660 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 uint32_t ColumnStart = Line->getColumnNumber();
79 uint32_t ColumnEnd = Line->getColumnNumberEnd();
80 if (ColumnStart != 0 || ColumnEnd != 0) {
81 Printer << ", Column: ";
82 WithColor(Printer, StatementColor).get() << ColumnStart;
83 if (ColumnEnd != ColumnStart)
84 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
85 }
86
87 Printer << ", Address: ";
88 if (Line->getLength() > 0) {
89 uint64_t AddrStart = Line->getVirtualAddress();
90 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
91 WithColor(Printer, PDB_ColorItem::Address).get()
61 WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
62
63 auto Lines = Session.findLineNumbers(Symbol, *File);
64 if (!Lines)
65 continue;
66
67 Printer.Indent();
68 while (auto Line = Lines->getNext()) {
69 Printer.NewLine();
70 uint32_t LineStart = Line->getLineNumber();
71 uint32_t LineEnd = Line->getLineNumberEnd();
72
73 Printer << "Line ";
74 PDB_ColorItem StatementColor = Line->isStatement()
75 ? PDB_ColorItem::Keyword
76 : PDB_ColorItem::LiteralValue;
77 WithColor(Printer, StatementColor).get() << LineStart;
78 if (LineStart != LineEnd)
79 WithColor(Printer, StatementColor).get() << " - " << LineEnd;
80
81 uint32_t ColumnStart = Line->getColumnNumber();
82 uint32_t ColumnEnd = Line->getColumnNumberEnd();
83 if (ColumnStart != 0 || ColumnEnd != 0) {
84 Printer << ", Column: ";
85 WithColor(Printer, StatementColor).get() << ColumnStart;
86 if (ColumnEnd != ColumnStart)
87 WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
88 }
89
90 Printer << ", Address: ";
91 if (Line->getLength() > 0) {
92 uint64_t AddrStart = Line->getVirtualAddress();
93 uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
94 WithColor(Printer, PDB_ColorItem::Address).get()
9295 << "[" << format_hex(AddrStart, 10) << " - "
9396 << format_hex(AddrEnd, 10) << "]";
94 Printer << " (" << Line->getLength() << " bytes)";
95 } else {
96 uint64_t AddrStart = Line->getVirtualAddress();
97 WithColor(Printer, PDB_ColorItem::Address).get()
97 Printer << " (" << Line->getLength() << " bytes)";
98 } else {
99 uint64_t AddrStart = Line->getVirtualAddress();
100 WithColor(Printer, PDB_ColorItem::Address).get()
98101 << "[" << format_hex(AddrStart, 10) << "] ";
99 Printer << "(0 bytes)";
102 Printer << "(0 bytes)";
103 }
100104 }
105 Printer.Unindent();
101106 }
102107 Printer.Unindent();
103108 }
104 Printer.Unindent();
105109 }
106110
107111 if (opts & Flags::Children) {
108 auto ChildrenEnum = Symbol.findAllChildren();
109 Printer.Indent();
110 while (auto Child = ChildrenEnum->getNext())
111 Child->dump(*this);
112 Printer.Unindent();
112 if (auto ChildrenEnum = Symbol.findAllChildren()) {
113 Printer.Indent();
114 while (auto Child = ChildrenEnum->getNext())
115 Child->dump(*this);
116 Printer.Unindent();
117 }
113118 }
114119 }
115120
2020 : PDBSymDumper(true), Printer(P) {}
2121
2222 void ExternalSymbolDumper::start(const PDBSymbolExe &Symbol) {
23 auto Vars = Symbol.findAllChildren();
24 while (auto Var = Vars->getNext())
25 Var->dump(*this);
23 if (auto Vars = Symbol.findAllChildren()) {
24 while (auto Var = Vars->getNext())
25 Var->dump(*this);
26 }
2627 }
2728
2829 void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) {
134134 TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
135135
136136 void TypeDumper::start(const PDBSymbolExe &Exe) {
137 auto Children = Exe.findAllChildren();
138137 if (opts::pretty::Enums) {
139138 if (auto Enums = Exe.findAllChildren()) {
140139 Printer.NewLine();
856856 LinePrinter Printer(2, UseColor, Stream);
857857
858858 auto GlobalScope(Session->getGlobalScope());
859 if (!GlobalScope)
860 return;
859861 std::string FileName(GlobalScope->getSymbolsFileName());
860862
861863 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
892894 Printer.NewLine();
893895 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
894896 << "---COMPILANDS---";
895 Printer.Indent();
896 auto Compilands = GlobalScope->findAllChildren();
897 CompilandDumper Dumper(Printer);
898 CompilandDumpFlags options = CompilandDumper::Flags::None;
899 if (opts::pretty::Lines)
900 options = options | CompilandDumper::Flags::Lines;
901 while (auto Compiland = Compilands->getNext())
902 Dumper.start(*Compiland, options);
903 Printer.Unindent();
897 if (auto Compilands = GlobalScope->findAllChildren()) {
898 Printer.Indent();
899 CompilandDumper Dumper(Printer);
900 CompilandDumpFlags options = CompilandDumper::Flags::None;
901 if (opts::pretty::Lines)
902 options = options | CompilandDumper::Flags::Lines;
903 while (auto Compiland = Compilands->getNext())
904 Dumper.start(*Compiland, options);
905 Printer.Unindent();
906 }
904907 }
905908
906909 if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs) {
915918 if (opts::pretty::Symbols) {
916919 Printer.NewLine();
917920 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
918 Printer.Indent();
919 auto Compilands = GlobalScope->findAllChildren();
920 CompilandDumper Dumper(Printer);
921 while (auto Compiland = Compilands->getNext())
922 Dumper.start(*Compiland, true);
923 Printer.Unindent();
921 if (auto Compilands = GlobalScope->findAllChildren()) {
922 Printer.Indent();
923 CompilandDumper Dumper(Printer);
924 while (auto Compiland = Compilands->getNext())
925 Dumper.start(*Compiland, true);
926 Printer.Unindent();
927 }
924928 }
925929
926930 if (opts::pretty::Globals) {
928932 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
929933 Printer.Indent();
930934 if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
931 FunctionDumper Dumper(Printer);
932 auto Functions = GlobalScope->findAllChildren();
933 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
934 while (auto Function = Functions->getNext()) {
935 Printer.NewLine();
936 Dumper.start(*Function, FunctionDumper::PointerType::None);
937 }
938 } else {
939 std::vector> Funcs;
940 while (auto Func = Functions->getNext())
941 Funcs.push_back(std::move(Func));
942 std::sort(Funcs.begin(), Funcs.end(),
943 opts::pretty::compareFunctionSymbols);
944 for (const auto &Func : Funcs) {
945 Printer.NewLine();
946 Dumper.start(*Func, FunctionDumper::PointerType::None);
935 if (auto Functions = GlobalScope->findAllChildren()) {
936 FunctionDumper Dumper(Printer);
937 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
938 while (auto Function = Functions->getNext()) {
939 Printer.NewLine();
940 Dumper.start(*Function, FunctionDumper::PointerType::None);
941 }
942 } else {
943 std::vector> Funcs;
944 while (auto Func = Functions->getNext())
945 Funcs.push_back(std::move(Func));
946 std::sort(Funcs.begin(), Funcs.end(),
947 opts::pretty::compareFunctionSymbols);
948 for (const auto &Func : Funcs) {
949 Printer.NewLine();
950 Dumper.start(*Func, FunctionDumper::PointerType::None);
951 }
947952 }
948953 }
949954 }
950955 if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
951 auto Vars = GlobalScope->findAllChildren();
952 VariableDumper Dumper(Printer);
953 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
954 while (auto Var = Vars->getNext())
955 Dumper.start(*Var);
956 } else {
957 std::vector> Datas;
958 while (auto Var = Vars->getNext())
959 Datas.push_back(std::move(Var));
960 std::sort(Datas.begin(), Datas.end(), opts::pretty::compareDataSymbols);
961 for (const auto &Var : Datas)
962 Dumper.start(*Var);
956 if (auto Vars = GlobalScope->findAllChildren()) {
957 VariableDumper Dumper(Printer);
958 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
959 while (auto Var = Vars->getNext())
960 Dumper.start(*Var);
961 } else {
962 std::vector> Datas;
963 while (auto Var = Vars->getNext())
964 Datas.push_back(std::move(Var));
965 std::sort(Datas.begin(), Datas.end(),
966 opts::pretty::compareDataSymbols);
967 for (const auto &Var : Datas)
968 Dumper.start(*Var);
969 }
963970 }
964971 }
965972 if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
966 auto Thunks = GlobalScope->findAllChildren();
967 CompilandDumper Dumper(Printer);
968 while (auto Thunk = Thunks->getNext())
969 Dumper.dump(*Thunk);
973 if (auto Thunks = GlobalScope->findAllChildren()) {
974 CompilandDumper Dumper(Printer);
975 while (auto Thunk = Thunks->getNext())
976 Dumper.dump(*Thunk);
977 }
970978 }
971979 Printer.Unindent();
972980 }