summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
diff options
context:
space:
mode:
authorAaron Smith <aaron.smith@microsoft.com>2018-03-07 02:23:08 +0000
committerAaron Smith <aaron.smith@microsoft.com>2018-03-07 02:23:08 +0000
commita27b5e93a3448059b79268caca36029a7f9b1343 (patch)
tree07fe66781ad9bc088fcdc25e91bc3883ec6246e4 /llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
parentbbf648253d096b4e25f588583df8ed8e764a28bb (diff)
downloadbcm5719-llvm-a27b5e93a3448059b79268caca36029a7f9b1343.tar.gz
bcm5719-llvm-a27b5e93a3448059b79268caca36029a7f9b1343.zip
[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
Diffstat (limited to 'llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp')
-rw-r--r--llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp102
1 files changed, 55 insertions, 47 deletions
diff --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index 089f7256536..a2a97596dc9 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -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();
}
OpenPOWER on IntegriCloud