[llvm-objdump] Use report_error() and improve error coverage.
authorDavide Italiano <davide@freebsd.org>
Wed, 13 Jan 2016 02:03:31 +0000 (02:03 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 13 Jan 2016 02:03:31 +0000 (02:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257561 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-objdump/Inputs/malformed-macho.bin [new file with mode: 0644]
test/tools/llvm-objdump/malformed-archives.test
test/tools/llvm-objdump/malformed-macho.test [new file with mode: 0644]
tools/llvm-objdump/MachODump.cpp

diff --git a/test/tools/llvm-objdump/Inputs/malformed-macho.bin b/test/tools/llvm-objdump/Inputs/malformed-macho.bin
new file mode 100644 (file)
index 0000000..b8a3f15
Binary files /dev/null and b/test/tools/llvm-objdump/Inputs/malformed-macho.bin differ
index e0f165d37ed7c9b8a190807abf56dc68fed388ef..c477022e2e11aa51bd8068a9831a86bf07ed7260 100644 (file)
@@ -1,7 +1,7 @@
 // These test checks that llvm-objdump will not crash with malformed Archive
 // files.  So the check line is not all that important but the bug fixes to
 // make sure llvm-objdump is robust is what matters.
-# RUN: llvm-objdump -macho -archive-headers \
+# RUN: not llvm-objdump -macho -archive-headers \
 # RUN:   %p/Inputs/libbogus1.a \
 # RUN:   2>&1 | FileCheck -check-prefix=bogus1 %s 
 
diff --git a/test/tools/llvm-objdump/malformed-macho.test b/test/tools/llvm-objdump/malformed-macho.test
new file mode 100644 (file)
index 0000000..e96945d
--- /dev/null
@@ -0,0 +1,2 @@
+RUN: not llvm-objdump -macho -s %p/Inputs/malformed-macho.bin 2>&1 | FileCheck %s -check-prefix=MALFORMED
+MALFORMED: '{{.*}}': The file was not recognized as a valid object file
index e486b1a0d6d9eb9d7072b40ed46d4198f6c2a771..87b2b439d55cc6136530e8fa3e714e1e386f297a 100644 (file)
@@ -1481,10 +1481,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
 
   // Attempt to open the binary.
   ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(Filename);
-  if (std::error_code EC = BinaryOrErr.getError()) {
-    errs() << "llvm-objdump: '" << Filename << "': " << EC.message() << ".\n";
-    return;
-  }
+  if (std::error_code EC = BinaryOrErr.getError())
+    report_error(Filename, EC);
   Binary &Bin = *BinaryOrErr.get().getBinary();
 
   if (Archive *A = dyn_cast<Archive>(&Bin)) {