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 @@ -91,7 +91,8 @@ std::unique_ptr RegInfo; - std::function RecoverableErrorHandler = defaultErrorHandler; + std::function RecoverableErrorHandler = + WithColor::defaultErrorHandler; std::function WarningHandler = WithColor::defaultWarningHandler; /// Read compile units from the debug_info section (if necessary) @@ -110,7 +111,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; @@ -354,16 +359,25 @@ /// 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 ErrorPolicy objectFileErrorHandler(Error E); static std::unique_ptr create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr, - function_ref HandleError = defaultErrorHandler, - std::string DWPName = ""); + function_ref ObjectFileErrorHandler = + objectFileErrorHandler, + 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 @@ -64,9 +64,13 @@ using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind; using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind; -DWARFContext::DWARFContext(std::unique_ptr DObj, - std::string DWPName) - : DIContext(CK_DWARF), DWPName(std::move(DWPName)), DObj(std::move(DObj)) {} +DWARFContext::DWARFContext( + std::unique_ptr 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; @@ -1425,7 +1429,7 @@ return MachObj->isRelocationScattered(RelocInfo); } -ErrorPolicy DWARFContext::defaultErrorHandler(Error E) { +ErrorPolicy DWARFContext::objectFileErrorHandler(Error E) { WithColor::defaultErrorHandler(std::move(E)); return ErrorPolicy::Continue; } @@ -1895,20 +1899,27 @@ }; } // namespace -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::unique_ptr DWARFContext::create( + const object::ObjectFile &Obj, const LoadedObjectInfo *L, + function_ref ObjectFileErrorsHandler, + std::string DWPName, std::function RecoverableErrorHandler, + std::function WarningHandler) { + auto DObj = + std::make_unique(Obj, L, ObjectFileErrorsHandler); + 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 @@ -66,8 +66,7 @@ if (I != Modules.end()) return symbolizeCodeCommon(I->second.get(), ModuleOffset); - std::unique_ptr Context = - DWARFContext::create(Obj, nullptr, DWARFContext::defaultErrorHandler); + std::unique_ptr Context = DWARFContext::create(Obj); Expected InfoOrErr = createModuleInfo(&Obj, std::move(Context), ModuleName); if (!InfoOrErr) @@ -564,9 +563,9 @@ } } if (!Context) - Context = - DWARFContext::create(*Objects.second, nullptr, - DWARFContext::defaultErrorHandler, Opts.DWPName); + Context = DWARFContext::create(*Objects.second, nullptr, + DWARFContext::objectFileErrorHandler, + Opts.DWPName); return createModuleInfo(Objects.first, std::move(Context), ModuleName); }