aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-cxxdump/llvm-cxxdump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-cxxdump/llvm-cxxdump.cpp')
-rw-r--r--tools/llvm-cxxdump/llvm-cxxdump.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/llvm-cxxdump/llvm-cxxdump.cpp b/tools/llvm-cxxdump/llvm-cxxdump.cpp
index 7594066a395d..833312655788 100644
--- a/tools/llvm-cxxdump/llvm-cxxdump.cpp
+++ b/tools/llvm-cxxdump/llvm-cxxdump.cpp
@@ -1,9 +1,8 @@
//===- llvm-cxxdump.cpp - Dump C++ data in an Object File -------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -49,15 +48,20 @@ static void error(std::error_code EC) {
exit(1);
}
-static void error(Error Err) {
- if (!Err)
- return;
+LLVM_ATTRIBUTE_NORETURN static void error(Error Err) {
logAllUnhandledErrors(std::move(Err), WithColor::error(outs()),
"reading file: ");
outs().flush();
exit(1);
}
+template <typename T>
+T unwrapOrError(Expected<T> EO) {
+ if (!EO)
+ error(EO.takeError());
+ return std::move(*EO);
+}
+
} // namespace llvm
static void reportError(StringRef Input, StringRef Message) {
@@ -196,8 +200,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
// Skip virtual or BSS sections.
if (Sec.isBSS() || Sec.isVirtual())
continue;
- StringRef SecContents;
- error(Sec.getContents(SecContents));
+ StringRef SecContents = unwrapOrError(Sec.getContents());
Expected<uint64_t> SymAddressOrErr = Sym.getAddress();
error(errorToErrorCode(SymAddressOrErr.takeError()));
uint64_t SymAddress = *SymAddressOrErr;
@@ -511,7 +514,8 @@ static void dumpArchive(const Archive *Arc) {
else
reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);
}
- error(std::move(Err));
+ if (Err)
+ error(std::move(Err));
}
static void dumpInput(StringRef File) {