Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-readobj] Add JSONScopedPrinter to llvm-readelf
Adds JSONScopedPrinter to llvm-readelf. It includes an empty JSONELFDumper class which will be used to override any LLVMELFDumper methods which utilize startLine() which JSONScopedPrinter cannot provide. This introduces a change where calls to llvm-readelf with non-ELF object files that specify --elf-output-style=GNU will now print file summary information where it previously didn't. Fixes previous Windows test failure which occured due to JSON escaping of '\' by not relying on LIT substitution. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D114225
- Loading branch information
Showing
11 changed files
with
276 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
llvm/test/tools/llvm-readobj/ELF/file-summary-json.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
## Test how we output JSON file summaries. | ||
|
||
# RUN: rm -rf %t.dir | ||
# RUN: mkdir -p %t.dir | ||
# RUN: yaml2obj %s -o %t.dir/obj | ||
|
||
## Test outputting file summary for a single file. | ||
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print %t.dir/obj | \ | ||
# RUN: FileCheck %s --check-prefix=SINGLE \ | ||
# RUN: --match-full-lines --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# SINGLE:[ | ||
# SINGLE-NEXT: { | ||
# SINGLE-NEXT: "{{.*}}/obj": { | ||
# SINGLE-NEXT: "FileSummary": { | ||
# SINGLE-NEXT: "File": "{{.*}}/obj", | ||
# SINGLE-NEXT: "Format": "elf64-x86-64", | ||
# SINGLE-NEXT: "Arch": "x86_64", | ||
# SINGLE-NEXT: "AddressSize": "64bit", | ||
# SINGLE-NEXT: "LoadName": "<Not found>" | ||
# SINGLE-NEXT: } | ||
# SINGLE-NEXT: } | ||
# SINGLE-NEXT: } | ||
# SINGLE-NEXT:] | ||
|
||
## Test outputting file summary for multiple files. | ||
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print %t.dir/obj %t.dir/obj | \ | ||
# RUN: FileCheck %s --check-prefix=MULTI \ | ||
# RUN: --match-full-lines --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# MULTI:[ | ||
# MULTI-NEXT: { | ||
# MULTI-NEXT: "{{.*}}/obj": { | ||
# MULTI-NEXT: "FileSummary": { | ||
# MULTI-NEXT: "File": "{{.*}}/obj", | ||
# MULTI-NEXT: "Format": "elf64-x86-64", | ||
# MULTI-NEXT: "Arch": "x86_64", | ||
# MULTI-NEXT: "AddressSize": "64bit", | ||
# MULTI-NEXT: "LoadName": "<Not found>" | ||
# MULTI-NEXT: } | ||
# MULTI-NEXT: } | ||
# MULTI-NEXT: }, | ||
# MULTI-NEXT: { | ||
# MULTI-NEXT: "{{.*}}/obj": { | ||
# MULTI-NEXT: "FileSummary": { | ||
# MULTI-NEXT: "File": "{{.*}}/obj", | ||
# MULTI-NEXT: "Format": "elf64-x86-64", | ||
# MULTI-NEXT: "Arch": "x86_64", | ||
# MULTI-NEXT: "AddressSize": "64bit", | ||
# MULTI-NEXT: "LoadName": "<Not found>" | ||
# MULTI-NEXT: } | ||
# MULTI-NEXT: } | ||
# MULTI-NEXT: } | ||
# MULTI-NEXT:] | ||
|
||
## Test outputting file summary for an archive with a single file. | ||
# RUN: rm -f %t.archive-single | ||
# RUN: llvm-ar rc %t.archive-single %t.dir/obj | ||
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print %t.archive-single | \ | ||
# RUN: FileCheck %s --check-prefix=ARCH-SINGLE \ | ||
# RUN: --match-full-lines --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# ARCH-SINGLE:[ | ||
# ARCH-SINGLE-NEXT: { | ||
# ARCH-SINGLE-NEXT: "{{.*}}.archive-single(obj)": { | ||
# ARCH-SINGLE-NEXT: "FileSummary": { | ||
# ARCH-SINGLE-NEXT: "File": "{{.*}}.archive-single(obj)", | ||
# ARCH-SINGLE-NEXT: "Format": "elf64-x86-64", | ||
# ARCH-SINGLE-NEXT: "Arch": "x86_64", | ||
# ARCH-SINGLE-NEXT: "AddressSize": "64bit", | ||
# ARCH-SINGLE-NEXT: "LoadName": "<Not found>" | ||
# ARCH-SINGLE-NEXT: } | ||
# ARCH-SINGLE-NEXT: } | ||
# ARCH-SINGLE-NEXT: } | ||
# ARCH-SINGLE-NEXT:] | ||
|
||
## Test outputting file summary for an archive with multiple files. | ||
# RUN: rm -f %t.archive-multiple | ||
# RUN: llvm-ar rc %t.archive-multiple %t.dir/obj %t.dir/obj | ||
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print %t.archive-multiple | \ | ||
# RUN: FileCheck %s --check-prefix=ARCH-MULTI \ | ||
# RUN: --match-full-lines --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# ARCH-MULTI:[ | ||
# ARCH-MULTI-NEXT: { | ||
# ARCH-MULTI-NEXT: "{{.*}}.archive-multiple(obj)": { | ||
# ARCH-MULTI-NEXT: "FileSummary": { | ||
# ARCH-MULTI-NEXT: "File": "{{.*}}.archive-multiple(obj)", | ||
# ARCH-MULTI-NEXT: "Format": "elf64-x86-64", | ||
# ARCH-MULTI-NEXT: "Arch": "x86_64", | ||
# ARCH-MULTI-NEXT: "AddressSize": "64bit", | ||
# ARCH-MULTI-NEXT: "LoadName": "<Not found>" | ||
# ARCH-MULTI-NEXT: } | ||
# ARCH-MULTI-NEXT: } | ||
# ARCH-MULTI-NEXT: }, | ||
# ARCH-MULTI-NEXT: { | ||
# ARCH-MULTI-NEXT: "{{.*}}.archive-multiple(obj)": { | ||
# ARCH-MULTI-NEXT: "FileSummary": { | ||
# ARCH-MULTI-NEXT: "File": "{{.*}}.archive-multiple(obj)", | ||
# ARCH-MULTI-NEXT: "Format": "elf64-x86-64", | ||
# ARCH-MULTI-NEXT: "Arch": "x86_64", | ||
# ARCH-MULTI-NEXT: "AddressSize": "64bit", | ||
# ARCH-MULTI-NEXT: "LoadName": "<Not found>" | ||
# ARCH-MULTI-NEXT: } | ||
# ARCH-MULTI-NEXT: } | ||
# ARCH-MULTI-NEXT: } | ||
# ARCH-MULTI-NEXT:] | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## Error for an unknown output style. | ||
RUN: not llvm-readobj --elf-output-style=unknown 2>&1 | FileCheck %s | ||
|
||
CHECK: error: --elf-output-style value should be either 'LLVM' or 'GNU' | ||
CHECK: error: --elf-output-style value should be either 'LLVM', 'GNU', or 'JSON', but was 'unknown' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Test the JSON pretty-print flag. | ||
# | ||
# RUN: yaml2obj %s -o %t.pretty | ||
|
||
## Test JSON with pretty-print off. | ||
# RUN: llvm-readobj --elf-output-style=JSON %t.pretty | \ | ||
# RUN: FileCheck %s --check-prefix=NO-PRETTY \ | ||
# RUN: --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# NO-PRETTY:[ | ||
# NO-PRETTY-SAME:{ | ||
# NO-PRETTY-SAME:"{{.*}}.pretty":{ | ||
# NO-PRETTY-SAME:"FileSummary":{ | ||
# NO-PRETTY-SAME:"File":"{{.*}}.pretty", | ||
# NO-PRETTY-SAME:"Format":"elf64-x86-64", | ||
# NO-PRETTY-SAME:"Arch":"x86_64", | ||
# NO-PRETTY-SAME:"AddressSize":"64bit", | ||
# NO-PRETTY-SAME:"LoadName":"<Not found>" | ||
# NO-PRETTY-SAME:} | ||
# NO-PRETTY-SAME:} | ||
# NO-PRETTY-SAME:} | ||
# NO-PRETTY-SAME:] | ||
|
||
## Test JSON with pretty-print on. | ||
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print %t.pretty | \ | ||
# RUN: FileCheck %s --check-prefix=PRETTY \ | ||
# RUN: --match-full-lines --strict-whitespace --implicit-check-not={{.}} | ||
|
||
# PRETTY:[ | ||
# PRETTY-NEXT: { | ||
# PRETTY-NEXT: "{{.*}}.pretty": { | ||
# PRETTY-NEXT: "FileSummary": { | ||
# PRETTY-NEXT: "File": "{{.*}}.pretty", | ||
# PRETTY-NEXT: "Format": "elf64-x86-64", | ||
# PRETTY-NEXT: "Arch": "x86_64", | ||
# PRETTY-NEXT: "AddressSize": "64bit", | ||
# PRETTY-NEXT: "LoadName": "<Not found>" | ||
# PRETTY-NEXT: } | ||
# PRETTY-NEXT: } | ||
# PRETTY-NEXT: } | ||
# PRETTY-NEXT:] | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.