Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -411,9 +411,10 @@ static Expected getModuleDebugStream(PDBFile &File, uint32_t Index) { - ExitOnError Err("Unexpected error: "); - - auto &Dbi = Err(File.getPDBDbiStream()); + auto DbiOrErr = File.getPDBDbiStream(); + if (!DbiOrErr) + return DbiOrErr.takeError(); + auto &Dbi = *DbiOrErr; const auto &Modules = Dbi.modules(); auto Modi = Modules.getModuleDescriptor(Index); @@ -433,7 +434,7 @@ } template -static void +static Error iterateOneModule(InputFile &File, const Optional &HeaderScope, const SymbolGroup &SG, uint32_t Modi, CallbackT Callback) { if (HeaderScope) { @@ -443,57 +444,59 @@ } AutoIndent Indent(HeaderScope); - Callback(Modi, SG); + return Callback(Modi, SG); } template -static void iterateSymbolGroups(InputFile &Input, - const Optional &HeaderScope, - CallbackT Callback) { +static Error iterateSymbolGroups(InputFile &Input, + const Optional &HeaderScope, + CallbackT Callback) { AutoIndent Indent(HeaderScope); - ExitOnError Err("Unexpected error processing modules: "); - if (opts::dump::DumpModi.getNumOccurrences() > 0) { assert(opts::dump::DumpModi.getNumOccurrences() == 1); uint32_t Modi = opts::dump::DumpModi; SymbolGroup SG(&Input, Modi); - iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), SG, - Modi, Callback); - return; + return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), + SG, Modi, Callback); } uint32_t I = 0; for (const auto &SG : Input.symbol_groups()) { if (shouldDumpSymbolGroup(I, SG)) - iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), SG, I, - Callback); + if (auto Err = + iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), + SG, I, Callback)) + return Err; ++I; } + return Error::success(); } template -static void iterateModuleSubsections( +static Error iterateModuleSubsections( InputFile &File, const Optional &HeaderScope, - llvm::function_ref + llvm::function_ref Callback) { - iterateSymbolGroups(File, HeaderScope, - [&](uint32_t Modi, const SymbolGroup &SG) { - for (const auto &SS : SG.getDebugSubsections()) { - SubsectionT Subsection; + return iterateSymbolGroups( + File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { + for (const auto &SS : SG.getDebugSubsections()) { + SubsectionT Subsection; - if (SS.kind() != Subsection.kind()) - continue; + if (SS.kind() != Subsection.kind()) + continue; - BinaryStreamReader Reader(SS.getRecordData()); - if (auto EC = Subsection.initialize(Reader)) - continue; - Callback(Modi, SG, Subsection); - } - }); + BinaryStreamReader Reader(SS.getRecordData()); + if (auto Err = Subsection.initialize(Reader)) + continue; + if (auto Err = Callback(Modi, SG, Subsection)) + return Err; + } + return Error::success(); + }); } static Expected, @@ -590,13 +593,16 @@ } AutoIndent Indent(P); - ExitOnError Err("Unexpected error processing modules: "); - auto &Stream = Err(getPdb().getPDBDbiStream()); + auto StreamOrErr = getPdb().getPDBDbiStream(); + if (!StreamOrErr) + return StreamOrErr.takeError(); + auto &Stream = *StreamOrErr; const DbiModuleList &Modules = Stream.modules(); - iterateSymbolGroups( - File, PrintScope{P, 11}, [&](uint32_t Modi, const SymbolGroup &Strings) { + return iterateSymbolGroups( + File, PrintScope{P, 11}, + [&](uint32_t Modi, const SymbolGroup &Strings) -> Error { auto Desc = Modules.getModuleDescriptor(Modi); if (opts::dump::DumpSectionContribs) { std::vector Sections = getSectionNames(getPdb()); @@ -606,15 +612,22 @@ P.formatLine("debug stream: {0}, # files: {1}, has ec info: {2}", Desc.getModuleStreamIndex(), Desc.getNumberOfFiles(), Desc.hasECInfo()); - StringRef PdbFilePath = - Err(Stream.getECName(Desc.getPdbFilePathNameIndex())); - StringRef SrcFilePath = - Err(Stream.getECName(Desc.getSourceFileNameIndex())); + + auto PdbPathOrErr = Stream.getECName(Desc.getPdbFilePathNameIndex()); + if (!PdbPathOrErr) + return PdbPathOrErr.takeError(); + StringRef PdbFilePath = *PdbPathOrErr; + + auto SrcPathOrErr = Stream.getECName(Desc.getSourceFileNameIndex()); + if (!SrcPathOrErr) + return SrcPathOrErr.takeError(); + StringRef SrcFilePath = *SrcPathOrErr; + P.formatLine("pdb file ni: {0} `{1}`, src file ni: {2} `{3}`", Desc.getPdbFilePathNameIndex(), PdbFilePath, Desc.getSourceFileNameIndex(), SrcFilePath); + return Error::success(); }); - return Error::success(); } Error DumpOutputStyle::dumpModuleFiles() { @@ -630,18 +643,20 @@ return Error::success(); } - ExitOnError Err("Unexpected error processing modules: "); - - iterateSymbolGroups(File, PrintScope{P, 11}, - [this, &Err](uint32_t Modi, const SymbolGroup &Strings) { - auto &Stream = Err(getPdb().getPDBDbiStream()); + return iterateSymbolGroups( + File, PrintScope{P, 11}, + [this](uint32_t Modi, const SymbolGroup &Strings) -> Error { + auto StreamOrErr = getPdb().getPDBDbiStream(); + if (!StreamOrErr) + return StreamOrErr.takeError(); + auto &Stream = *StreamOrErr; - const DbiModuleList &Modules = Stream.modules(); - for (const auto &F : Modules.source_files(Modi)) { - Strings.formatFromFileName(P, F); - } - }); - return Error::success(); + const DbiModuleList &Modules = Stream.modules(); + for (const auto &F : Modules.source_files(Modi)) { + Strings.formatFromFileName(P, F); + } + return Error::success(); + }); } Error DumpOutputStyle::dumpSymbolStats() { @@ -652,8 +667,6 @@ return Error::success(); } - ExitOnError Err("Unexpected error processing modules: "); - StatCollection SymStats; StatCollection ChunkStats; @@ -661,30 +674,34 @@ if (File.isPdb()) Scope.emplace(P, 2); - iterateSymbolGroups(File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) { - StatCollection SS = getSymbolStats(SG, SymStats); - StatCollection CS = getChunkStats(SG, ChunkStats); - - if (SG.getFile().isPdb()) { - AutoIndent Indent(P); - auto Modules = cantFail(File.pdb().getPDBDbiStream()).modules(); - uint32_t ModCount = Modules.getModuleCount(); - DbiModuleDescriptor Desc = Modules.getModuleDescriptor(Modi); - uint32_t StreamIdx = Desc.getModuleStreamIndex(); - - if (StreamIdx == kInvalidStreamIndex) { - P.formatLine("Mod {0} (debug info not present): [{1}]", - fmt_align(Modi, AlignStyle::Right, NumDigits(ModCount)), - Desc.getModuleName()); - return; - } - P.formatLine("Stream {0}, {1} bytes", StreamIdx, - getPdb().getStreamByteSize(StreamIdx)); - - printModuleDetailStats(P, "Symbols", SS); - printModuleDetailStats(P, "Chunks", CS); - } - }); + if (Error Err = iterateSymbolGroups( + File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { + StatCollection SS = getSymbolStats(SG, SymStats); + StatCollection CS = getChunkStats(SG, ChunkStats); + + if (SG.getFile().isPdb()) { + AutoIndent Indent(P); + auto Modules = cantFail(File.pdb().getPDBDbiStream()).modules(); + uint32_t ModCount = Modules.getModuleCount(); + DbiModuleDescriptor Desc = Modules.getModuleDescriptor(Modi); + uint32_t StreamIdx = Desc.getModuleStreamIndex(); + + if (StreamIdx == kInvalidStreamIndex) { + P.formatLine( + "Mod {0} (debug info not present): [{1}]", + fmt_align(Modi, AlignStyle::Right, NumDigits(ModCount)), + Desc.getModuleName()); + return Error::success(); + } + P.formatLine("Stream {0}, {1} bytes", StreamIdx, + getPdb().getStreamByteSize(StreamIdx)); + + printModuleDetailStats(P, "Symbols", SS); + printModuleDetailStats(P, "Chunks", CS); + } + return Error::success(); + })) + return Err; if (SymStats.Totals.Count > 0) { P.printLine(" Summary |"); @@ -944,11 +961,11 @@ uint32_t LastModi = UINT32_MAX; uint32_t LastNameIndex = UINT32_MAX; - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 4}, - [this, &LastModi, &LastNameIndex](uint32_t Modi, - const SymbolGroup &Strings, - DebugLinesSubsectionRef &Lines) { + [this, &LastModi, + &LastNameIndex](uint32_t Modi, const SymbolGroup &Strings, + DebugLinesSubsectionRef &Lines) -> Error { uint16_t Segment = Lines.header()->RelocSegment; uint32_t Begin = Lines.header()->RelocOffset; uint32_t End = Begin + Lines.header()->CodeSize; @@ -970,9 +987,8 @@ P.NewLine(); typesetLinesAndColumns(P, Begin, Block); } + return Error::success(); }); - - return Error::success(); } Error DumpOutputStyle::dumpInlineeLines() { @@ -983,10 +999,10 @@ return Error::success(); } - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 2}, [this](uint32_t Modi, const SymbolGroup &Strings, - DebugInlineeLinesSubsectionRef &Lines) { + DebugInlineeLinesSubsectionRef &Lines) -> Error { P.formatLine("{0,+8} | {1,+5} | {2}", "Inlinee", "Line", "Source File"); for (const auto &Entry : Lines) { P.formatLine("{0,+8} | {1,+5} | ", Entry.Header->Inlinee, @@ -998,9 +1014,8 @@ } } P.NewLine(); + return Error::success(); }); - - return Error::success(); } Error DumpOutputStyle::dumpXmi() { @@ -1011,10 +1026,10 @@ return Error::success(); } - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 2}, [this](uint32_t Modi, const SymbolGroup &Strings, - DebugCrossModuleImportsSubsectionRef &Imports) { + DebugCrossModuleImportsSubsectionRef &Imports) -> Error { P.formatLine("{0,=32} | {1}", "Imported Module", "Type IDs"); for (const auto &Xmi : Imports) { @@ -1039,9 +1054,8 @@ typesetItemList(TIs, P.getIndentLevel() + 35, 12, " "); P.formatLine("{0,+32} | {1}", Module, Result); } + return Error::success(); }); - - return Error::success(); } Error DumpOutputStyle::dumpXme() { @@ -1052,18 +1066,17 @@ return Error::success(); } - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 2}, [this](uint32_t Modi, const SymbolGroup &Strings, - DebugCrossModuleExportsSubsectionRef &Exports) { + DebugCrossModuleExportsSubsectionRef &Exports) -> Error { P.formatLine("{0,-10} | {1}", "Local ID", "Global ID"); for (const auto &Export : Exports) { P.formatLine("{0,+10:X+} | {1}", TypeIndex(Export.Local), TypeIndex(Export.Global)); } + return Error::success(); }); - - return Error::success(); } std::string formatFrameType(object::frame_type FT) { @@ -1232,10 +1245,10 @@ } Error DumpOutputStyle::dumpStringTableFromObj() { - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 4}, [&](uint32_t Modi, const SymbolGroup &Strings, - DebugStringTableSubsectionRef &Strings2) { + DebugStringTableSubsectionRef &Strings2) -> Error { BinaryStreamRef StringTableBuffer = Strings2.getBuffer(); BinaryStreamReader Reader(StringTableBuffer); while (Reader.bytesRemaining() > 0) { @@ -1248,8 +1261,8 @@ P.formatLine("{0} | {1}", fmt_align(Offset, AlignStyle::Right, 4), Str); } + return Error::success(); }); - return Error::success(); } Error DumpOutputStyle::dumpNamedStreams() { @@ -1532,8 +1545,6 @@ AutoIndent Indent(P); - ExitOnError Err("Unexpected error processing symbols: "); - auto &Types = File.types(); SymbolVisitorCallbackPipeline Pipeline; @@ -1544,25 +1555,18 @@ Pipeline.addCallbackToPipeline(Dumper); CVSymbolVisitor Visitor(Pipeline); - std::unique_ptr SymbolError; - - iterateModuleSubsections( + return iterateModuleSubsections( File, PrintScope{P, 2}, [&](uint32_t Modi, const SymbolGroup &Strings, - DebugSymbolsSubsectionRef &Symbols) { + DebugSymbolsSubsectionRef &Symbols) -> Error { Dumper.setSymbolGroup(&Strings); for (auto Symbol : Symbols) { if (auto EC = Visitor.visitSymbolRecord(Symbol)) { - SymbolError = std::make_unique(std::move(EC)); - return; + return EC; } } + return Error::success(); }); - - if (SymbolError) - return std::move(*SymbolError); - - return Error::success(); } Error DumpOutputStyle::dumpModuleSymsForPdb() { @@ -1574,18 +1578,18 @@ } AutoIndent Indent(P); - ExitOnError Err("Unexpected error processing symbols: "); auto &Ids = File.ids(); auto &Types = File.types(); - iterateSymbolGroups( - File, PrintScope{P, 2}, [&](uint32_t I, const SymbolGroup &Strings) { + return iterateSymbolGroups( + File, PrintScope{P, 2}, + [&](uint32_t I, const SymbolGroup &Strings) -> Error { auto ExpectedModS = getModuleDebugStream(File.pdb(), I); if (!ExpectedModS) { P.formatLine("Error loading module stream {0}. {1}", I, toString(ExpectedModS.takeError())); - return; + return Error::success(); } ModuleDebugStreamRef &ModS = *ExpectedModS; @@ -1603,10 +1607,10 @@ Visitor.visitSymbolStream(ModS.getSymbolArray(), SS.Offset)) { P.formatLine("Error while processing symbol records. {0}", toString(std::move(EC))); - return; + return EC; } + return Error::success(); }); - return Error::success(); } Error DumpOutputStyle::dumpTypeRefStats() { Index: llvm/tools/llvm-pdbutil/InputFile.cpp =================================================================== --- llvm/tools/llvm-pdbutil/InputFile.cpp +++ llvm/tools/llvm-pdbutil/InputFile.cpp @@ -37,9 +37,10 @@ static Expected getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) { - ExitOnError Err("Unexpected error: "); - - auto &Dbi = Err(File.getPDBDbiStream()); + auto DbiOrErr = File.getPDBDbiStream(); + if (!DbiOrErr) + return DbiOrErr.takeError(); + auto &Dbi = *DbiOrErr; const auto &Modules = Dbi.modules(); if (Index >= Modules.getModuleCount()) return make_error(raw_error_code::index_out_of_bounds,