aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/llvm-readobj.h
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-08 07:17:35 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-08 07:17:35 +0000
commit67ea32a00709f5f2d999002d747c58ac357223fd (patch)
tree997907a1a6b02d74da239524972b3beacef356b7 /llvm/tools/llvm-readobj/llvm-readobj.h
parent6fd13f0849573aeec26f28ab0927eea0b5a7ccb9 (diff)
downloadllvm-67ea32a00709f5f2d999002d747c58ac357223fd.zip
llvm-67ea32a00709f5f2d999002d747c58ac357223fd.tar.gz
llvm-67ea32a00709f5f2d999002d747c58ac357223fd.tar.bz2
[llvm-readobj/libObject] - Introduce a custom warning handler for `ELFFile<ELFT>` 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<ELFT> 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<ELFT> 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
Diffstat (limited to 'llvm/tools/llvm-readobj/llvm-readobj.h')
-rw-r--r--llvm/tools/llvm-readobj/llvm-readobj.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.h b/llvm/tools/llvm-readobj/llvm-readobj.h
index 0e02da4..7ca1dfb 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.h
+++ b/llvm/tools/llvm-readobj/llvm-readobj.h
@@ -24,6 +24,7 @@ namespace llvm {
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(StringRef Input, Error Err);
void reportWarning(Twine Msg);
+ void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);
void error(llvm::Error EC);
@@ -37,6 +38,8 @@ namespace llvm {
return *EO;
reportError(EO.getError().message());
}
+
+ // TODO: This one is deprecated. Use one with a Input name below.
template <class T> T unwrapOrError(Expected<T> EO) {
if (EO)
return *EO;
@@ -46,6 +49,13 @@ namespace llvm {
OS.flush();
reportError(Buf);
}
+
+ template <class T> T unwrapOrError(StringRef Input, Expected<T> EO) {
+ if (EO)
+ return *EO;
+ reportError(Input, EO.takeError());
+ llvm_unreachable("reportError shouldn't return in this case");
+ }
} // namespace llvm
namespace opts {