diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-06-04 18:34:11 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-06-04 18:34:11 +0000 |
commit | 50d0fbd2b95dc931fe1803468628a7e53ad1bbee (patch) | |
tree | a7dc95b93931c0a6f800aefa40edebe351ada64b /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 713bfbb2d415a73e0dd3e20ba7b37bf0493368bd (diff) | |
download | bcm5719-llvm-50d0fbd2b95dc931fe1803468628a7e53ad1bbee.tar.gz bcm5719-llvm-50d0fbd2b95dc931fe1803468628a7e53ad1bbee.zip |
llvm-objdump: return non-zero exit code for certain cases of invalid input
* If the input file is missing;
* If the type of input object file can't be recognized;
* If the object file can't be parsed correctly.
llvm-svn: 239065
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 58600f62f4d..58f6db0465d 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/GraphWriter.h" @@ -161,6 +162,12 @@ bool llvm::error(std::error_code EC) { return true; } +static void report_error(StringRef File, std::error_code EC) { + assert(EC); + errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n"; + ReturnValue = EXIT_FAILURE; +} + static const Target *getTarget(const ObjectFile *Obj = nullptr) { // Figure out the target triple. llvm::Triple TheTriple("unknown-unknown-unknown"); @@ -1263,15 +1270,13 @@ static void DumpArchive(const Archive *a) { if (std::error_code EC = ChildOrErr.getError()) { // Ignore non-object files. if (EC != object_error::invalid_file_type) - errs() << ToolName << ": '" << a->getFileName() << "': " << EC.message() - << ".\n"; + report_error(a->getFileName(), EC); continue; } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) DumpObject(o); else - errs() << ToolName << ": '" << a->getFileName() << "': " - << "Unrecognized file type.\n"; + report_error(a->getFileName(), object_error::invalid_file_type); } } @@ -1279,7 +1284,7 @@ static void DumpArchive(const Archive *a) { static void DumpInput(StringRef file) { // If file isn't stdin, check that it exists. if (file != "-" && !sys::fs::exists(file)) { - errs() << ToolName << ": '" << file << "': " << "No such file\n"; + report_error(file, errc::no_such_file_or_directory); return; } @@ -1294,7 +1299,7 @@ static void DumpInput(StringRef file) { // Attempt to open the binary. ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file); if (std::error_code EC = BinaryOrErr.getError()) { - errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n"; + report_error(file, EC); return; } Binary &Binary = *BinaryOrErr.get().getBinary(); @@ -1304,7 +1309,7 @@ static void DumpInput(StringRef file) { else if (ObjectFile *o = dyn_cast<ObjectFile>(&Binary)) DumpObject(o); else - errs() << ToolName << ": '" << file << "': " << "Unrecognized file type.\n"; + report_error(file, object_error::invalid_file_type); } int main(int argc, char **argv) { |