Skip to content

Commit ea4ae25

Browse files
authored
[lldb] Fix section printing to always align. (#98521)
Section IDs are 64 bit and if a section ID was over 4GB, then the tabular output of the "target modules dump sections" command would not align to the column headers. Also if the section type's name was too long, the output wouldn't algin. This patch fixes this issue. Old output looked like: ``` (lldb) image dump sections a.out Sections for '/tmp/a.out' (arm): SectID Type File Address Perm File Off. File Size Flags Section Name ---------- ---------------- --------------------------------------- ---- ---------- ---------- ---------- ---------------------------- 0xffffffffffffffff container [0x0000000000001000-0x0000000000001010) rw- 0x00000074 0x00000010 0x00000000 a.out.PT_LOAD[0] 0x00000001 data [0x0000000000001000-0x0000000000001010) rw- 0x00000074 0x00000010 0x00000003 a.out.PT_LOAD[0]..data 0xfffffffffffffffe container [0x0000000000001000-0x0000000000001010) rw- 0x00000084 0x00000000 0x00000000 a.out.PT_TLS[0] 0x00000002 zero-fill [0x0000000000001000-0x0000000000001010) rw- 0x00000084 0x00000000 0x00000403 a.out.PT_TLS[0]..tbss 0x00000003 regular --- 0x00000084 0x00000001 0x00000000 a.out..strtab 0x00000004 regular --- 0x00000085 0x0000001f 0x00000000 a.out..shstrtab ``` New output looks like: ``` (lldb) image dump sections a.out Sections for '/tmp/a.out' (arm): SectID Type File Address Perm File Off. File Size Flags Section Name ------------------ ---------------------- --------------------------------------- ---- ---------- ---------- ---------- ---------------------------- 0xffffffffffffffff container [0x0000000000001000-0x0000000000001010) rw- 0x00000074 0x00000010 0x00000000 a.out.PT_LOAD[0] 0x0000000000000001 data [0x0000000000001000-0x0000000000001010) rw- 0x00000074 0x00000010 0x00000003 a.out.PT_LOAD[0]..data 0xfffffffffffffffe container [0x0000000000001000-0x0000000000001010) rw- 0x00000084 0x00000000 0x00000000 a.out.PT_TLS[0] 0x0000000000000002 zero-fill [0x0000000000001000-0x0000000000001010) rw- 0x00000084 0x00000000 0x00000403 a.out.PT_TLS[0]..tbss 0x0000000000000003 regular --- 0x00000084 0x00000001 0x00000000 a.out..strtab 0x0000000000000004 regular --- 0x00000085 0x0000001f 0x00000000 a.out..shstrtab ```
1 parent 43024a4 commit ea4ae25

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lldb/source/Core/Section.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool Section::ContainsFileAddress(addr_t vm_addr) const {
275275
void Section::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
276276
uint32_t depth) const {
277277
s.indent(indent);
278-
s << llvm::format("0x%8.8" PRIx64 " %-16s ", GetID(), GetTypeAsCString());
278+
s << llvm::format("0x%16.16" PRIx64 " %-22s ", GetID(), GetTypeAsCString());
279279
bool resolved = true;
280280
addr_t addr = LLDB_INVALID_ADDRESS;
281281

@@ -642,14 +642,12 @@ void SectionList::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
642642
if (show_header && !m_sections.empty()) {
643643
s.indent(indent);
644644
s << llvm::formatv(
645-
"SectID Type {0} Address "
646-
" Perm File Off. File Size Flags "
647-
" Section Name\n",
645+
"SectID Type {0} Address "
646+
" Perm File Off. File Size Flags Section Name\n",
648647
target_has_loaded_sections ? "Load" : "File");
649648
s.indent(indent);
650-
s << "---------- ---------------- "
651-
"--------------------------------------- ---- ---------- "
652-
"---------- "
649+
s << "------------------ ---------------------- "
650+
"--------------------------------------- ---- ---------- ---------- "
653651
"---------- ----------------------------\n";
654652
}
655653

lldb/test/Shell/Commands/command-target-modules-dump-sections.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
# RUN: | FileCheck --match-full-lines --strict-whitespace %s
44

55
# CHECK:Sections for '{{.*}}command-target-modules-dump-sections.yaml.tmp' (x86_64):
6-
# CHECK-NEXT: SectID Type File Address Perm File Off. File Size Flags Section Name
7-
# CHECK-NEXT: ---------- ---------------- --------------------------------------- ---- ---------- ---------- ---------- ----------------------------
8-
# CHECK-NEXT: 0x00000001 code [0x0000000000004000-0x0000000000005000) r-x 0x00001000 0x00001000 0x00000006 command-target-modules-dump-sections.yaml.tmp..text
9-
# CHECK-NEXT: 0x00000002 regular [0x0000000000005000-0x0000000000005100) r-- 0x00002000 0x00000100 0x00000002 command-target-modules-dump-sections.yaml.tmp..rodata
10-
# CHECK-NEXT: 0x00000003 eh-frame [0x0000000000006000-0x0000000000006040) r-- 0x00002100 0x00000040 0x00000002 command-target-modules-dump-sections.yaml.tmp..eh_frame
6+
# CHECK-NEXT: SectID Type File Address Perm File Off. File Size Flags Section Name
7+
# CHECK-NEXT: ------------------ ---------------------- --------------------------------------- ---- ---------- ---------- ---------- ----------------------------
8+
# CHECK-NEXT: 0x0000000000000001 code [0x0000000000004000-0x0000000000005000) r-x 0x00001000 0x00001000 0x00000006 command-target-modules-dump-sections.yaml.tmp..text
9+
# CHECK-NEXT: 0x0000000000000002 regular [0x0000000000005000-0x0000000000005100) r-- 0x00002000 0x00000100 0x00000002 command-target-modules-dump-sections.yaml.tmp..rodata
10+
# CHECK-NEXT: 0x0000000000000003 eh-frame [0x0000000000006000-0x0000000000006040) r-- 0x00002100 0x00000040 0x00000002 command-target-modules-dump-sections.yaml.tmp..eh_frame
1111
--- !ELF
12-
FileHeader:
12+
FileHeader:
1313
Class: ELFCLASS64
1414
Data: ELFDATA2LSB
1515
Type: ET_EXEC
1616
Machine: EM_X86_64
17-
Sections:
17+
Sections:
1818
- Name: .text
1919
Type: SHT_PROGBITS
2020
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]

0 commit comments

Comments
 (0)