summaryrefslogtreecommitdiff
path: root/unittests/DebugInfo/DWARF
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-06-28 08:21:19 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-06-28 08:21:19 +0000
commitc9c94f42b160b3524455479295fb6bbdf925f1d3 (patch)
tree2c19b6fcd3b7a53b09477db82936ccbb54e4420b /unittests/DebugInfo/DWARF
parentf41c3c9239734af0a6c543430ea4ffd2dfe736cb (diff)
Recommit "[ELF] - Add ability for DWARFContextInMemory to exit early when any error happen."
With fix in include folder character case: #include "llvm/Codegen/AsmPrinter.h" -> #include "llvm/CodeGen/AsmPrinter.h" Original commit message: Change introduces error reporting policy for DWARFContextInMemory. New callback provided by client is able to handle error on it's side and return Halt or Continue. That allows to either keep current behavior when parser prints all errors but continues parsing object or implement something very different, like stop parsing on a first error and report an error in a client style. Differential revision: https://reviews.llvm.org/D34328 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/DebugInfo/DWARF')
-rw-r--r--unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp47
-rw-r--r--unittests/DebugInfo/DWARF/DwarfGenerator.h1
2 files changed, 48 insertions, 0 deletions
diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
index bf004d6ffc2..7f6492ee6d1 100644
--- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -15,10 +15,14 @@
#include "llvm/ADT/Triple.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSectionELF.h"
+#include "llvm/MC/MCStreamer.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/ObjectYAML/DWARFEmitter.h"
#include "llvm/ObjectYAML/DWARFYAML.h"
@@ -2146,4 +2150,47 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) {
"offset:");
}
+TEST(DWARFDebugInfo, TestErrorReportingPolicy) {
+ initLLVMIfNeeded();
+ auto ExpectedDG = dwarfgen::Generator::create(Triple("x86_64-pc-linux"),
+ 4 /*DwarfVersion*/);
+ if (HandleExpectedError(ExpectedDG))
+ return;
+ dwarfgen::Generator *DG = ExpectedDG.get().get();
+ AsmPrinter *AP = DG->getAsmPrinter();
+ MCContext *MC = DG->getMCContext();
+
+ // Emit two compressed sections with broken headers.
+ AP->OutStreamer->SwitchSection(
+ MC->getELFSection(".zdebug_foo", 0 /*Type*/, 0 /*Flags*/));
+ AP->OutStreamer->EmitBytes("0");
+ AP->OutStreamer->SwitchSection(
+ MC->getELFSection(".zdebug_bar", 0 /*Type*/, 0 /*Flags*/));
+ AP->OutStreamer->EmitBytes("0");
+
+ MemoryBufferRef FileBuffer(DG->generate(), "dwarf");
+ auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
+ EXPECT_TRUE((bool)Obj);
+
+ // Case 1: error handler handles all errors. That allows
+ // DWARFContextInMemory
+ // to parse whole file and find both two errors we know about.
+ int Errors = 0;
+ DWARFContextInMemory Ctx1(*Obj.get(), nullptr, [&](Error E) {
+ ++Errors;
+ consumeError(std::move(E));
+ return ErrorPolicy::Continue;
+ });
+ EXPECT_TRUE(Errors == 2);
+
+ // Case 2: error handler stops parsing of object after first error.
+ Errors = 0;
+ DWARFContextInMemory Ctx2(*Obj.get(), nullptr, [&](Error E) {
+ ++Errors;
+ consumeError(std::move(E));
+ return ErrorPolicy::Halt;
+ });
+ EXPECT_TRUE(Errors == 1);
+}
+
} // end anonymous namespace
diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.h b/unittests/DebugInfo/DWARF/DwarfGenerator.h
index 76665e5193e..dd7e8709638 100644
--- a/unittests/DebugInfo/DWARF/DwarfGenerator.h
+++ b/unittests/DebugInfo/DWARF/DwarfGenerator.h
@@ -215,6 +215,7 @@ public:
BumpPtrAllocator &getAllocator() { return Allocator; }
AsmPrinter *getAsmPrinter() const { return Asm.get(); }
+ MCContext *getMCContext() const { return MC.get(); }
DIEAbbrevSet &getAbbrevSet() { return Abbreviations; }
DwarfStringPool &getStringPool() { return *StringPool; }