[llvm] 949134e - [DebugInfo][NFC] Remove handler with ErrorPolicy from DWARFContext.
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 13:42:47 PST 2020
Author: Alexey Lapshin
Date: 2020-02-27T00:42:37+03:00
New Revision: 949134e2fefd34a38ed71de90dffe2300e2e1139
URL: https://github.com/llvm/llvm-project/commit/949134e2fefd34a38ed71de90dffe2300e2e1139
DIFF: https://github.com/llvm/llvm-project/commit/949134e2fefd34a38ed71de90dffe2300e2e1139.diff
LOG: [DebugInfo][NFC] Remove handler with ErrorPolicy from DWARFContext.
Summary:
Current LLVM code base does not use error handler with ErrorPolicy.
This patch removes ErrorPolicy from DWARFContext.
This patch is extracted from the D74308.
Reviewers: jhenderson, dblaikie, grimar, aprantl, JDevlieghere
Reviewed By: grimar
Subscribers: hiraditya, llvm-commits
Tags: #llvm, #debug-info
Differential Revision: https://reviews.llvm.org/D75118
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 6de718768d18..d0013664702c 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -47,11 +47,6 @@ class MCRegisterInfo;
class MemoryBuffer;
class raw_ostream;
-/// 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 };
-
/// DWARFContext
/// This data structure is the top level entity that deals with dwarf debug
/// information parsing. The actual data is supplied through DWARFObj.
@@ -91,7 +86,8 @@ class DWARFContext : public DIContext {
std::unique_ptr<MCRegisterInfo> RegInfo;
- std::function<void(Error)> RecoverableErrorHandler = defaultErrorHandler;
+ std::function<void(Error)> RecoverableErrorHandler =
+ WithColor::defaultErrorHandler;
std::function<void(Error)> WarningHandler = WithColor::defaultWarningHandler;
/// Read compile units from the debug_info section (if necessary)
@@ -352,13 +348,9 @@ class DWARFContext : public DIContext {
function_ref<void(Error)> getWarningHandler() { return WarningHandler; }
- /// 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);
-
static std::unique_ptr<DWARFContext>
create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
- function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler,
+ function_ref<void(Error)> HandleError = WithColor::defaultErrorHandler,
std::string DWPName = "");
static std::unique_ptr<DWARFContext>
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index e46c7eb150af..0ce69da1ef82 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1427,11 +1427,6 @@ static bool isRelocScattered(const object::ObjectFile &Obj,
return MachObj->isRelocationScattered(RelocInfo);
}
-ErrorPolicy DWARFContext::defaultErrorHandler(Error E) {
- WithColor::defaultErrorHandler(std::move(E));
- return ErrorPolicy::Continue;
-}
-
namespace {
struct DWARFSectionMap final : public DWARFSection {
RelocAddrMap Relocs;
@@ -1583,7 +1578,7 @@ class DWARFObjInMemory final : public DWARFObject {
}
}
DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
- function_ref<ErrorPolicy(Error)> HandleError)
+ function_ref<void(Error)> HandleError)
: IsLittleEndian(Obj.isLittleEndian()),
AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
Obj(&Obj) {
@@ -1610,10 +1605,8 @@ class DWARFObjInMemory final : public DWARFObject {
StringRef Data;
Expected<section_iterator> SecOrErr = Section.getRelocatedSection();
if (!SecOrErr) {
- ErrorPolicy EP = HandleError(createError(
- "failed to get relocated section: ", SecOrErr.takeError()));
- if (EP == ErrorPolicy::Halt)
- return;
+ HandleError(createError("failed to get relocated section: ",
+ SecOrErr.takeError()));
continue;
}
@@ -1631,10 +1624,8 @@ class DWARFObjInMemory final : public DWARFObject {
}
if (auto Err = maybeDecompress(Section, Name, Data)) {
- ErrorPolicy EP = HandleError(createError(
- "failed to decompress '" + Name + "', ", std::move(Err)));
- if (EP == ErrorPolicy::Halt)
- return;
+ HandleError(createError("failed to decompress '" + Name + "', ",
+ std::move(Err)));
continue;
}
@@ -1735,8 +1726,7 @@ class DWARFObjInMemory final : public DWARFObject {
Expected<SymInfo> SymInfoOrErr =
getSymbolInfo(Obj, Reloc, L, AddrCache);
if (!SymInfoOrErr) {
- if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
- return;
+ HandleError(SymInfoOrErr.takeError());
continue;
}
@@ -1756,10 +1746,8 @@ class DWARFObjInMemory final : public DWARFObject {
if (!I.second) {
RelocAddrEntry &entry = I.first->getSecond();
if (entry.Reloc2) {
- ErrorPolicy EP = HandleError(createError(
+ HandleError(createError(
"At most two relocations per offset are supported"));
- if (EP == ErrorPolicy::Halt)
- return;
}
entry.Reloc2 = Reloc;
entry.SymbolValue2 = SymInfoOrErr->Address;
@@ -1767,11 +1755,9 @@ class DWARFObjInMemory final : public DWARFObject {
} else {
SmallString<32> Type;
Reloc.getTypeName(Type);
- ErrorPolicy EP = HandleError(
+ HandleError(
createError("failed to compute relocation: " + Type + ", ",
errorCodeToError(object_error::parse_failed)));
- if (EP == ErrorPolicy::Halt)
- return;
}
}
}
@@ -1899,7 +1885,7 @@ class DWARFObjInMemory final : public DWARFObject {
std::unique_ptr<DWARFContext>
DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
- function_ref<ErrorPolicy(Error)> HandleError,
+ function_ref<void(Error)> HandleError,
std::string DWPName) {
auto DObj = std::make_unique<DWARFObjInMemory>(Obj, L, HandleError);
return std::make_unique<DWARFContext>(std::move(DObj), std::move(DWPName));
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 84cf4d40318f..03c0ee96a8d4 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -66,8 +66,7 @@ LLVMSymbolizer::symbolizeCode(const ObjectFile &Obj,
if (I != Modules.end())
return symbolizeCodeCommon(I->second.get(), ModuleOffset);
- std::unique_ptr<DIContext> Context =
- DWARFContext::create(Obj, nullptr, DWARFContext::defaultErrorHandler);
+ std::unique_ptr<DIContext> Context = DWARFContext::create(Obj);
Expected<SymbolizableModule *> InfoOrErr =
createModuleInfo(&Obj, std::move(Context), ModuleName);
if (!InfoOrErr)
@@ -564,9 +563,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
}
}
if (!Context)
- Context =
- DWARFContext::create(*Objects.second, nullptr,
- DWARFContext::defaultErrorHandler, Opts.DWPName);
+ Context = DWARFContext::create(
+ *Objects.second, nullptr, WithColor::defaultErrorHandler, Opts.DWPName);
return createModuleInfo(Objects.first, std::move(Context), ModuleName);
}
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
index 870247a22cf0..b2db87ad5cd7 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -2506,7 +2506,7 @@ TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) {
"offset:");
}
-TEST(DWARFDebugInfo, TestErrorReportingPolicy) {
+TEST(DWARFDebugInfo, TestErrorReporting) {
Triple Triple("x86_64-pc-linux");
if (!isConfigurationSupported(Triple))
return;
@@ -2529,26 +2529,14 @@ TEST(DWARFDebugInfo, TestErrorReportingPolicy) {
auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
EXPECT_TRUE((bool)Obj);
- // Case 1: error handler handles all errors. That allows
- // DWARFContext to parse whole file and find both two errors we know about.
+ // DWARFContext parses whole file and finds the two errors we expect.
int Errors = 0;
std::unique_ptr<DWARFContext> Ctx1 =
DWARFContext::create(**Obj, 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;
- std::unique_ptr<DWARFContext> Ctx2 =
- DWARFContext::create(**Obj, nullptr, [&](Error E) {
- ++Errors;
- consumeError(std::move(E));
- return ErrorPolicy::Halt;
- });
- EXPECT_TRUE(Errors == 1);
}
TEST(DWARFDebugInfo, TestDwarfVerifyCURangesIncomplete) {
More information about the llvm-commits
mailing list