[llvm] aa123b8 - [llvm-readobj] Improve JSON output
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 09:43:07 PDT 2022
Author: Paul Kirth
Date: 2022-10-17T16:42:57Z
New Revision: aa123b8c096cc75100f7d87c9cfcc7afaa03cfd1
URL: https://github.com/llvm/llvm-project/commit/aa123b8c096cc75100f7d87c9cfcc7afaa03cfd1
DIFF: https://github.com/llvm/llvm-project/commit/aa123b8c096cc75100f7d87c9cfcc7afaa03cfd1.diff
LOG: [llvm-readobj] Improve JSON output
The current implementation outputs JSON in the following way:
[{'<filename>':{'FileSummary':{},...}}]
Using the filename as a key makes processing the JSON data awkward, and
should be avoided. This patch removes that outer key, since the
'FileSummary' data also includes a 'File' field, and so we lose no data.
Reviewed By: jhenderson, leonardchan
Differential Revision: https://reviews.llvm.org/D134843
Added:
Modified:
llvm/docs/ReleaseNotes.rst
llvm/test/tools/llvm-readobj/ELF/file-summary-json.test
llvm/test/tools/llvm-readobj/ELF/pretty-print.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 1c1d5d5736cd..95ccc06f496d 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -178,6 +178,14 @@ During this release ...
Changes to the LLVM tools
---------------------------------
+* ``llvm-readobj --elf-output-style=JSON`` no longer prefixes each JSON object
+ with the file name. Previously, each object file's output looked like
+ ``"main.o":{"FileSummary":{"File":"main.o"},...}`` but is now
+ ``{"FileSummary":{"File":"main.o"},...}``. This allows each JSON object to be
+ parsed in the same way, since each object no longer has a unique key. Tools
+ that consume ``llvm-readobj``'s JSON output should update their parsers
+ accordingly.
+
Changes to LLDB
---------------------------------
diff --git a/llvm/test/tools/llvm-readobj/ELF/file-summary-json.test b/llvm/test/tools/llvm-readobj/ELF/file-summary-json.test
index 7af0a0131413..458b94e0b94f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/file-summary-json.test
+++ b/llvm/test/tools/llvm-readobj/ELF/file-summary-json.test
@@ -11,14 +11,12 @@
# 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: "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:]
@@ -30,25 +28,21 @@
# 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: "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: "{{.*}}/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: "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:]
@@ -62,14 +56,12 @@
# 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: "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:]
@@ -83,25 +75,21 @@
# 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: "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: "{{.*}}.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: "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:]
diff --git a/llvm/test/tools/llvm-readobj/ELF/pretty-print.test b/llvm/test/tools/llvm-readobj/ELF/pretty-print.test
index 0f27db3992df..f729bfd519af 100644
--- a/llvm/test/tools/llvm-readobj/ELF/pretty-print.test
+++ b/llvm/test/tools/llvm-readobj/ELF/pretty-print.test
@@ -9,7 +9,6 @@
# 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",
@@ -18,7 +17,6 @@
# NO-PRETTY-SAME:"LoadName":"<Not found>"
# NO-PRETTY-SAME:}
# NO-PRETTY-SAME:}
-# NO-PRETTY-SAME:}
# NO-PRETTY-SAME:]
## Test JSON with pretty-print on.
@@ -28,14 +26,12 @@
# 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: "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:]
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index e6f87edd7152..7738efa3027c 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -7508,7 +7508,7 @@ template <class ELFT>
void JSONELFDumper<ELFT>::printFileSummary(StringRef FileStr, ObjectFile &Obj,
ArrayRef<std::string> InputFilenames,
const Archive *A) {
- FileScope = std::make_unique<DictScope>(this->W, FileStr);
+ FileScope = std::make_unique<DictScope>(this->W);
DictScope D(this->W, "FileSummary");
this->W.printString("File", FileStr);
this->W.printString("Format", Obj.getFileFormatName());
More information about the llvm-commits
mailing list