diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -267,9 +267,7 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) { DumpVisitor Visitor(DI, OS); - Visitor.traverseDebugInfo(); - - return Error::success(); + return Visitor.traverseDebugInfo(); } static void emitFileEntry(raw_ostream &OS, const DWARFYAML::File &File) { @@ -483,7 +481,8 @@ if (ApplyFixups) { DIEFixupVisitor DIFixer(DI); - DIFixer.traverseDebugInfo(); + if (Error Err = DIFixer.traverseDebugInfo()) + return std::move(Err); } StringMap> DebugSections; diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.h b/llvm/lib/ObjectYAML/DWARFVisitor.h --- a/llvm/lib/ObjectYAML/DWARFVisitor.h +++ b/llvm/lib/ObjectYAML/DWARFVisitor.h @@ -16,6 +16,7 @@ #include "llvm/Support/MemoryBuffer.h" namespace llvm { +class Error; namespace DWARFYAML { @@ -68,7 +69,7 @@ virtual ~VisitorImpl() {} - void traverseDebugInfo(); + Error traverseDebugInfo(); private: void onVariableSizeValue(uint64_t U, unsigned Size); diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp --- a/llvm/lib/ObjectYAML/DWARFVisitor.cpp +++ b/llvm/lib/ObjectYAML/DWARFVisitor.cpp @@ -10,7 +10,8 @@ #include "DWARFVisitor.h" #include "llvm/ObjectYAML/DWARFYAML.h" -#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Errc.h" +#include "llvm/Support/Error.h" using namespace llvm; @@ -44,7 +45,7 @@ return getOffsetSize(Unit); } -template void DWARFYAML::VisitorImpl::traverseDebugInfo() { +template Error DWARFYAML::VisitorImpl::traverseDebugInfo() { for (auto &Unit : DebugInfo.CompileUnits) { onStartCompileUnit(Unit); if (Unit.Entries.empty()) @@ -57,8 +58,8 @@ continue; if (AbbrCode > DebugInfo.AbbrevDecls.size()) - // TODO: Handle and test this error. - report_fatal_error( + return createStringError( + errc::invalid_argument, "abbrev code must be less than or equal to the number of " "entries in abbreviation table"); const DWARFYAML::Abbrev &Abbrev = DebugInfo.AbbrevDecls[AbbrCode - 1]; @@ -179,6 +180,8 @@ } onEndCompileUnit(Unit); } + + return Error::success(); } // Explicitly instantiate the two template expansions. diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml @@ -643,13 +643,13 @@ Values: - Value: 0x1234 -## i) Test that yaml2obj reports a fatal error when 'debug_info' has values in its +## i) Test that yaml2obj reports an error when 'debug_info' has values in its ## entries but 'debug_abbrev' doesn't have enough attributes for them. -# RUN: not --crash yaml2obj --docnum=10 %s -o %t10.o 2>&1 | \ -# RUN: FileCheck %s --check-prefixes=FATAL +# RUN: not yaml2obj --docnum=10 %s -o %t10.o 2>&1 | \ +# RUN: FileCheck %s --check-prefixes=ERROR -# FATAL: LLVM ERROR: abbrev code must be less than or equal to the number of entries in abbreviation table +# ERROR: yaml2obj: error: abbrev code must be less than or equal to the number of entries in abbreviation table --- !ELF FileHeader: