[llvm] r302664 - [llvm-readobj] Improve errors on invalid binary
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed May 10 07:18:12 PDT 2017
Author: sbc
Date: Wed May 10 09:18:11 2017
New Revision: 302664
URL: http://llvm.org/viewvc/llvm-project?rev=302664&view=rev
Log:
[llvm-readobj] Improve errors on invalid binary
The previous code was discarding the error message from
createBinary() by calling errorToErrorCode().
This meant that such error were always reported unhelpfully
as "Invalid data was encountered while parsing the file".
Other tools such as llvm-objdump already produce a more
the error message in this case.
Differential Revision: https://reviews.llvm.org/D32985
Added:
llvm/trunk/test/tools/llvm-readobj/wasm-invalid.test
Modified:
llvm/trunk/test/Object/invalid.test
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=302664&r1=302663&r2=302664&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Wed May 10 09:18:11 2017
@@ -53,7 +53,7 @@ INVALID-SYMTAB-SIZE: size is not a multi
RUN: not llvm-readobj -t %p/Inputs/invalid-xindex-size.elf 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
-INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file.
+INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file
RUN: not llvm-readobj -t %p/Inputs/invalid-e_shnum.elf 2>&1 | FileCheck --check-prefix=INVALID-SH-NUM %s
INVALID-SH-NUM: invalid e_phentsize
@@ -77,7 +77,7 @@ RUN: FileCheck --check-prefix=INVALID-
INVALID-SECTION-SIZE2: invalid section offset
RUN: not llvm-readobj -t %p/Inputs/invalid-sections-num.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-NUM %s
-INVALID-SECTION-NUM: Invalid data was encountered while parsing the file.
+INVALID-SECTION-NUM: Invalid data was encountered while parsing the file
RUN: not llvm-readobj -r %p/Inputs/invalid-rel-sym.elf 2>&1 | FileCheck --check-prefix=INVALID-REL-SYM %s
INVALID-REL-SYM: invalid section offset
Added: llvm/trunk/test/tools/llvm-readobj/wasm-invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/wasm-invalid.test?rev=302664&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/wasm-invalid.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/wasm-invalid.test Wed May 10 09:18:11 2017
@@ -0,0 +1,7 @@
+# RUN: yaml2obj %s | not llvm-readobj -t - 2>&1 | FileCheck %s
+
+--- !WASM
+FileHeader:
+ Version: 0x0000000c
+
+# CHECK: Error reading file: <stdin>: Bad version number
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=302664&r1=302663&r2=302664&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Wed May 10 09:18:11 2017
@@ -311,13 +311,6 @@ static void reportError(StringRef Input,
reportError(Twine(Input) + ": " + EC.message());
}
-static void reportError(StringRef Input, StringRef Message) {
- if (Input == "-")
- Input = "<stdin>";
-
- reportError(Twine(Input) + ": " + Message);
-}
-
static void reportError(StringRef Input, Error Err) {
if (Input == "-")
Input = "<stdin>";
@@ -481,11 +474,7 @@ static void dumpArchive(const Archive *A
Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
if (!ChildOrErr) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
- std::string Buf;
- raw_string_ostream OS(Buf);
- logAllUnhandledErrors(ChildOrErr.takeError(), OS, "");
- OS.flush();
- reportError(Arc->getFileName(), Buf);
+ reportError(Arc->getFileName(), ChildOrErr.takeError());
}
continue;
}
@@ -507,11 +496,7 @@ static void dumpMachOUniversalBinary(con
if (ObjOrErr)
dumpObject(&*ObjOrErr.get());
else if (auto E = isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
- std::string Buf;
- raw_string_ostream OS(Buf);
- logAllUnhandledErrors(ObjOrErr.takeError(), OS, "");
- OS.flush();
- reportError(UBinary->getFileName(), Buf);
+ reportError(UBinary->getFileName(), ObjOrErr.takeError());
}
else if (Expected<std::unique_ptr<Archive>> AOrErr = Obj.getAsArchive())
dumpArchive(&*AOrErr.get());
@@ -524,7 +509,7 @@ static void dumpInput(StringRef File) {
// Attempt to open the binary.
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
if (!BinaryOrErr)
- reportError(File, errorToErrorCode(BinaryOrErr.takeError()));
+ reportError(File, BinaryOrErr.takeError());
Binary &Binary = *BinaryOrErr.get().getBinary();
if (Archive *Arc = dyn_cast<Archive>(&Binary))
More information about the llvm-commits
mailing list