[DWARFYAML][debug_info] Add support for error handling.

This patch helps add support for error handling in `DWARFYAML::emitDebugInfo()`.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D82275
This commit is contained in:
Xing GUO 2020-06-22 21:35:51 +08:00
parent 3a48a632d0
commit 03480c80d3
4 changed files with 16 additions and 13 deletions

View File

@ -267,9 +267,7 @@ public:
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 @@ DWARFYAML::emitDebugSections(StringRef YAMLString, bool ApplyFixups,
if (ApplyFixups) {
DIEFixupVisitor DIFixer(DI);
DIFixer.traverseDebugInfo();
if (Error Err = DIFixer.traverseDebugInfo())
return std::move(Err);
}
StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;

View File

@ -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 @@ static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
return getOffsetSize(Unit);
}
template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
template <typename T> Error DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
for (auto &Unit : DebugInfo.CompileUnits) {
onStartCompileUnit(Unit);
if (Unit.Entries.empty())
@ -57,8 +58,8 @@ template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
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 @@ template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
}
onEndCompileUnit(Unit);
}
return Error::success();
}
// Explicitly instantiate the two template expansions.

View File

@ -16,6 +16,7 @@
#include "llvm/Support/MemoryBuffer.h"
namespace llvm {
class Error;
namespace DWARFYAML {
@ -68,7 +69,7 @@ public:
virtual ~VisitorImpl() {}
void traverseDebugInfo();
Error traverseDebugInfo();
private:
void onVariableSizeValue(uint64_t U, unsigned Size);

View File

@ -643,13 +643,13 @@ DWARF:
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: