From 67ea32a00709f5f2d999002d747c58ac357223fd Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 8 Aug 2019 07:17:35 +0000 Subject: [llvm-readobj/libObject] - Introduce a custom warning handler for `ELFFile` methods. Currently, we have a code duplication in llvm-readobj which was introduced in D63266. The duplication was introduced to allow llvm-readobj to dump the partially broken object. Methods in ELFFile perform a strict validation of the inputs, what is itself good, but not for dumper tools, that might want to dump the information, even if some pieces are broken/unexpected. This patch introduces a warning handler which can be passed to ELFFile methods and can allow skipping the non-critical errors when needed/possible. For demonstration, I removed the duplication from llvm-readobj and implemented a warning using the new custom warning handler. It also deduplicates the strings printed, making the output less verbose. Differential revision: https://reviews.llvm.org/D65515 llvm-svn: 368260 --- llvm/tools/llvm-readobj/llvm-readobj.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/tools/llvm-readobj/llvm-readobj.cpp') diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index bb629c28cf1..f607490e8f8 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -394,6 +394,12 @@ void reportWarning(Twine Msg) { WithColor::warning(errs()) << Msg << "\n"; } +void reportWarning(StringRef Input, Error Err) { + if (Input == "-") + Input = ""; + warn(createFileError(Input, std::move(Err))); +} + void warn(Error Err) { handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) { reportWarning(EI.message()); -- cgit v1.2.3