[llvm] 03480c8 - [DWARFYAML][debug_info] Add support for error handling.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 06:32:16 PDT 2020
Author: Xing GUO
Date: 2020-06-22T21:36:13+08:00
New Revision: 03480c80d3a00765c92e8b2a9eab69af642ed274
URL: https://github.com/llvm/llvm-project/commit/03480c80d3a00765c92e8b2a9eab69af642ed274
DIFF: https://github.com/llvm/llvm-project/commit/03480c80d3a00765c92e8b2a9eab69af642ed274.diff
LOG: [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
Added:
Modified:
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFVisitor.cpp
llvm/lib/ObjectYAML/DWARFVisitor.h
llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
Removed:
################################################################################
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 6c60f0423c00..f1b46d7b3f87 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -267,9 +267,7 @@ class DumpVisitor : public DWARFYAML::ConstVisitor {
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;
diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.cpp b/llvm/lib/ObjectYAML/DWARFVisitor.cpp
index 99edb57153f4..5c07b6aa956a 100644
--- 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 @@ 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.
diff --git a/llvm/lib/ObjectYAML/DWARFVisitor.h b/llvm/lib/ObjectYAML/DWARFVisitor.h
index 50e88aa7a26b..3b2c4303c7f7 100644
--- 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 @@ template <typename T> class VisitorImpl {
virtual ~VisitorImpl() {}
- void traverseDebugInfo();
+ Error traverseDebugInfo();
private:
void onVariableSizeValue(uint64_t U, unsigned Size);
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
index 1061d90ae167..f369dbe7e9bc 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -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:
More information about the llvm-commits
mailing list