summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorStephen Tozer <stephen.tozer@sony.com>2019-04-05 16:15:50 +0000
committerStephen Tozer <stephen.tozer@sony.com>2019-04-05 16:15:50 +0000
commit681b0798dbbc6b3500c9930977ec8a274b142acb (patch)
tree09416478f4286b865120010561943098cbf97980 /llvm/tools
parented7f8e6509ba6997b12281acd41fbeddc0d27216 (diff)
downloadbcm5719-llvm-681b0798dbbc6b3500c9930977ec8a274b142acb.tar.gz
bcm5719-llvm-681b0798dbbc6b3500c9930977ec8a274b142acb.zip
[llvm-readobj] Improve error message for --string-dump
Fixes bug 40630: https://bugs.llvm.org/show_bug.cgi?id=40630 This patch changes the error message when the section specified by --string-dump cannot be found by including the name of the section in the error message and changing the prefix text to not imply that the file itself was invalid. As part of this change some uses of std::error_code have been replaced with the llvm Error class to better encapsulate the error info (rather than passing File strings around), and the WithColor class replaces string literal error prefixes. Differential Revision: https://reviews.llvm.org/D59946 llvm-svn: 357772
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-readobj/ObjDumper.cpp6
-rw-r--r--llvm/tools/llvm-readobj/llvm-readobj.cpp21
2 files changed, 11 insertions, 16 deletions
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 2009ddeb57a..15facefaddf 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -16,6 +16,7 @@
#include "llvm-readobj.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/raw_ostream.h"
@@ -54,8 +55,9 @@ getSecNameOrIndexAsSecRef(const object::ObjectFile *Obj, StringRef SecName) {
SecIndex++;
}
- return make_error<StringError>("invalid section reference",
- object::object_error::parse_failed);
+ return make_error<StringError>(
+ formatv("could not find section '{0}'", SecName),
+ object::object_error::parse_failed);
}
void ObjDumper::printSectionAsString(const object::ObjectFile *Obj,
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index 30c51c46c9f..7ccc67bfb31 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -39,6 +39,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/WithColor.h"
using namespace llvm;
using namespace llvm::object;
@@ -367,8 +368,8 @@ namespace opts {
namespace llvm {
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
- errs() << "\nError reading file: " << Msg << ".\n";
- errs().flush();
+ errs() << "\n";
+ WithColor::error(errs()) << Msg << "\n";
exit(1);
}
@@ -391,22 +392,14 @@ bool relocAddressLess(RelocationRef a, RelocationRef b) {
} // namespace llvm
-static void reportError(StringRef Input, std::error_code EC) {
+static void reportError(StringRef Input, Error Err) {
if (Input == "-")
Input = "<stdin>";
-
- reportError(Twine(Input) + ": " + EC.message());
+ error(createFileError(Input, std::move(Err)));
}
-static void reportError(StringRef Input, Error Err) {
- if (Input == "-")
- Input = "<stdin>";
- std::string ErrMsg;
- {
- raw_string_ostream ErrStream(ErrMsg);
- logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");
- }
- reportError(ErrMsg);
+static void reportError(StringRef Input, std::error_code EC) {
+ reportError(Input, errorCodeToError(EC));
}
static bool isMipsArch(unsigned Arch) {
OpenPOWER on IntegriCloud