diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -106,7 +106,11 @@ public: DWARFContext(std::unique_ptr DObj, - std::string DWPName = ""); + std::string DWPName = "", + std::function RecoverableErrorHandler = + WithColor::defaultErrorHandler, + std::function WarningHandler = + WithColor::defaultWarningHandler); ~DWARFContext(); DWARFContext(DWARFContext &) = delete; @@ -350,12 +354,19 @@ static std::unique_ptr create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr, - function_ref HandleError = WithColor::defaultErrorHandler, - std::string DWPName = ""); + std::string DWPName = "", + std::function RecoverableErrorHandler = + WithColor::defaultErrorHandler, + std::function WarningHandler = + WithColor::defaultWarningHandler); static std::unique_ptr create(const StringMap> &Sections, - uint8_t AddrSize, bool isLittleEndian = sys::IsLittleEndianHost); + uint8_t AddrSize, bool isLittleEndian = sys::IsLittleEndianHost, + std::function RecoverableErrorHandler = + WithColor::defaultErrorHandler, + std::function WarningHandler = + WithColor::defaultWarningHandler); /// Loads register info for the architecture of the provided object file. /// Improves readability of dumped DWARF expressions. Requires the caller to diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -65,8 +65,12 @@ using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind; DWARFContext::DWARFContext(std::unique_ptr DObj, - std::string DWPName) - : DIContext(CK_DWARF), DWPName(std::move(DWPName)), DObj(std::move(DObj)) {} + std::string DWPName, + std::function RecoverableErrorHandler, + std::function WarningHandler) + : DIContext(CK_DWARF), DWPName(std::move(DWPName)), + RecoverableErrorHandler(RecoverableErrorHandler), + WarningHandler(WarningHandler), DObj(std::move(DObj)) {} DWARFContext::~DWARFContext() = default; @@ -1885,18 +1889,25 @@ std::unique_ptr DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L, - function_ref HandleError, - std::string DWPName) { - auto DObj = std::make_unique(Obj, L, HandleError); - return std::make_unique(std::move(DObj), std::move(DWPName)); + std::string DWPName, + std::function RecoverableErrorHandler, + std::function WarningHandler) { + auto DObj = + std::make_unique(Obj, L, RecoverableErrorHandler); + return std::make_unique(std::move(DObj), std::move(DWPName), + RecoverableErrorHandler, + WarningHandler); } std::unique_ptr DWARFContext::create(const StringMap> &Sections, - uint8_t AddrSize, bool isLittleEndian) { + uint8_t AddrSize, bool isLittleEndian, + std::function RecoverableErrorHandler, + std::function WarningHandler) { auto DObj = std::make_unique(Sections, AddrSize, isLittleEndian); - return std::make_unique(std::move(DObj), ""); + return std::make_unique( + std::move(DObj), "", RecoverableErrorHandler, WarningHandler); } Error DWARFContext::loadRegisterInfo(const object::ObjectFile &Obj) { diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -563,8 +563,7 @@ } } if (!Context) - Context = DWARFContext::create( - *Objects.second, nullptr, WithColor::defaultErrorHandler, Opts.DWPName); + Context = DWARFContext::create(*Objects.second, nullptr, 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 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -2532,7 +2532,7 @@ // DWARFContext parses whole file and finds the two errors we expect. int Errors = 0; std::unique_ptr Ctx1 = - DWARFContext::create(**Obj, nullptr, [&](Error E) { + DWARFContext::create(**Obj, nullptr, "", [&](Error E) { ++Errors; consumeError(std::move(E)); });