Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-readobj] Fixes malformed json on JSON printed corefiles #92835

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ Changes to the LLVM tools
documented in `--help` output and the command guide. (`#90474
<https://github.com/llvm/llvm-project/pull/90474>`)

* llvm-readobj's LLVM output format for ELF core files has been changed.
Similarly, the JSON format has been fixed for this case. The NT_FILE note
now has a map for the mapped files. (`#92835
<https://github.com/llvm/llvm-project/pull/92835>`).

Changes to LLDB
---------------------------------

Expand Down
53 changes: 46 additions & 7 deletions llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM
# RUN: llvm-readobj --elf-output-style=JSON --pretty-print --notes %t.o | FileCheck %s --check-prefix=JSON

## llvm-mc doesn't support generating ET_CORE files; the 'Content' field was
## generated with the following steps:
Expand Down Expand Up @@ -72,24 +73,62 @@ ProgramHeaders:
# LLVM-NEXT: Data size: 0x80
# LLVM-NEXT: Type: NT_FILE (mapped files)
# LLVM-NEXT: Page Size: 4096
# LLVM-NEXT: Mapping [
# LLVM-NEXT: Mappings [
# LLVM-NEXT: {
# LLVM-NEXT: Start: 0x1000
# LLVM-NEXT: End: 0x2000
# LLVM-NEXT: Offset: 0x3000
# LLVM-NEXT: Filename: /path/to/a.out
# LLVM-NEXT: ]
# LLVM-NEXT: Mapping [
# LLVM-NEXT: }
# LLVM-NEXT: {
# LLVM-NEXT: Start: 0x4000
# LLVM-NEXT: End: 0x5000
# LLVM-NEXT: Offset: 0x6000
# LLVM-NEXT: Filename: /path/to/libc.so
# LLVM-NEXT: ]
# LLVM-NEXT: Mapping [
# LLVM-NEXT: }
# LLVM-NEXT: {
# LLVM-NEXT: Start: 0x7000
# LLVM-NEXT: End: 0x8000
# LLVM-NEXT: Offset: 0x9000
# LLVM-NEXT: Filename: [stack]
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: ]
# LLVM-NEXT: }
# LLVM-NEXT: }
# LLVM-NEXT: ]

# JSON: "Notes": [
# JSON-NEXT: {
# JSON-NEXT: "NoteSection": {
# JSON-NEXT: "Name": "<?>",
# JSON-NEXT: "Offset": 120,
# JSON-NEXT: "Size": 148,
# JSON-NEXT: "Note": {
# JSON-NEXT: "Owner": "CORE",
# JSON-NEXT: "Data size": 128,
# JSON-NEXT: "Type": "NT_FILE (mapped files)",
# JSON-NEXT: "Page Size": 4096,
# JSON-NEXT: "Mappings": [
# JSON-NEXT: {
# JSON-NEXT: "Start": 4096,
# JSON-NEXT: "End": 8192,
# JSON-NEXT: "Offset": 12288,
# JSON-NEXT: "Filename": "/path/to/a.out"
# JSON-NEXT: },
# JSON-NEXT: {
# JSON-NEXT: "Start": 16384,
# JSON-NEXT: "End": 20480,
# JSON-NEXT: "Offset": 24576,
# JSON-NEXT: "Filename": "/path/to/libc.so"
# JSON-NEXT: },
# JSON-NEXT: {
# JSON-NEXT: "Start": 28672,
# JSON-NEXT: "End": 32768,
# JSON-NEXT: "Offset": 36864,
# JSON-NEXT: "Filename": "[stack]"
# JSON-NEXT: }
# JSON-NEXT: ]
# JSON-NEXT: }
# JSON-NEXT: }
# JSON-NEXT: }
# JSON-NEXT: ]
3 changes: 2 additions & 1 deletion llvm/tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7840,8 +7840,9 @@ static bool printLLVMOMPOFFLOADNoteLLVMStyle(uint32_t NoteType,

static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) {
W.printNumber("Page Size", Note.PageSize);
ListScope D(W, "Mappings");
for (const CoreFileMapping &Mapping : Note.Mappings) {
ListScope D(W, "Mapping");
DictScope D(W);
W.printHex("Start", Mapping.Start);
W.printHex("End", Mapping.End);
W.printHex("Offset", Mapping.Offset);
Expand Down
Loading