diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -164,6 +164,9 @@ Changes to the LLVM tools --------------------------------- +* Made significant changes to JSON output format of `llvm-readobj`/`llvm-readelf` + to improve correctness and clarity. + Changes to LLDB --------------------------------- diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h --- a/llvm/include/llvm/Support/ScopedPrinter.h +++ b/llvm/include/llvm/Support/ScopedPrinter.h @@ -682,7 +682,7 @@ void printFlagsImpl(StringRef Label, HexNumber Value, ArrayRef Flags) override { JOS.attributeObject(Label, [&]() { - JOS.attribute("RawFlags", hexNumberToInt(Value)); + JOS.attribute("Value", hexNumberToInt(Value)); JOS.attributeArray("Flags", [&]() { for (const FlagEntry &Flag : Flags) { JOS.objectBegin(); @@ -697,7 +697,7 @@ void printFlagsImpl(StringRef Label, HexNumber Value, ArrayRef Flags) override { JOS.attributeObject(Label, [&]() { - JOS.attribute("RawFlags", hexNumberToInt(Value)); + JOS.attribute("Value", hexNumberToInt(Value)); JOS.attributeArray("Flags", [&]() { for (const HexNumber &Flag : Flags) { JOS.value(Flag.Value); @@ -728,8 +728,8 @@ void printHexImpl(StringRef Label, StringRef Str, HexNumber Value) override { JOS.attributeObject(Label, [&]() { - JOS.attribute("Value", Str); - JOS.attribute("RawValue", hexNumberToInt(Value)); + JOS.attribute("Name", Str); + JOS.attribute("Value", hexNumberToInt(Value)); }); } @@ -744,8 +744,8 @@ void printNumberImpl(StringRef Label, StringRef Str, StringRef Value) override { JOS.attributeObject(Label, [&]() { - JOS.attribute("Value", Str); - JOS.attributeBegin("RawValue"); + JOS.attribute("Name", Str); + JOS.attributeBegin("Value"); JOS.rawValueBegin() << Value; JOS.rawValueEnd(); JOS.attributeEnd(); diff --git a/llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test b/llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test --- a/llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test +++ b/llvm/test/tools/llvm-readobj/ELF/aarch64-symbols-stother.test @@ -29,9 +29,9 @@ # GNU-NEXT: 3: 0000000000000000 0 NOTYPE LOCAL PROTECTED [VARIANT_PCS] UND foo3 # GNU-NEXT: 4: 0000000000000000 0 NOTYPE LOCAL PROTECTED UND foo4 -# JSON: "Value": "foo1", +# JSON: "Name": "foo1", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 128, +# JSON-NEXT: "Value": 128, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STO_AARCH64_VARIANT_PCS", @@ -40,9 +40,9 @@ # JSON-NEXT: ] # JSON-NEXT:}, -# JSON: "Value": "foo2", +# JSON: "Name": "foo2", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 192, +# JSON-NEXT: "Value": 192, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STO_AARCH64_VARIANT_PCS", @@ -51,9 +51,9 @@ # JSON-NEXT: ] # JSON-NEXT:}, -# JSON: "Value": "foo3", +# JSON: "Name": "foo3", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 131, +# JSON-NEXT: "Value": 131, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STO_AARCH64_VARIANT_PCS", @@ -66,9 +66,9 @@ # JSON-NEXT: ] # JSON-NEXT:}, -# JSON: "Value": "foo4", +# JSON: "Name": "foo4", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 3, +# JSON-NEXT: "Value": 3, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STV_PROTECTED", diff --git a/llvm/test/tools/llvm-readobj/ELF/mips-symbols-stother.test b/llvm/test/tools/llvm-readobj/ELF/mips-symbols-stother.test --- a/llvm/test/tools/llvm-readobj/ELF/mips-symbols-stother.test +++ b/llvm/test/tools/llvm-readobj/ELF/mips-symbols-stother.test @@ -24,9 +24,9 @@ # MIPS-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT [] UND foo # MIPS-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT [] UND bar -# MIPS-JSON: "Value": "foo", +# MIPS-JSON: "Name": "foo", # MIPS-JSON: "Other": { -# MIPS-JSON-NEXT: "RawFlags": 172, +# MIPS-JSON-NEXT: "Value": 172, # MIPS-JSON-NEXT: "Flags": [ # MIPS-JSON-NEXT: { # MIPS-JSON-NEXT: "Name": "STO_MIPS_MICROMIPS", @@ -46,9 +46,9 @@ # MIPS-JSON-NEXT: } # MIPS-JSON-NEXT: ] # MIPS-JSON-NEXT: }, -# MIPS-JSON: "Value": "bar", +# MIPS-JSON: "Name": "bar", # MIPS-JSON: "Other": { -# MIPS-JSON-NEXT: "RawFlags": 240, +# MIPS-JSON-NEXT: "Value": 240, # MIPS-JSON-NEXT: "Flags": [ # MIPS-JSON-NEXT: { # MIPS-JSON-NEXT: "Name": "STO_MIPS_MIPS16", diff --git a/llvm/test/tools/llvm-readobj/ELF/relocations.test b/llvm/test/tools/llvm-readobj/ELF/relocations.test --- a/llvm/test/tools/llvm-readobj/ELF/relocations.test +++ b/llvm/test/tools/llvm-readobj/ELF/relocations.test @@ -120,12 +120,12 @@ # JSON-EXPAND-64: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 0, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_NONE", -# JSON-EXPAND-64-NEXT: "RawValue": 0 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_NONE", +# JSON-EXPAND-64-NEXT: "Value": 0 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rel_0", -# JSON-EXPAND-64-NEXT: "RawValue": 1 +# JSON-EXPAND-64-NEXT: "Name": "rel_0", +# JSON-EXPAND-64-NEXT: "Value": 1 # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: }, @@ -133,12 +133,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 1, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_PC32", -# JSON-EXPAND-64-NEXT: "RawValue": 2 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PC32", +# JSON-EXPAND-64-NEXT: "Value": 2 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rel_neg", -# JSON-EXPAND-64-NEXT: "RawValue": 2 +# JSON-EXPAND-64-NEXT: "Name": "rel_neg", +# JSON-EXPAND-64-NEXT: "Value": 2 # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: }, @@ -146,12 +146,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 5, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_PLT32", -# JSON-EXPAND-64-NEXT: "RawValue": 4 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PLT32", +# JSON-EXPAND-64-NEXT: "Value": 4 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rel_pos", -# JSON-EXPAND-64-NEXT: "RawValue": 3 +# JSON-EXPAND-64-NEXT: "Name": "rel_pos", +# JSON-EXPAND-64-NEXT: "Value": 3 # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: }, @@ -159,12 +159,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 9, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_64", -# JSON-EXPAND-64-NEXT: "RawValue": 1 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_64", +# JSON-EXPAND-64-NEXT: "Value": 1 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rel_64", -# JSON-EXPAND-64-NEXT: "RawValue": 4 +# JSON-EXPAND-64-NEXT: "Name": "rel_64", +# JSON-EXPAND-64-NEXT: "Value": 4 # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: } # JSON-EXPAND-64-NEXT: }} @@ -174,12 +174,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 0, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_NONE", -# JSON-EXPAND-64-NEXT: "RawValue": 0 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_NONE", +# JSON-EXPAND-64-NEXT: "Value": 0 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rela_0", -# JSON-EXPAND-64-NEXT: "RawValue": 5 +# JSON-EXPAND-64-NEXT: "Name": "rela_0", +# JSON-EXPAND-64-NEXT: "Value": 5 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Addend": 0 # JSON-EXPAND-64-NEXT: } @@ -188,12 +188,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 1, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_PC32", -# JSON-EXPAND-64-NEXT: "RawValue": 2 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PC32", +# JSON-EXPAND-64-NEXT: "Value": 2 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rela_neg", -# JSON-EXPAND-64-NEXT: "RawValue": 6 +# JSON-EXPAND-64-NEXT: "Name": "rela_neg", +# JSON-EXPAND-64-NEXT: "Value": 6 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Addend": 18446744073709551615 # JSON-EXPAND-64-NEXT: } @@ -202,12 +202,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 5, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_PLT32", -# JSON-EXPAND-64-NEXT: "RawValue": 4 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PLT32", +# JSON-EXPAND-64-NEXT: "Value": 4 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rela_pos", -# JSON-EXPAND-64-NEXT: "RawValue": 7 +# JSON-EXPAND-64-NEXT: "Name": "rela_pos", +# JSON-EXPAND-64-NEXT: "Value": 7 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Addend": 2 # JSON-EXPAND-64-NEXT: } @@ -216,12 +216,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 18446744073709551615, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_64", -# JSON-EXPAND-64-NEXT: "RawValue": 1 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_64", +# JSON-EXPAND-64-NEXT: "Value": 1 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rela_minneg", -# JSON-EXPAND-64-NEXT: "RawValue": 8 +# JSON-EXPAND-64-NEXT: "Name": "rela_minneg", +# JSON-EXPAND-64-NEXT: "Value": 8 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Addend": 9223372036854775808 # JSON-EXPAND-64-NEXT: } @@ -230,12 +230,12 @@ # JSON-EXPAND-64-NEXT: "Relocation": { # JSON-EXPAND-64-NEXT: "Offset": 9, # JSON-EXPAND-64-NEXT: "Type": { -# JSON-EXPAND-64-NEXT: "Value": "R_X86_64_32S", -# JSON-EXPAND-64-NEXT: "RawValue": 11 +# JSON-EXPAND-64-NEXT: "Name": "R_X86_64_32S", +# JSON-EXPAND-64-NEXT: "Value": 11 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Symbol": { -# JSON-EXPAND-64-NEXT: "Value": "rela_maxpos", -# JSON-EXPAND-64-NEXT: "RawValue": 9 +# JSON-EXPAND-64-NEXT: "Name": "rela_maxpos", +# JSON-EXPAND-64-NEXT: "Value": 9 # JSON-EXPAND-64-NEXT: }, # JSON-EXPAND-64-NEXT: "Addend": 9223372036854775807 # JSON-EXPAND-64-NEXT: } diff --git a/llvm/test/tools/llvm-readobj/ELF/symbol-visibility.test b/llvm/test/tools/llvm-readobj/ELF/symbol-visibility.test --- a/llvm/test/tools/llvm-readobj/ELF/symbol-visibility.test +++ b/llvm/test/tools/llvm-readobj/ELF/symbol-visibility.test @@ -31,15 +31,15 @@ # GNU-NEXT: HIDDEN UND hidden # GNU-NEXT: PROTECTED UND protected -# JSON: "Value": "default", +# JSON: "Name": "default", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 0, +# JSON-NEXT: "Value": 0, # JSON-NEXT: "Flags": [] # JSON-NEXT: }, -# JSON: "Value": "internal", +# JSON: "Name": "internal", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 1, +# JSON-NEXT: "Value": 1, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STV_INTERNAL", @@ -48,9 +48,9 @@ # JSON-NEXT: ] # JSON-NEXT: }, -# JSON: "Value": "hidden", +# JSON: "Name": "hidden", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 2, +# JSON-NEXT: "Value": 2, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STV_HIDDEN", @@ -59,9 +59,9 @@ # JSON-NEXT: ] # JSON-NEXT: }, -# JSON: "Value": "protected", +# JSON: "Name": "protected", # JSON: "Other": { -# JSON-NEXT: "RawFlags": 3, +# JSON-NEXT: "Value": 3, # JSON-NEXT: "Flags": [ # JSON-NEXT: { # JSON-NEXT: "Name": "STV_PROTECTED", diff --git a/llvm/unittests/Support/ScopedPrinterTest.cpp b/llvm/unittests/Support/ScopedPrinterTest.cpp --- a/llvm/unittests/Support/ScopedPrinterTest.cpp +++ b/llvm/unittests/Support/ScopedPrinterTest.cpp @@ -236,8 +236,8 @@ const char *JSONExpectedOut = R"({ "Exists": { - "Value": "Name2", - "RawValue": 2 + "Name": "Name2", + "Value": 2 }, "DoesNotExist": 5 })"; @@ -345,15 +345,15 @@ const char *JSONExpectedOut = R"({ "ZeroFlag": { - "RawFlags": 0, + "Value": 0, "Flags": [] }, "NoFlag": { - "RawFlags": 8, + "Value": 8, "Flags": [] }, "Flag1": { - "RawFlags": 1, + "Value": 1, "Flags": [ { "Name": "Name1", @@ -362,7 +362,7 @@ ] }, "Flag1&3": { - "RawFlags": 5, + "Value": 5, "Flags": [ { "Name": "Name1", @@ -375,30 +375,30 @@ ] }, "ZeroFlagRaw": { - "RawFlags": 0, + "Value": 0, "Flags": [] }, "NoFlagRaw": { - "RawFlags": 8, + "Value": 8, "Flags": [ 8 ] }, "Flag1Raw": { - "RawFlags": 1, + "Value": 1, "Flags": [ 1 ] }, "Flag1&3Raw": { - "RawFlags": 5, + "Value": 5, "Flags": [ 1, 4 ] }, "FlagSorted": { - "RawFlags": 7, + "Value": 7, "Flags": [ { "Name": "A", @@ -415,7 +415,7 @@ ] }, "NoBitMask": { - "RawFlags": 4095, + "Value": 4095, "Flags": [ { "Name": "FirstByte1", @@ -456,7 +456,7 @@ ] }, "FirstByteMask": { - "RawFlags": 3, + "Value": 3, "Flags": [ { "Name": "FirstByte3", @@ -465,7 +465,7 @@ ] }, "SecondByteMask": { - "RawFlags": 48, + "Value": 48, "Flags": [ { "Name": "SecondByte3", @@ -474,7 +474,7 @@ ] }, "ValueOutsideMask": { - "RawFlags": 1, + "Value": 1, "Flags": [ { "Name": "FirstByte1", @@ -483,11 +483,11 @@ ] }, "FirstSecondByteMask": { - "RawFlags": 255, + "Value": 255, "Flags": [] }, "FirstSecondThirdByteMask": { - "RawFlags": 819, + "Value": 819, "Flags": [ { "Name": "FirstByte3", @@ -594,8 +594,8 @@ "int8_t-min": -128, "apsint": 9999999999999999999999, "label": { - "Value": "value", - "RawValue": 0 + "Name": "value", + "Value": 0 } })"; verifyAll(ExpectedOut, JSONExpectedOut, PrintFunc); @@ -761,8 +761,8 @@ const char *JSONExpectedOut = R"({ "HexNumber": 16, "HexLabel": { - "Value": "Name", - "RawValue": 16 + "Name": "Name", + "Value": 16 } })"; verifyAll(ExpectedOut, JSONExpectedOut, PrintFunc);