llvm.org GIT mirror llvm / b856c16
obj2yaml: Improve error reporting Previously only the error codes were reported which meant that useful information about malformed inputs was not shown. Differential Revision: https://reviews.llvm.org/D34008 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305609 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Clegg 2 years ago
4 changed file(s) with 24 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
477477 ELF-X86-64-UNWIND-NEXT: Content: ''
478478
479479 RUN: not obj2yaml %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
480 ENOENT: Error: '{{[Nn]}}o such file or directory'
480 ENOENT: Error reading file: {{.*}}.blah: {{[Nn]}}o such file or directory
22 FileHeader:
33 Version: 0x00000002
44 ...
5 # CHECK: Error: 'Invalid data was encountered while parsing the file'
5 # CHECK: Error reading file: : Bad version number
0 # RUN: not obj2yaml %p/path/does/not/exist 2>&1 | FileCheck %s
1
2 # Don't check the OS-dependent message "No such file or directory".
3 # CHECK: Error reading file: {{.*}}/path/does/not/exist: {{.*}}
2929 return obj2yaml_error::unsupported_obj_file_format;
3030 }
3131
32 static std::error_code dumpInput(StringRef File) {
32 static Error dumpInput(StringRef File) {
3333 Expected> BinaryOrErr = createBinary(File);
3434 if (!BinaryOrErr)
35 return errorToErrorCode(BinaryOrErr.takeError());
35 return BinaryOrErr.takeError();
3636
3737 Binary &Binary = *BinaryOrErr.get().getBinary();
3838 // Universal MachO is not a subclass of ObjectFile, so it needs to be handled
3939 // here with the other binary types.
4040 if (Binary.isMachO() || Binary.isMachOUniversalBinary())
41 return macho2yaml(outs(), Binary);
41 return errorCodeToError(macho2yaml(outs(), Binary));
4242 // TODO: If this is an archive, then burst it and dump each entry
4343 if (ObjectFile *Obj = dyn_cast(&Binary))
44 return dumpObject(*Obj);
44 return errorCodeToError(dumpObject(*Obj));
4545
46 return obj2yaml_error::unrecognized_file_format;
46 return Error::success();
47 }
48
49 static void reportError(StringRef Input, Error Err) {
50 if (Input == "-")
51 Input = "";
52 std::string ErrMsg;
53 raw_string_ostream OS(ErrMsg);
54 logAllUnhandledErrors(std::move(Err), OS, "");
55 OS.flush();
56 errs() << "Error reading file: " << Input << ": " << ErrMsg;
57 errs().flush();
4758 }
4859
4960 cl::opt InputFilename(cl::Positional, cl::desc(""),
5566 PrettyStackTraceProgram X(argc, argv);
5667 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
5768
58 if (std::error_code EC = dumpInput(InputFilename)) {
59 errs() << "Error: '" << EC.message() << "'\n";
69 if (Error Err = dumpInput(InputFilename)) {
70 reportError(InputFilename, std::move(Err));
6071 return 1;
6172 }
6273