Index: llvm/trunk/tools/llvm-pdbutil/PrettyCompilandDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbutil/PrettyCompilandDumper.cpp +++ llvm/trunk/tools/llvm-pdbutil/PrettyCompilandDumper.cpp @@ -55,62 +55,67 @@ 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(); - - 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; - } + WithColor(Printer, PDB_ColorItem::Path).get() << File->getFileName(); - Printer << ", Address: "; - if (Line->getLength() > 0) { - uint64_t AddrStart = Line->getVirtualAddress(); - uint64_t AddrEnd = AddrStart + Line->getLength() - 1; - WithColor(Printer, PDB_ColorItem::Address).get() + auto Lines = Session.findLineNumbers(Symbol, *File); + if (!Lines) + continue; + + Printer.Indent(); + while (auto Line = Lines->getNext()) { + Printer.NewLine(); + uint32_t LineStart = Line->getLineNumber(); + uint32_t LineEnd = Line->getLineNumberEnd(); + + 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(); + } } } Index: llvm/trunk/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp +++ llvm/trunk/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp @@ -21,9 +21,10 @@ : PDBSymDumper(true), Printer(P) {} void ExternalSymbolDumper::start(const PDBSymbolExe &Symbol) { - auto Vars = Symbol.findAllChildren(); - while (auto Var = Vars->getNext()) - Var->dump(*this); + if (auto Vars = Symbol.findAllChildren()) { + while (auto Var = Vars->getNext()) + Var->dump(*this); + } } void ExternalSymbolDumper::dump(const PDBSymbolPublicSymbol &Symbol) { Index: llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp +++ llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp @@ -135,7 +135,6 @@ 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()) { Printer.NewLine(); Index: llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -857,6 +857,8 @@ 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 @@ Printer.NewLine(); WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---COMPILANDS---"; - Printer.Indent(); - auto Compilands = GlobalScope->findAllChildren(); - 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()) { + 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 @@ if (opts::pretty::Symbols) { Printer.NewLine(); WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---"; - Printer.Indent(); - auto Compilands = GlobalScope->findAllChildren(); - CompilandDumper Dumper(Printer); - while (auto Compiland = Compilands->getNext()) - Dumper.start(*Compiland, true); - Printer.Unindent(); + if (auto Compilands = GlobalScope->findAllChildren()) { + Printer.Indent(); + CompilandDumper Dumper(Printer); + while (auto Compiland = Compilands->getNext()) + Dumper.start(*Compiland, true); + Printer.Unindent(); + } } if (opts::pretty::Globals) { @@ -929,45 +933,49 @@ WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---"; Printer.Indent(); if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) { - FunctionDumper Dumper(Printer); - auto Functions = GlobalScope->findAllChildren(); - if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) { - while (auto Function = Functions->getNext()) { - Printer.NewLine(); - Dumper.start(*Function, FunctionDumper::PointerType::None); - } - } else { - std::vector> 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()) { + 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> 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(); - VariableDumper Dumper(Printer); - if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) { - while (auto Var = Vars->getNext()) - Dumper.start(*Var); - } else { - std::vector> 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()) { + VariableDumper Dumper(Printer); + if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) { + while (auto Var = Vars->getNext()) + Dumper.start(*Var); + } else { + std::vector> 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(); - CompilandDumper Dumper(Printer); - while (auto Thunk = Thunks->getNext()) - Dumper.dump(*Thunk); + if (auto Thunks = GlobalScope->findAllChildren()) { + CompilandDumper Dumper(Printer); + while (auto Thunk = Thunks->getNext()) + Dumper.dump(*Thunk); + } } Printer.Unindent(); }