Skip to content

Commit c2e6bcb

Browse files
committed
[llvm-objdump] Prevent variable locations to overlap short comments
For now, the source variable locations are printed at about the same space as the comments for disassembled code, which can make some ranges for variables disappear if a line contains comments, for example: ┠─ bar = W1 0: add x0, x2, #2, lsl #12 // =8192┃ 4: add z31.d, z31.d, #65280 // =0xff00 8: nop ┻ The patch shifts the report a bit to allow printing comments up to approximately 16 characters without interferences. Differential Revision: https://reviews.llvm.org/D104700
1 parent abe0fa4 commit c2e6bcb

File tree

6 files changed

+178
-66
lines changed

6 files changed

+178
-66
lines changed

llvm/docs/CommandGuide/llvm-objdump.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ OPTIONS
132132
.. option:: --debug-vars-indent=<width>
133133

134134
Distance to indent the source-level variable display, relative to the start
135-
of the disassembly. Defaults to 40 characters.
135+
of the disassembly. Defaults to 52 characters.
136136

137137
.. option:: -j, --section=<section1[,section2,...]>
138138

llvm/test/tools/llvm-objdump/ELF/AArch64/disassemble-print-comments.s

+56
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,63 @@
77
# CHECK-NEXT: 0: add x0, x2, #2, lsl #12 // =8192
88
# CHECK-NEXT: 4: add z31.d, z31.d, #65280 // =0xff00
99

10+
## Check that comments and locations of variables can be printed together.
11+
# RUN: llvm-objdump -d --mattr=+sve --debug-vars --no-show-raw-insn %t | \
12+
# RUN: FileCheck %s --check-prefix=DBGVARS
13+
14+
# DBGVARS: 0000000000000000 <foo>:
15+
# DBGVARS-NEXT: ┠─ bar = W1
16+
# DBGVARS-NEXT: 0: add x0, x2, #2, lsl #12 // =8192 ┃
17+
# DBGVARS-NEXT: 4: add z31.d, z31.d, #65280 // =0xff00 ┻
18+
1019
.text
1120
foo:
1221
add x0, x2, 8192
1322
add z31.d, z31.d, #65280
23+
.LFooEnd:
24+
25+
.section .debug_abbrev,"",@progbits
26+
.uleb128 1 // Abbreviation Code
27+
.uleb128 0x11 // DW_TAG_compile_unit
28+
.byte 1 // DW_CHILDREN_yes
29+
.byte 0 // EOM(1)
30+
.byte 0 // EOM(2)
31+
.uleb128 2 // Abbreviation Code
32+
.uleb128 0x2e // DW_TAG_subprogram
33+
.byte 1 // DW_CHILDREN_yes
34+
.uleb128 0x11 // DW_AT_low_pc
35+
.uleb128 0x01 // DW_FORM_addr
36+
.uleb128 0x12 // DW_AT_high_pc
37+
.uleb128 0x06 // DW_FORM_data4
38+
.byte 0 // EOM(1)
39+
.byte 0 // EOM(2)
40+
.uleb128 3 // Abbreviation Code
41+
.uleb128 0x34 // DW_TAG_variable
42+
.byte 0 // DW_CHILDREN_no
43+
.uleb128 0x02 // DW_AT_location
44+
.uleb128 0x18 // DW_FORM_exprloc
45+
.uleb128 0x03 // DW_AT_name
46+
.uleb128 0x08 // DW_FORM_string
47+
.byte 0 // EOM(1)
48+
.byte 0 // EOM(2)
49+
.byte 0 // EOM(3)
50+
51+
.section .debug_info,"",@progbits
52+
.long .LCuEnd-.LCuBegin // Length of Unit
53+
.LCuBegin:
54+
.short 4 // DWARF version number
55+
.long .debug_abbrev // Offset Into Abbrev. Section
56+
.byte 8 // Address Size
57+
.uleb128 1 // Abbrev [1] DW_TAG_compile_unit
58+
.uleb128 2 // Abbrev [2] DW_TAG_subprogram
59+
.quad foo // DW_AT_low_pc
60+
.long .LFooEnd-foo // DW_AT_high_pc
61+
.uleb128 3 // Abbrev [3] DW_TAG_variable
62+
.byte .LLocEnd-.LLocBegin // DW_AT_location
63+
.LLocBegin:
64+
.byte 0x51 // DW_OP_reg1
65+
.LLocEnd:
66+
.asciz "bar" // DW_FORM_string
67+
.byte 0 // End Of Children Mark
68+
.byte 0 // End Of Children Mark
69+
.LCuEnd:

llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s

+61-61
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
# RUN: llvm-objdump - -d --debug-vars | \
1313
# RUN: FileCheck %s --check-prefix=RAW --strict-whitespace
1414

15-
## Check that passing the default value for --debug-vars-indent (40) makes no
15+
## Check that passing the default value for --debug-vars-indent (52) makes no
1616
## change to the output.
1717
# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \
18-
# RUN: llvm-objdump - -d --debug-vars --debug-vars-indent=40 | \
18+
# RUN: llvm-objdump - -d --debug-vars --debug-vars-indent=52 | \
1919
# RUN: FileCheck %s --check-prefix=RAW --strict-whitespace
2020

2121
# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \
@@ -50,19 +50,19 @@
5050
## 8-byte tab stop, so these might not look aligned in a text editor.
5151

5252
# RAW: 00000000 <foo>:
53-
# RAW-NEXT: ┠─ a = R0
54-
# RAW-NEXT: ┃ ┠─ b = R1
55-
# RAW-NEXT: ┃ ┃ ┠─ c = R2
56-
# RAW-NEXT: ┃ ┃ ┃ ┌─ x = R0
57-
# RAW-NEXT: 0: 00 00 81 e0 add r0, r1, r0 ┻ ┃ ┃ ╈
58-
# RAW-NEXT: ┌─ y = R0
59-
# RAW-NEXT: 4: 02 00 80 e0 add r0, r0, r2 ╈ ┃ ┃ ┻
60-
# RAW-NEXT: 8: 1e ff 2f e1 bx lr ┻ ┻ ┻
53+
# RAW-NEXT: ┠─ a = R0
54+
# RAW-NEXT: ┃ ┠─ b = R1
55+
# RAW-NEXT: ┃ ┃ ┠─ c = R2
56+
# RAW-NEXT: ┃ ┃ ┃ ┌─ x = R0
57+
# RAW-NEXT: 0: 00 00 81 e0 add r0, r1, r0 ┻ ┃ ┃ ╈
58+
# RAW-NEXT: ┌─ y = R0
59+
# RAW-NEXT: 4: 02 00 80 e0 add r0, r0, r2 ╈ ┃ ┃ ┻
60+
# RAW-NEXT: 8: 1e ff 2f e1 bx lr ┻ ┻ ┻
6161
# RAW-EMPTY:
6262
# RAW-NEXT: 0000000c <bar>:
63-
# RAW-NEXT: ┠─ a = R0
64-
# RAW-NEXT: c: 01 00 80 e2 add r0, r0, #1 ┃
65-
# RAW-NEXT: 10: 1e ff 2f e1 bx lr ┻
63+
# RAW-NEXT: ┠─ a = R0
64+
# RAW-NEXT: c: 01 00 80 e2 add r0, r0, #1
65+
# RAW-NEXT: 10: 1e ff 2f e1 bx lr
6666

6767

6868
# INDENT: 00000000 <foo>:
@@ -81,70 +81,70 @@
8181
# INDENT-NEXT: 10: 1e ff 2f e1 bx lr ┻
8282

8383
# NO-RAW: 00000000 <foo>:
84-
# NO-RAW-NEXT: ┠─ a = R0
85-
# NO-RAW-NEXT: ┃ ┠─ b = R1
86-
# NO-RAW-NEXT: ┃ ┃ ┠─ c = R2
87-
# NO-RAW-NEXT: ┃ ┃ ┃ ┌─ x = R0
88-
# NO-RAW-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
89-
# NO-RAW-NEXT: ┌─ y = R0
90-
# NO-RAW-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
91-
# NO-RAW-NEXT: 8: bx lr ┻ ┻ ┻
84+
# NO-RAW-NEXT: ┠─ a = R0
85+
# NO-RAW-NEXT: ┃ ┠─ b = R1
86+
# NO-RAW-NEXT: ┃ ┃ ┠─ c = R2
87+
# NO-RAW-NEXT: ┃ ┃ ┃ ┌─ x = R0
88+
# NO-RAW-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
89+
# NO-RAW-NEXT: ┌─ y = R0
90+
# NO-RAW-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
91+
# NO-RAW-NEXT: 8: bx lr ┻ ┻ ┻
9292
# NO-RAW-EMPTY:
9393
# NO-RAW-NEXT: 0000000c <bar>:
94-
# NO-RAW-NEXT: ┠─ a = R0
95-
# NO-RAW-NEXT: c: add r0, r0, #1 ┃
96-
# NO-RAW-NEXT: 10: bx lr ┻
94+
# NO-RAW-NEXT: ┠─ a = R0
95+
# NO-RAW-NEXT: c: add r0, r0, #1
96+
# NO-RAW-NEXT: 10: bx lr
9797

9898
# LINE-NUMS: 00000000 <foo>:
9999
# LINE-NUMS-NEXT: ; foo():
100-
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:2 ┠─ a = R0
101-
# LINE-NUMS-NEXT: ┃ ┠─ b = R1
102-
# LINE-NUMS-NEXT: ┃ ┃ ┠─ c = R2
103-
# LINE-NUMS-NEXT: ┃ ┃ ┃ ┌─ x = R0
104-
# LINE-NUMS-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
105-
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:3 ┌─ y = R0
106-
# LINE-NUMS-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
107-
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:4 ┃ ┃ ┃
108-
# LINE-NUMS-NEXT: 8: bx lr ┻ ┻ ┻
100+
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:2 ┠─ a = R0
101+
# LINE-NUMS-NEXT: ┃ ┠─ b = R1
102+
# LINE-NUMS-NEXT: ┃ ┃ ┠─ c = R2
103+
# LINE-NUMS-NEXT: ┃ ┃ ┃ ┌─ x = R0
104+
# LINE-NUMS-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
105+
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:3 ┌─ y = R0
106+
# LINE-NUMS-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
107+
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:4 ┃ ┃ ┃
108+
# LINE-NUMS-NEXT: 8: bx lr ┻ ┻ ┻
109109
# LINE-NUMS-EMPTY:
110110
# LINE-NUMS-NEXT: 0000000c <bar>:
111111
# LINE-NUMS-NEXT: ; bar():
112-
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:8 ┠─ a = R0
113-
# LINE-NUMS-NEXT: c: add r0, r0, #1 ┃
114-
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:9 ┃
115-
# LINE-NUMS-NEXT: 10: bx lr ┻
112+
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:8 ┠─ a = R0
113+
# LINE-NUMS-NEXT: c: add r0, r0, #1
114+
# LINE-NUMS-NEXT: ; SRC_COMPDIR{{[\\/]}}debug.c:9
115+
# LINE-NUMS-NEXT: 10: bx lr
116116

117117
# SOURCE: 00000000 <foo>:
118-
# SOURCE-NEXT: ; int x = a + b; ┠─ a = R0
119-
# SOURCE-NEXT: ┃ ┠─ b = R1
120-
# SOURCE-NEXT: ┃ ┃ ┠─ c = R2
121-
# SOURCE-NEXT: ┃ ┃ ┃ ┌─ x = R0
122-
# SOURCE-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
123-
# SOURCE-NEXT: ; int y = x + c; ┌─ y = R0
124-
# SOURCE-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
125-
# SOURCE-NEXT: ; return y; ┃ ┃ ┃
126-
# SOURCE-NEXT: 8: bx lr ┻ ┻ ┻
118+
# SOURCE-NEXT: ; int x = a + b; ┠─ a = R0
119+
# SOURCE-NEXT: ┃ ┠─ b = R1
120+
# SOURCE-NEXT: ┃ ┃ ┠─ c = R2
121+
# SOURCE-NEXT: ┃ ┃ ┃ ┌─ x = R0
122+
# SOURCE-NEXT: 0: add r0, r1, r0 ┻ ┃ ┃ ╈
123+
# SOURCE-NEXT: ; int y = x + c; ┌─ y = R0
124+
# SOURCE-NEXT: 4: add r0, r0, r2 ╈ ┃ ┃ ┻
125+
# SOURCE-NEXT: ; return y; ┃ ┃ ┃
126+
# SOURCE-NEXT: 8: bx lr ┻ ┻ ┻
127127
# SOURCE-EMPTY:
128128
# SOURCE-NEXT: 0000000c <bar>:
129-
# SOURCE-NEXT: ; a++; ┠─ a = R0
130-
# SOURCE-NEXT: c: add r0, r0, #1 ┃
131-
# SOURCE-NEXT: ; return a; ┃
132-
# SOURCE-NEXT: 10: bx lr ┻
129+
# SOURCE-NEXT: ; a++; ┠─ a = R0
130+
# SOURCE-NEXT: c: add r0, r0, #1
131+
# SOURCE-NEXT: ; return a;
132+
# SOURCE-NEXT: 10: bx lr
133133

134134
# ASCII: 00000000 <foo>:
135-
# ASCII-NEXT: |- a = R0
136-
# ASCII-NEXT: | |- b = R1
137-
# ASCII-NEXT: | | |- c = R2
138-
# ASCII-NEXT: | | | /- x = R0
139-
# ASCII-NEXT: 0: 00 00 81 e0 add r0, r1, r0 v | | ^
140-
# ASCII-NEXT: /- y = R0
141-
# ASCII-NEXT: 4: 02 00 80 e0 add r0, r0, r2 ^ | | v
142-
# ASCII-NEXT: 8: 1e ff 2f e1 bx lr v v v
135+
# ASCII-NEXT: |- a = R0
136+
# ASCII-NEXT: | |- b = R1
137+
# ASCII-NEXT: | | |- c = R2
138+
# ASCII-NEXT: | | | /- x = R0
139+
# ASCII-NEXT: 0: 00 00 81 e0 add r0, r1, r0 v | | ^
140+
# ASCII-NEXT: /- y = R0
141+
# ASCII-NEXT: 4: 02 00 80 e0 add r0, r0, r2 ^ | | v
142+
# ASCII-NEXT: 8: 1e ff 2f e1 bx lr v v v
143143
# ASCII-EMPTY:
144144
# ASCII-NEXT: 0000000c <bar>:
145-
# ASCII-NEXT: |- a = R0
146-
# ASCII-NEXT: c: 01 00 80 e2 add r0, r0, #1 |
147-
# ASCII-NEXT: 10: 1e ff 2f e1 bx lr v
145+
# ASCII-NEXT: |- a = R0
146+
# ASCII-NEXT: c: 01 00 80 e2 add r0, r0, #1 |
147+
# ASCII-NEXT: 10: 1e ff 2f e1 bx lr v
148148

149149
.text
150150
.syntax unified

llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-wide-chars.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
## characters.
1414

1515
# CHECK: 00000000 <foo>:
16-
# CHECK-NEXT: ; return *喵; ┠─ 喵 = R0
17-
# CHECK-NEXT: 0: 00 00 90 e5 ldr r0, [r0] ┻
18-
# CHECK-NEXT: 4: 1e ff 2f e1 bx lr
16+
# CHECK-NEXT: ; return *喵; ┠─ 喵 = R0
17+
# CHECK-NEXT: 0: 00 00 90 e5 ldr r0, [r0]
18+
# CHECK-NEXT: 4: 1e ff 2f e1 bx lr
1919

2020
.text
2121
.syntax unified

llvm/test/tools/llvm-objdump/X86/disassemble-print-comments.s

+56
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,63 @@
77
# CHECK-NEXT: 0: nop
88
# CHECK-NEXT: 1: cmpl $305419896, %eax # imm = 0x12345678
99

10+
## Check that comments and locations of variables can be printed together.
11+
# RUN: llvm-objdump -d --debug-vars --no-show-raw-insn %t | \
12+
# RUN: FileCheck %s --check-prefix=DBGVARS
13+
14+
# DBGVARS: 0000000000000000 <foo>:
15+
# DBGVARS-NEXT: ┠─ bar = RDX
16+
# DBGVARS-NEXT: 0: nop ┃
17+
# DBGVARS-NEXT: 1: cmpl $305419896, %eax # imm = 0x12345678 ┻
18+
1019
.text
1120
foo:
1221
nop
1322
cmpl $0x12345678, %eax
23+
.LFooEnd:
24+
25+
.section .debug_abbrev,"",@progbits
26+
.uleb128 1 # Abbreviation Code
27+
.uleb128 0x11 # DW_TAG_compile_unit
28+
.byte 1 # DW_CHILDREN_yes
29+
.byte 0 # EOM(1)
30+
.byte 0 # EOM(2)
31+
.uleb128 2 # Abbreviation Code
32+
.uleb128 0x2e # DW_TAG_subprogram
33+
.byte 1 # DW_CHILDREN_yes
34+
.uleb128 0x11 # DW_AT_low_pc
35+
.uleb128 0x01 # DW_FORM_addr
36+
.uleb128 0x12 # DW_AT_high_pc
37+
.uleb128 0x06 # DW_FORM_data4
38+
.byte 0 # EOM(1)
39+
.byte 0 # EOM(2)
40+
.uleb128 3 # Abbreviation Code
41+
.uleb128 0x34 # DW_TAG_variable
42+
.byte 0 # DW_CHILDREN_no
43+
.uleb128 0x02 # DW_AT_location
44+
.uleb128 0x18 # DW_FORM_exprloc
45+
.uleb128 0x03 # DW_AT_name
46+
.uleb128 0x08 # DW_FORM_string
47+
.byte 0 # EOM(1)
48+
.byte 0 # EOM(2)
49+
.byte 0 # EOM(3)
50+
51+
.section .debug_info,"",@progbits
52+
.long .LCuEnd-.LCuBegin # Length of Unit
53+
.LCuBegin:
54+
.short 4 # DWARF version number
55+
.long .debug_abbrev # Offset Into Abbrev. Section
56+
.byte 8 # Address Size
57+
.uleb128 1 # Abbrev [1] DW_TAG_compile_unit
58+
.uleb128 2 # Abbrev [2] DW_TAG_subprogram
59+
.quad foo # DW_AT_low_pc
60+
.long .LFooEnd-foo # DW_AT_high_pc
61+
.uleb128 3 # Abbrev [3] DW_TAG_variable
62+
.byte .LLocEnd-.LLocBegin # DW_AT_location
63+
.LLocBegin:
64+
.byte 0x51 # DW_OP_reg1
65+
.LLocEnd:
66+
.asciz "bar" # DW_FORM_string
67+
.byte 0 # End Of Children Mark
68+
.byte 0 # End Of Children Mark
69+
.LCuEnd:

llvm/tools/llvm-objdump/llvm-objdump.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ uint32_t objdump::PrefixStrip;
221221

222222
DebugVarsFormat objdump::DbgVariables = DVDisabled;
223223

224-
int objdump::DbgIndent = 40;
224+
int objdump::DbgIndent = 52;
225225

226226
static StringSet<> DisasmSymbolSet;
227227
StringSet<> objdump::FoundSectionSet;

0 commit comments

Comments
 (0)