mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:39:47 +00:00
[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 llvm-svn: 326863
This commit is contained in:
parent
700479379c
commit
b47bc6778f
@ -55,62 +55,67 @@ void CompilandDumper::start(const PDBSymbolCompiland &Symbol,
|
||||
|
||||
if (opts & Flags::Lines) {
|
||||
const IPDBSession &Session = Symbol.getSession();
|
||||
auto Files = Session.getSourceFilesForCompiland(Symbol);
|
||||
Printer.Indent();
|
||||
while (auto File = Files->getNext()) {
|
||||
Printer.NewLine();
|
||||
WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
|
||||
|
||||
auto Lines = Session.findLineNumbers(Symbol, *File);
|
||||
if (auto Files = Session.getSourceFilesForCompiland(Symbol)) {
|
||||
Printer.Indent();
|
||||
while (auto Line = Lines->getNext()) {
|
||||
while (auto File = Files->getNext()) {
|
||||
Printer.NewLine();
|
||||
uint32_t LineStart = Line->getLineNumber();
|
||||
uint32_t LineEnd = Line->getLineNumberEnd();
|
||||
WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName();
|
||||
|
||||
Printer << "Line ";
|
||||
PDB_ColorItem StatementColor = Line->isStatement()
|
||||
? PDB_ColorItem::Keyword
|
||||
: PDB_ColorItem::LiteralValue;
|
||||
WithColor(Printer, StatementColor).get() << LineStart;
|
||||
if (LineStart != LineEnd)
|
||||
WithColor(Printer, StatementColor).get() << " - " << LineEnd;
|
||||
auto Lines = Session.findLineNumbers(Symbol, *File);
|
||||
if (!Lines)
|
||||
continue;
|
||||
|
||||
uint32_t ColumnStart = Line->getColumnNumber();
|
||||
uint32_t ColumnEnd = Line->getColumnNumberEnd();
|
||||
if (ColumnStart != 0 || ColumnEnd != 0) {
|
||||
Printer << ", Column: ";
|
||||
WithColor(Printer, StatementColor).get() << ColumnStart;
|
||||
if (ColumnEnd != ColumnStart)
|
||||
WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
|
||||
}
|
||||
Printer.Indent();
|
||||
while (auto Line = Lines->getNext()) {
|
||||
Printer.NewLine();
|
||||
uint32_t LineStart = Line->getLineNumber();
|
||||
uint32_t LineEnd = Line->getLineNumberEnd();
|
||||
|
||||
Printer << ", Address: ";
|
||||
if (Line->getLength() > 0) {
|
||||
uint64_t AddrStart = Line->getVirtualAddress();
|
||||
uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
|
||||
WithColor(Printer, PDB_ColorItem::Address).get()
|
||||
Printer << "Line ";
|
||||
PDB_ColorItem StatementColor = Line->isStatement()
|
||||
? PDB_ColorItem::Keyword
|
||||
: PDB_ColorItem::LiteralValue;
|
||||
WithColor(Printer, StatementColor).get() << LineStart;
|
||||
if (LineStart != LineEnd)
|
||||
WithColor(Printer, StatementColor).get() << " - " << LineEnd;
|
||||
|
||||
uint32_t ColumnStart = Line->getColumnNumber();
|
||||
uint32_t ColumnEnd = Line->getColumnNumberEnd();
|
||||
if (ColumnStart != 0 || ColumnEnd != 0) {
|
||||
Printer << ", Column: ";
|
||||
WithColor(Printer, StatementColor).get() << ColumnStart;
|
||||
if (ColumnEnd != ColumnStart)
|
||||
WithColor(Printer, StatementColor).get() << " - " << ColumnEnd;
|
||||
}
|
||||
|
||||
Printer << ", Address: ";
|
||||
if (Line->getLength() > 0) {
|
||||
uint64_t AddrStart = Line->getVirtualAddress();
|
||||
uint64_t AddrEnd = AddrStart + Line->getLength() - 1;
|
||||
WithColor(Printer, PDB_ColorItem::Address).get()
|
||||
<< "[" << format_hex(AddrStart, 10) << " - "
|
||||
<< format_hex(AddrEnd, 10) << "]";
|
||||
Printer << " (" << Line->getLength() << " bytes)";
|
||||
} else {
|
||||
uint64_t AddrStart = Line->getVirtualAddress();
|
||||
WithColor(Printer, PDB_ColorItem::Address).get()
|
||||
Printer << " (" << Line->getLength() << " bytes)";
|
||||
} else {
|
||||
uint64_t AddrStart = Line->getVirtualAddress();
|
||||
WithColor(Printer, PDB_ColorItem::Address).get()
|
||||
<< "[" << format_hex(AddrStart, 10) << "] ";
|
||||
Printer << "(0 bytes)";
|
||||
Printer << "(0 bytes)";
|
||||
}
|
||||
}
|
||||
Printer.Unindent();
|
||||
}
|
||||
Printer.Unindent();
|
||||
}
|
||||
Printer.Unindent();
|
||||
}
|
||||
|
||||
if (opts & Flags::Children) {
|
||||
auto ChildrenEnum = Symbol.findAllChildren();
|
||||
Printer.Indent();
|
||||
while (auto Child = ChildrenEnum->getNext())
|
||||
Child->dump(*this);
|
||||
Printer.Unindent();
|
||||
if (auto ChildrenEnum = Symbol.findAllChildren()) {
|
||||
Printer.Indent();
|
||||
while (auto Child = ChildrenEnum->getNext())
|
||||
Child->dump(*this);
|
||||
Printer.Unindent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,10 @@ ExternalSymbolDumper::ExternalSymbolDumper(LinePrinter &P)
|
||||
: PDBSymDumper(true), Printer(P) {}
|
||||
|
||||
void ExternalSymbolDumper::start(const PDBSymbolExe &Symbol) {
|
||||
auto Vars = Symbol.findAllChildren<PDBSymbolPublicSymbol>();
|
||||
while (auto Var = Vars->getNext())
|
||||
Var->dump(*this);
|
||||
if (auto Vars = Symbol.findAllChildren<PDBSymbolPublicSymbol>()) {
|
||||
while (auto Var = Vars->getNext())
|
||||
Var->dump(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) {
|
||||
|
@ -135,7 +135,6 @@ filterAndSortClassDefs(LinePrinter &Printer, Enumerator &E,
|
||||
TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
|
||||
|
||||
void TypeDumper::start(const PDBSymbolExe &Exe) {
|
||||
auto Children = Exe.findAllChildren();
|
||||
if (opts::pretty::Enums) {
|
||||
if (auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>()) {
|
||||
Printer.NewLine();
|
||||
|
@ -857,6 +857,8 @@ static void dumpPretty(StringRef Path) {
|
||||
LinePrinter Printer(2, UseColor, Stream);
|
||||
|
||||
auto GlobalScope(Session->getGlobalScope());
|
||||
if (!GlobalScope)
|
||||
return;
|
||||
std::string FileName(GlobalScope->getSymbolsFileName());
|
||||
|
||||
WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
|
||||
@ -893,15 +895,16 @@ static void dumpPretty(StringRef Path) {
|
||||
Printer.NewLine();
|
||||
WithColor(Printer, PDB_ColorItem::SectionHeader).get()
|
||||
<< "---COMPILANDS---";
|
||||
Printer.Indent();
|
||||
auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
|
||||
CompilandDumper Dumper(Printer);
|
||||
CompilandDumpFlags options = CompilandDumper::Flags::None;
|
||||
if (opts::pretty::Lines)
|
||||
options = options | CompilandDumper::Flags::Lines;
|
||||
while (auto Compiland = Compilands->getNext())
|
||||
Dumper.start(*Compiland, options);
|
||||
Printer.Unindent();
|
||||
if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
|
||||
Printer.Indent();
|
||||
CompilandDumper Dumper(Printer);
|
||||
CompilandDumpFlags options = CompilandDumper::Flags::None;
|
||||
if (opts::pretty::Lines)
|
||||
options = options | CompilandDumper::Flags::Lines;
|
||||
while (auto Compiland = Compilands->getNext())
|
||||
Dumper.start(*Compiland, options);
|
||||
Printer.Unindent();
|
||||
}
|
||||
}
|
||||
|
||||
if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs) {
|
||||
@ -916,12 +919,13 @@ static void dumpPretty(StringRef Path) {
|
||||
if (opts::pretty::Symbols) {
|
||||
Printer.NewLine();
|
||||
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
|
||||
Printer.Indent();
|
||||
auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
|
||||
CompilandDumper Dumper(Printer);
|
||||
while (auto Compiland = Compilands->getNext())
|
||||
Dumper.start(*Compiland, true);
|
||||
Printer.Unindent();
|
||||
if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
|
||||
Printer.Indent();
|
||||
CompilandDumper Dumper(Printer);
|
||||
while (auto Compiland = Compilands->getNext())
|
||||
Dumper.start(*Compiland, true);
|
||||
Printer.Unindent();
|
||||
}
|
||||
}
|
||||
|
||||
if (opts::pretty::Globals) {
|
||||
@ -929,45 +933,49 @@ static void dumpPretty(StringRef Path) {
|
||||
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
|
||||
Printer.Indent();
|
||||
if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
|
||||
FunctionDumper Dumper(Printer);
|
||||
auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
|
||||
if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
|
||||
while (auto Function = Functions->getNext()) {
|
||||
Printer.NewLine();
|
||||
Dumper.start(*Function, FunctionDumper::PointerType::None);
|
||||
}
|
||||
} else {
|
||||
std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
|
||||
while (auto Func = Functions->getNext())
|
||||
Funcs.push_back(std::move(Func));
|
||||
std::sort(Funcs.begin(), Funcs.end(),
|
||||
opts::pretty::compareFunctionSymbols);
|
||||
for (const auto &Func : Funcs) {
|
||||
Printer.NewLine();
|
||||
Dumper.start(*Func, FunctionDumper::PointerType::None);
|
||||
if (auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>()) {
|
||||
FunctionDumper Dumper(Printer);
|
||||
if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
|
||||
while (auto Function = Functions->getNext()) {
|
||||
Printer.NewLine();
|
||||
Dumper.start(*Function, FunctionDumper::PointerType::None);
|
||||
}
|
||||
} else {
|
||||
std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
|
||||
while (auto Func = Functions->getNext())
|
||||
Funcs.push_back(std::move(Func));
|
||||
std::sort(Funcs.begin(), Funcs.end(),
|
||||
opts::pretty::compareFunctionSymbols);
|
||||
for (const auto &Func : Funcs) {
|
||||
Printer.NewLine();
|
||||
Dumper.start(*Func, FunctionDumper::PointerType::None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
|
||||
auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
|
||||
VariableDumper Dumper(Printer);
|
||||
if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
|
||||
while (auto Var = Vars->getNext())
|
||||
Dumper.start(*Var);
|
||||
} else {
|
||||
std::vector<std::unique_ptr<PDBSymbolData>> Datas;
|
||||
while (auto Var = Vars->getNext())
|
||||
Datas.push_back(std::move(Var));
|
||||
std::sort(Datas.begin(), Datas.end(), opts::pretty::compareDataSymbols);
|
||||
for (const auto &Var : Datas)
|
||||
Dumper.start(*Var);
|
||||
if (auto Vars = GlobalScope->findAllChildren<PDBSymbolData>()) {
|
||||
VariableDumper Dumper(Printer);
|
||||
if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
|
||||
while (auto Var = Vars->getNext())
|
||||
Dumper.start(*Var);
|
||||
} else {
|
||||
std::vector<std::unique_ptr<PDBSymbolData>> Datas;
|
||||
while (auto Var = Vars->getNext())
|
||||
Datas.push_back(std::move(Var));
|
||||
std::sort(Datas.begin(), Datas.end(),
|
||||
opts::pretty::compareDataSymbols);
|
||||
for (const auto &Var : Datas)
|
||||
Dumper.start(*Var);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
|
||||
auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
|
||||
CompilandDumper Dumper(Printer);
|
||||
while (auto Thunk = Thunks->getNext())
|
||||
Dumper.dump(*Thunk);
|
||||
if (auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>()) {
|
||||
CompilandDumper Dumper(Printer);
|
||||
while (auto Thunk = Thunks->getNext())
|
||||
Dumper.dump(*Thunk);
|
||||
}
|
||||
}
|
||||
Printer.Unindent();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user