[llvm] r306513 - Revert r306512 "[ELF] - Add ability for DWARFContextInMemory to exit early when any error happen."

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 00:06:17 PDT 2017


Author: grimar
Date: Wed Jun 28 00:06:17 2017
New Revision: 306513

URL: http://llvm.org/viewvc/llvm-project?rev=306513&view=rev
Log:
Revert r306512 "[ELF] - Add ability for DWARFContextInMemory to exit early when any error happen."

It broke BB:

[13/106] 13 0.022 Generating VCSRevision.h
[25/106] 24 1.209 Building CXX object unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o
FAILED: unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o 
/home/bb/bin/g++  -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_GLOBAL_ISEL -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iunittests/DebugInfo/DWARF -I../llvm-project/llvm/unittests/DebugInfo/DWARF -Iinclude -I../llvm-project/llvm/include -I../llvm-project/llvm/utils/unittest/googletest/include -I../llvm-project/llvm/utils/unittest/googlemock/include -fPIC -fvisibility-inlines-hidden -m32 -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O3    -UNDEBUG  -Wno-variadic-macros -fno-exceptions -fno-rtti -MD -MT unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o -MF unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o.d -o unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o -c ../llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
../llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp:18:37: fatal error: llvm/Codegen/AsmPrinter.h: No such file or directory
 #include "llvm/Codegen/AsmPrinter.h"
                                     ^
compilation terminated.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
    llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=306513&r1=306512&r2=306513&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Wed Jun 28 00:06:17 2017
@@ -289,11 +289,6 @@ private:
   DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
 };
 
-/// Used as a return value for a error callback passed to DWARF context.
-/// Callback should return Halt if client application wants to stop
-/// object parsing, or should return Continue otherwise.
-enum class ErrorPolicy { Halt, Continue };
-
 /// DWARFContextInMemory is the simplest possible implementation of a
 /// DWARFContext. It assumes all content is available in memory and stores
 /// pointers to it.
@@ -351,14 +346,9 @@ class DWARFContextInMemory : public DWAR
   Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
                         StringRef &Data);
 
-  /// Function used to handle default error reporting policy. Prints a error
-  /// message and returns Continue, so DWARF context ignores the error.
-  static ErrorPolicy defaultErrorHandler(Error E);
-
 public:
-  DWARFContextInMemory(
-      const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
-      function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler);
+  DWARFContextInMemory(const object::ObjectFile &Obj,
+    const LoadedObjectInfo *L = nullptr);
 
   DWARFContextInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
                        uint8_t AddrSize,

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=306513&r1=306512&r2=306513&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Wed Jun 28 00:06:17 2017
@@ -870,13 +870,13 @@ static Expected<SymInfo> getSymbolInfo(c
 
     Expected<uint64_t> SymAddrOrErr = Sym->getAddress();
     if (!SymAddrOrErr)
-      return createError("failed to compute symbol address: ",
+      return createError("error: failed to compute symbol address: ",
                          SymAddrOrErr.takeError());
 
     // Also remember what section this symbol is in for later
     auto SectOrErr = Sym->getSection();
     if (!SectOrErr)
-      return createError("failed to get symbol section: ",
+      return createError("error: failed to get symbol section: ",
                          SectOrErr.takeError());
 
     RSec = *SectOrErr;
@@ -937,14 +937,8 @@ Error DWARFContextInMemory::maybeDecompr
   return Error::success();
 }
 
-ErrorPolicy DWARFContextInMemory::defaultErrorHandler(Error E) {
-  errs() << "error: " + toString(std::move(E)) << '\n';
-  return ErrorPolicy::Continue;
-}
-
-DWARFContextInMemory::DWARFContextInMemory(
-    const object::ObjectFile &Obj, const LoadedObjectInfo *L,
-    function_ref<ErrorPolicy(Error)> HandleError)
+DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
+                                           const LoadedObjectInfo *L)
     : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()),
       AddressSize(Obj.getBytesInAddress()) {
   for (const SectionRef &Section : Obj.sections()) {
@@ -967,10 +961,9 @@ DWARFContextInMemory::DWARFContextInMemo
       Section.getContents(data);
 
     if (auto Err = maybeDecompress(Section, name, data)) {
-      ErrorPolicy EP = HandleError(
-          createError("failed to decompress '" + name + "', ", std::move(Err)));
-      if (EP == ErrorPolicy::Halt)
-        return;
+      errs() << "error: failed to decompress '" + name + "', " +
+                    toString(std::move(Err))
+             << '\n';
       continue;
     }
 
@@ -1062,8 +1055,7 @@ DWARFContextInMemory::DWARFContextInMemo
 
       Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache);
       if (!SymInfoOrErr) {
-        if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
-          return;
+        errs() << toString(SymInfoOrErr.takeError()) << '\n';
         continue;
       }
 
@@ -1072,11 +1064,7 @@ DWARFContextInMemory::DWARFContextInMemo
       if (V.error()) {
         SmallString<32> Name;
         Reloc.getTypeName(Name);
-        ErrorPolicy EP = HandleError(
-            createError("failed to compute relocation: " + name + ", ",
-                        errorCodeToError(object_error::parse_failed)));
-        if (EP == ErrorPolicy::Halt)
-          return;
+        errs() << "error: failed to compute relocation: " << Name << "\n";
         continue;
       }
       RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};

Modified: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=306513&r1=306512&r2=306513&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp Wed Jun 28 00:06:17 2017
@@ -15,14 +15,10 @@
 #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"
@@ -2150,47 +2146,4 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDo
                             "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

Modified: llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h?rev=306513&r1=306512&r2=306513&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h (original)
+++ llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h Wed Jun 28 00:06:17 2017
@@ -215,7 +215,6 @@ 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; }
 




More information about the llvm-commits mailing list