diff options
author | Adrian Prantl <aprantl@apple.com> | 2021-06-23 10:43:38 -0700 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2021-06-23 10:44:13 -0700 |
commit | 072f5180f2d33a3323a164fe19a7a477e93073a9 (patch) | |
tree | 8b36a13a478e9a67c6909f0f23b8d3a3b2862870 /llvm/tools/llvm-dwarfdump | |
parent | 5d44d56f7deb086ac91664fbd053d703cefd3da9 (diff) | |
download | llvm-072f5180f2d33a3323a164fe19a7a477e93073a9.zip llvm-072f5180f2d33a3323a164fe19a7a477e93073a9.tar.gz llvm-072f5180f2d33a3323a164fe19a7a477e93073a9.tar.bz2 |
Improve error handling in llvm-dwarfdump.
Without this patch we're only showing a generic error message derived
from the error code to the end user.
rdar://79378794
Differential Revision: https://reviews.llvm.org/D104483
Diffstat (limited to 'llvm/tools/llvm-dwarfdump')
-rw-r--r-- | llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index abb2961..889deb4 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -263,13 +263,17 @@ static cl::extrahelp /// @} //===----------------------------------------------------------------------===// -static void error(StringRef Prefix, std::error_code EC) { - if (!EC) +static void error(StringRef Prefix, Error Err) { + if (!Err) return; - WithColor::error() << Prefix << ": " << EC.message() << "\n"; + WithColor::error() << Prefix << ": " << toString(std::move(Err)) << "\n"; exit(1); } +static void error(StringRef Prefix, std::error_code EC) { + error(Prefix, errorCodeToError(EC)); +} + static DIDumpOptions getDumpOpts(DWARFContext &C) { DIDumpOptions DumpOpts; DumpOpts.DumpType = DumpType; @@ -508,13 +512,13 @@ static bool handleArchive(StringRef Filename, Archive &Arch, Error Err = Error::success(); for (auto Child : Arch.children(Err)) { auto BuffOrErr = Child.getMemoryBufferRef(); - error(Filename, errorToErrorCode(BuffOrErr.takeError())); + error(Filename, BuffOrErr.takeError()); auto NameOrErr = Child.getName(); - error(Filename, errorToErrorCode(NameOrErr.takeError())); + error(Filename, NameOrErr.takeError()); std::string Name = (Filename + "(" + NameOrErr.get() + ")").str(); Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj, OS); } - error(Filename, errorToErrorCode(std::move(Err))); + error(Filename, std::move(Err)); return Result; } @@ -522,7 +526,7 @@ static bool handleArchive(StringRef Filename, Archive &Arch, static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer, HandlerFn HandleObj, raw_ostream &OS) { Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer); - error(Filename, errorToErrorCode(BinOrErr.takeError())); + error(Filename, BinOrErr.takeError()); bool Result = true; auto RecoverableErrorHandler = [&](Error E) { @@ -553,7 +557,7 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer, } else consumeError(MachOOrErr.takeError()); if (auto ArchiveOrErr = ObjForArch.getAsArchive()) { - error(ObjName, errorToErrorCode(ArchiveOrErr.takeError())); + error(ObjName, ArchiveOrErr.takeError()); if (!handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS)) Result = false; continue; |