Issues in .debug_line
// test.c
1 #include <stdio.h>
2
3 int main()
4 {
5 printf("a");
6 printf("b");
7 printf("c");
8 return 0;
9 }
lui a1, 0
addi a1, a1, 0
sw a0, -16(s0)
c.mv a0, a1
auipc ra, 0
jalr ra, ra, 0
lui a1, 0
addi a1, a1, 0
sw a0, -20(s0)
compile
Issues in .debug_line
// llvm-dwarfdump
file_names[ 1] 0 0x00000000 0x00000000 test.c
Address Line Column File ISA Discriminator
------------------ ------ ------ ------ --- -------------
0x00000000000101c0 4 0 1 0 0
0x00000000000101d0 5 3 1 0 0
0x00000000000101e6 6 3 1 0 0
0x00000000000101fc 7 3 1 0 0
0x0000000000010212 8 3 1 0 0
0x000000000001022a 8 3 1 0 0
// llvm-objdump -disassemble
101d0: b7 85 01 00 lui a1, 24
101d4: 93 85 05 27 addi a1, a1, 624
101d8: 23 28 a4 fe sw a0, -16(s0)
101dc: 2e 85 c.mv a0, a1
101de: c9 2a c.jal 466
101e0: b7 85 01 00 lui a1, 24
101e4: 93 85 45 27 addi a1, a1, 628
101e8: 23 26 a4 fe sw a0, -20(s0)
lui a1, 0
addi a1, a1, 0
sw a0, -16(s0)
c.mv a0, a1
auipc ra, 0
jalr ra, ra, 0
lui a1, 0
addi a1, a1, 0
sw a0, -20(s0)
If there is no relocation for .debug_line, address will be wrong.
In the case, the address of line 6 is not existed.
link
(gdb) b test.c:6
Breakpoint 1 at 0x101e6: file test.c, line 6.
(gdb) r
Starting program: /home/users/kai/sandbox/llvm-test/debug-line/test
ac[Inferior 1 (process 42000) exited normally]
Issues in .debug_line
Insert a breakpoint at line 6, the program will not hit the breakpoint.
• “we design a byte-coded language for a state machine
and store a stream of bytes in the object file instead of the
matrix. This language can be much more compact than
the matrix.”
How to Encode Line Number
Information in DWARF
How to Encode Address
Delta
• DW_LNS_advance_pc

• Takes a single unsigned LEB128 operand as the operation advance
and modifies the address.

• unsigned LEB128 is a variable length operand.

• DW_LNS_fixed_advance_pc (No supported in LLVM yet. D46850)

• Takes a single uhalf (unencoded) operand and adds it to the address
register of the state machine and sets the op_index register to 0.

• Relaxation may change the address delta after linking. We use the
fixed length operand to make it easier to generate fixups
in .debug_line.

Debug Line Issues After Relaxation.

  • 1.
    Issues in .debug_line //test.c 1 #include <stdio.h> 2 3 int main() 4 { 5 printf("a"); 6 printf("b"); 7 printf("c"); 8 return 0; 9 } lui a1, 0 addi a1, a1, 0 sw a0, -16(s0) c.mv a0, a1 auipc ra, 0 jalr ra, ra, 0 lui a1, 0 addi a1, a1, 0 sw a0, -20(s0) compile
  • 2.
    Issues in .debug_line //llvm-dwarfdump file_names[ 1] 0 0x00000000 0x00000000 test.c Address Line Column File ISA Discriminator ------------------ ------ ------ ------ --- ------------- 0x00000000000101c0 4 0 1 0 0 0x00000000000101d0 5 3 1 0 0 0x00000000000101e6 6 3 1 0 0 0x00000000000101fc 7 3 1 0 0 0x0000000000010212 8 3 1 0 0 0x000000000001022a 8 3 1 0 0 // llvm-objdump -disassemble 101d0: b7 85 01 00 lui a1, 24 101d4: 93 85 05 27 addi a1, a1, 624 101d8: 23 28 a4 fe sw a0, -16(s0) 101dc: 2e 85 c.mv a0, a1 101de: c9 2a c.jal 466 101e0: b7 85 01 00 lui a1, 24 101e4: 93 85 45 27 addi a1, a1, 628 101e8: 23 26 a4 fe sw a0, -20(s0) lui a1, 0 addi a1, a1, 0 sw a0, -16(s0) c.mv a0, a1 auipc ra, 0 jalr ra, ra, 0 lui a1, 0 addi a1, a1, 0 sw a0, -20(s0) If there is no relocation for .debug_line, address will be wrong. In the case, the address of line 6 is not existed. link
  • 3.
    (gdb) b test.c:6 Breakpoint1 at 0x101e6: file test.c, line 6. (gdb) r Starting program: /home/users/kai/sandbox/llvm-test/debug-line/test ac[Inferior 1 (process 42000) exited normally] Issues in .debug_line Insert a breakpoint at line 6, the program will not hit the breakpoint.
  • 4.
    • “we designa byte-coded language for a state machine and store a stream of bytes in the object file instead of the matrix. This language can be much more compact than the matrix.” How to Encode Line Number Information in DWARF
  • 5.
    How to EncodeAddress Delta • DW_LNS_advance_pc • Takes a single unsigned LEB128 operand as the operation advance and modifies the address. • unsigned LEB128 is a variable length operand. • DW_LNS_fixed_advance_pc (No supported in LLVM yet. D46850) • Takes a single uhalf (unencoded) operand and adds it to the address register of the state machine and sets the op_index register to 0. • Relaxation may change the address delta after linking. We use the fixed length operand to make it easier to generate fixups in .debug_line.