[llvm-readelf] Print a blank line for the first hex/string dump

GNU readelf prints a blank line before the first hex/string dump, which
serves as a separator when there are other dump operations. Port the
behavior.

Pull Request: https://github.com/llvm/llvm-project/pull/85744
This commit is contained in:
Fangrui Song 2024-03-19 09:38:55 -07:00 committed by GitHub
parent e59f120e3a
commit 24f22b3f93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 26 additions and 21 deletions

View File

@ -13,6 +13,7 @@
// RELA-NEXT: 0x[[#ADDR+16]] R_AARCH64_TLSDESC - 0x4
// RELA-NEXT: }
// RELA-NEXT: ]
// RELA-EMPTY:
// RELA-NEXT: Hex dump of section '.got':
// RELA-NEXT: 0x000[[#ADDR]] 00000000 00000000 00000000 00000000
// RELA-NO-ADDENDS-NEXT: 0x000[[#ADDR+16]] 00000000 00000000 00000000 00000000

View File

@ -353,6 +353,7 @@
// RELR64-NEXT: 0000000000030550 0000000000000403 R_AARCH64_RELATIVE
// RELR64-NEXT: 0000000000030558 0000000000000403 R_AARCH64_RELATIVE
// RELR64-NEXT: 0000000000030560 0000000000000403 R_AARCH64_RELATIVE
// RELR64-EMPTY:
// RELR64-NEXT: Hex dump of section '.data':
// RELR64-NEXT: 0x00030490 00000000 00000000 01000000 00000000 .
// RELR64-NEXT: 0x000304a0 02000000 00000000 ffffffff ffffffff .

View File

@ -10,6 +10,7 @@
# CHECK-NEXT: [ 18] x.c.
# CHECK-NEXT: [ 1e] .
# CHECK-NEXT: [ 20] .
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time
# CHECK-NEXT: 0x00000000 01000000 00000000 01000000 00000000 ................

View File

@ -28,6 +28,7 @@
# COMPRESSED: String dump of section '.not_null_terminated':
# COMPRESSED-NEXT: [ 0] no
# COMPRESSED-NEXT: [ 3] null
# COMPRESSED-EMPTY:
# COMPRESSED-NEXT: Hex dump of section '.strings':
# COMPRESSED-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................
# COMPRESSED-NEXT: 0x00000010 00000000 00000000 789ccb48 2d4a6548 ........x..H-JeH
@ -39,6 +40,7 @@
# INVALID: String dump of section '.invalid1':
# INVALID-NEXT: warning: '[[FILE]]': corrupted compressed section header
# INVALID-NEXT: [ 0] .
# INVALID-EMPTY:
# INVALID-NEXT: Hex dump of section '.invalid2':
# INVALID-NEXT: warning: '[[FILE]]': zlib error: Z_DATA_ERROR
# INVALID-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................

View File

@ -9,6 +9,7 @@
# CHECK-NEXT: [ 10] .
# CHECK-NEXT: [ 18] (./. ..
# CHECK-NEXT: [ 21] .
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at build time
# CHECK-NEXT: 0x00000000 02000000 00000000 01000000 00000000 ................

View File

@ -1,10 +1,12 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -filetype=obj -triple x86_64 %s -o %t.o
# RUN: llvm-readobj -x .a -x .b %t.o | FileCheck %s
# RUN: llvm-readobj -x .a -x .b %t.o | FileCheck %s --check-prefixes=HEADER,CHECK
# RUN: llvm-readelf -x .a -x .b %t.o | FileCheck %s
# CHECK: Hex dump of section '.a':
# HEADER: LoadName:
# CHECK: {{^$}}
# CHECK-NEXT: Hex dump of section '.a':
# CHECK-NEXT: 0x00000000 00
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':

View File

@ -46,7 +46,8 @@ FileHeader:
# RUN: llvm-readelf --hex-dump=.sec %t2.out1 | \
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES1
# SPACES1:Hex dump of section '.sec':
# SPACES1:{{^$}}
# SPACES1-NEXT:Hex dump of section '.sec':
# SPACES1-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES1-NEXT:0x00000010 0000 ..
@ -55,7 +56,8 @@ FileHeader:
# RUN: llvm-readelf --hex-dump=.sec %t2.out2 | \
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES2
# SPACES2:Hex dump of section '.sec':
# SPACES2:{{^$}}
# SPACES2-NEXT:Hex dump of section '.sec':
# SPACES2-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES2-NEXT:0x00000010 00000000 00000000 00000000 0000 ..............
@ -64,7 +66,8 @@ FileHeader:
# RUN: llvm-readelf --hex-dump=.sec %t2.out3 | \
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES3
# SPACES3:Hex dump of section '.sec':
# SPACES3:{{^$}}
# SPACES3-NEXT:Hex dump of section '.sec':
# SPACES3-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES3-NEXT:0x00000010 00000000 00000000 00000000 ............

View File

@ -1,10 +1,12 @@
# REQUIRES: x86-registered-target
# RUN: llvm-mc -filetype=obj -triple x86_64 %s -o %t.o
# RUN: llvm-readobj -p .a -p .b %t.o | FileCheck %s
# RUN: llvm-readobj -p .a -p .b %t.o | FileCheck %s --check-prefixes=HEADER,CHECK
# RUN: llvm-readelf -p .a -p .b %t.o | FileCheck %s
# CHECK: String dump of section '.a':
# HEADER: LoadName:
# CHECK: {{^$}}
# CHECK-NEXT: String dump of section '.a':
# CHECK-NEXT: [ 0] 0
# CHECK-EMPTY:
# CHECK-NEXT: String dump of section '.b':

View File

@ -3,7 +3,7 @@
# RUN: llvm-readobj --string-dump=.strings \
# RUN: --string-dump=.not_null_terminated %t > %t.readobj.out
# RUN: FileCheck %s --input-file=%t.readobj.out
# RUN: FileCheck %s --input-file=%t.readobj.out --check-prefixes=HEADER,CHECK
# Also test the different ways --string-dump can be specified, i.e. as a short
# flag (-p), with different prefix modes (-p .foo, -p=.foo, -p.foo), and with
@ -23,7 +23,9 @@
# RUN: llvm-readelf -hp1 -p2 %t | cmp %t.readelf.out -
# RUN: llvm-readelf -hp 1 -p.not_null_terminated %t | cmp %t.readelf.out -
# CHECK: String dump of section '.strings':
# HEADER: LoadName:
# CHECK: {{^$}}
# CHECK-NEXT: String dump of section '.strings':
# CHECK-NEXT: [ 0] here
# CHECK-NEXT: [ 5] are
# CHECK-NEXT: [ 9] some

View File

@ -160,15 +160,10 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections,
bool Decompress) {
SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
if (!First)
W.startLine() << '\n';
First = false;
W.startLine() << "String dump of section '" << SectionName << "':\n";
W.startLine() << "\nString dump of section '" << SectionName << "':\n";
StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());
@ -182,15 +177,10 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections,
bool Decompress) {
SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
if (!First)
W.startLine() << '\n';
First = false;
W.startLine() << "Hex dump of section '" << SectionName << "':\n";
W.startLine() << "\nHex dump of section '" << SectionName << "':\n";
StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());