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 @@ -13,6 +13,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" namespace llvm { @@ -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,9 +58,9 @@ continue; if (AbbrCode > DebugInfo.AbbrevDecls.size()) - // TODO: Report and test this error. - report_fatal_error("abbrev code must be less than the number of " - "entries in abbreviation table"); + return createStringError(errc::invalid_argument, + "abbrev code must be less than the number of " + "entries in abbreviation table"); const DWARFYAML::Abbrev &Abbrev = DebugInfo.AbbrevDecls[AbbrCode - 1]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); @@ -178,6 +179,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 @@ -646,10 +646,10 @@ ## i) Test that yaml2obj reports a fatal 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 the number of entries in abbreviation table +# ERROR: yaml2obj: error: abbrev code must be less than the number of entries in abbreviation table --- !ELF FileHeader: