Skip to content

Commit 38e8187

Browse files
committed
[llvm-readobj] Fixes malformed json on JSON printed corefiles
This patch fixes an issue where, when printing corefile notes with llvm-readobj as json, the dumper generated llvm formatted output which isn't valid json. This alters the dumper to, in the NT_FILE, note use a JSON particular method and dump properly formatted json data. Prior to this patch the JSON output was formatted like: ``` "Mapping": [ "Start": 4096, "End": 8192, "Offset": 12288, "Filename": "/path/to/a.out" ], ... ``` Whereas now it is formatted as: ``` "Mappings": [ { "Start": 4096, "End": 8192, "Offset": 12288, "Filename": "/path/to/a.out" }, ... ``` Which is valid.
1 parent 50be0b1 commit 38e8187

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ Changes to the LLVM tools
238238
documented in `--help` output and the command guide. (`#90474
239239
<https://github.com/llvm/llvm-project/pull/90474>`)
240240

241+
* llvm-readobj's LLVM output has changed format for ELF core files. The
242+
NT_FILE note now has a map for the mapped files.
243+
(`#92835 <https://github.com/llvm/llvm-project/pull/92835>`).
244+
241245
Changes to LLDB
242246
---------------------------------
243247

llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# RUN: yaml2obj %s -o %t.o
44
# RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
55
# RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
6+
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print --notes %t.o | FileCheck %s --check-prefix=JSON
67

78
## llvm-mc doesn't support generating ET_CORE files; the 'Content' field was
89
## generated with the following steps:
@@ -72,24 +73,62 @@ ProgramHeaders:
7273
# LLVM-NEXT: Data size: 0x80
7374
# LLVM-NEXT: Type: NT_FILE (mapped files)
7475
# LLVM-NEXT: Page Size: 4096
75-
# LLVM-NEXT: Mapping [
76+
# LLVM-NEXT: Mappings [
77+
# LLVM-NEXT: {
7678
# LLVM-NEXT: Start: 0x1000
7779
# LLVM-NEXT: End: 0x2000
7880
# LLVM-NEXT: Offset: 0x3000
7981
# LLVM-NEXT: Filename: /path/to/a.out
80-
# LLVM-NEXT: ]
81-
# LLVM-NEXT: Mapping [
82+
# LLVM-NEXT: }
83+
# LLVM-NEXT: {
8284
# LLVM-NEXT: Start: 0x4000
8385
# LLVM-NEXT: End: 0x5000
8486
# LLVM-NEXT: Offset: 0x6000
8587
# LLVM-NEXT: Filename: /path/to/libc.so
86-
# LLVM-NEXT: ]
87-
# LLVM-NEXT: Mapping [
88+
# LLVM-NEXT: }
89+
# LLVM-NEXT: {
8890
# LLVM-NEXT: Start: 0x7000
8991
# LLVM-NEXT: End: 0x8000
9092
# LLVM-NEXT: Offset: 0x9000
9193
# LLVM-NEXT: Filename: [stack]
92-
# LLVM-NEXT: ]
93-
# LLVM-NEXT: }
94+
# LLVM-NEXT: }
95+
# LLVM-NEXT: ]
9496
# LLVM-NEXT: }
97+
# LLVM-NEXT: }
9598
# LLVM-NEXT: ]
99+
100+
# JSON: "Notes": [
101+
# JSON-NEXT: {
102+
# JSON-NEXT: "NoteSection": {
103+
# JSON-NEXT: "Name": "<?>",
104+
# JSON-NEXT: "Offset": 120,
105+
# JSON-NEXT: "Size": 148,
106+
# JSON-NEXT: "Note": {
107+
# JSON-NEXT: "Owner": "CORE",
108+
# JSON-NEXT: "Data size": 128,
109+
# JSON-NEXT: "Type": "NT_FILE (mapped files)",
110+
# JSON-NEXT: "Page Size": 4096,
111+
# JSON-NEXT: "Mappings": [
112+
# JSON-NEXT: {
113+
# JSON-NEXT: "Start": 4096,
114+
# JSON-NEXT: "End": 8192,
115+
# JSON-NEXT: "Offset": 12288,
116+
# JSON-NEXT: "Filename": "/path/to/a.out"
117+
# JSON-NEXT: },
118+
# JSON-NEXT: {
119+
# JSON-NEXT: "Start": 16384,
120+
# JSON-NEXT: "End": 20480,
121+
# JSON-NEXT: "Offset": 24576,
122+
# JSON-NEXT: "Filename": "/path/to/libc.so"
123+
# JSON-NEXT: },
124+
# JSON-NEXT: {
125+
# JSON-NEXT: "Start": 28672,
126+
# JSON-NEXT: "End": 32768,
127+
# JSON-NEXT: "Offset": 36864,
128+
# JSON-NEXT: "Filename": "[stack]"
129+
# JSON-NEXT: }
130+
# JSON-NEXT: ]
131+
# JSON-NEXT: }
132+
# JSON-NEXT: }
133+
# JSON-NEXT: }
134+
# JSON-NEXT: ]

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7840,8 +7840,9 @@ static bool printLLVMOMPOFFLOADNoteLLVMStyle(uint32_t NoteType,
78407840

78417841
static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) {
78427842
W.printNumber("Page Size", Note.PageSize);
7843+
ListScope D(W, "Mappings");
78437844
for (const CoreFileMapping &Mapping : Note.Mappings) {
7844-
ListScope D(W, "Mapping");
7845+
DictScope D(W);
78457846
W.printHex("Start", Mapping.Start);
78467847
W.printHex("End", Mapping.End);
78477848
W.printHex("Offset", Mapping.Offset);

0 commit comments

Comments
 (0)