George Rimar e3fb2d549b Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API."
Fix: Add a `consumeError` call removed by mistake to 'printStackSize',
this should fix the "Expected<T> must be checked before access or destruction." reported by following bot:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio

Original commit message:
Currently we have the following functions for error reporting:

LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportError(Error Err, StringRef Input); 
void reportWarning(Twine Msg);
void reportWarning(StringRef Input, Error Err);
void warn(llvm::Error Err);
void error(std::error_code EC);

Problems are: naming is inconsistent, arguments order is inconsistent,
some of the functions looks excessive.

After applying this patch we have:

void reportError(Error Err, StringRef Input); 
void reportError(std::error_code EC, StringRef Input);
void reportWarning(Error Err, StringRef Input);

I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it
is used by COFF heavily.

Test cases were updated, they show an improvement introduced.

Differential revision: https://reviews.llvm.org/D66286

llvm-svn: 369194
2019-08-17 16:07:18 +00:00

60 lines
2.9 KiB
Plaintext

## Test that the -x alias can be used flexibly. Create a baseline and ensure
## all other combinations are identical.
# RUN: llvm-readelf --file-header --hex-dump=.text \
# RUN: %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.out
# RUN: llvm-readelf -h --hex-dump .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.1
# RUN: llvm-readelf -h -x .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.2
# RUN: llvm-readelf -h -x=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.3
# RUN: llvm-readelf -h -x.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.4
# RUN: llvm-readelf -hx .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.5
# RUN: llvm-readelf -hx=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.6
# RUN: llvm-readelf -hx.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.7
# RUN: cmp %t.hexdump.out %t.hexdump.1
# RUN: cmp %t.hexdump.out %t.hexdump.2
# RUN: cmp %t.hexdump.out %t.hexdump.3
# RUN: cmp %t.hexdump.out %t.hexdump.4
# RUN: cmp %t.hexdump.out %t.hexdump.5
# RUN: cmp %t.hexdump.out %t.hexdump.6
# RUN: cmp %t.hexdump.out %t.hexdump.7
# RUN: llvm-readelf -S %p/Inputs/trivial.obj.elf-x86-64 | FileCheck %s --check-prefix=ELF-SEC
## Both 9 and .strtab refer to .strtab. Test we dump the section only once.
# RUN: llvm-readobj -x 9 -x 9 -x .strtab -x .strtab %p/Inputs/trivial.obj.elf-x86-64 2>&1 | \
# RUN: FileCheck %s --check-prefix=ELF
# RUN: llvm-readobj -x 9 -x .strtab -x 10 -x not_exist \
# RUN: %p/Inputs/trivial.obj.elf-x86-64 2>&1 | FileCheck %s -DFILE=%p/Inputs/trivial.obj.elf-x86-64 --check-prefixes=ELF-WARN,ELF
# ELF-SEC: [ 9] .strtab
# ELF-WARN: warning: '[[FILE]]': could not find section 'not_exist'
# ELF-WARN: warning: '[[FILE]]': could not find section 10
# ELF: Hex dump of section '.strtab':
# ELF-NEXT: 0x00000000 00747269 7669616c 2e6c6c00 6d61696e .trivial.ll.main
# ELF-NEXT: 0x00000010 002e4c2e 73747200 70757473 00536f6d ..L.str.puts.Som
# ELF-NEXT: 0x00000020 654f7468 65724675 6e637469 6f6e005f eOtherFunction._
# ELF-NEXT: 0x00000030 474c4f42 414c5f4f 46465345 545f5441 GLOBAL_OFFSET_TA
# ELF-NEXT: 0x00000040 424c455f 00 BLE_.
# ELF-NOT: {{.}}
## Below we test -x can be used for other binary formats.
# RUN: llvm-readobj -x 1 %p/Inputs/trivial.obj.coff-x86-64 \
# RUN: | FileCheck %s --check-prefix COFF
# COFF: 0x00000000 4883ec28 488d0d00 000000e8 00000000 H..(H...........
# COFF: 0x00000010 e8000000 0031c048 83c428c3 .....1.H..(.
# RUN: llvm-readobj -x 1 %p/Inputs/trivial.obj.macho-x86-64 \
# RUN: | FileCheck %s --check-prefix MACHO
# MACHO: 0x00000000 50488d3d 00000000 e8000000 00e80000 PH.=............
# MACHO: 0x00000010 000031c0 5ac3 ..1.Z.
# RUN: llvm-readobj -x 1 %p/Inputs/trivial.obj.wasm \
# RUN: | FileCheck %s --check-prefix WASM
# WASM: 0x00000000 04600001 7f60017f 017f6000 0060017f .`...`....`..`..
# WASM: 0x00000010 00 .