<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Misleading line table for the spinning infinite loop"
href="https://bugs.llvm.org/show_bug.cgi?id=49614">49614</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Misleading line table for the spinning infinite loop
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>tankut.baris.aktemur@intel.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Hi,
Suppose we have the following program:
1 static void loop()
2 {
3 while(1);
4 }
5
6 int main()
7 {
8 loop();
9
10 return 0;
11 }
First, compile:
$ clang-11 --version
Ubuntu clang version
11.1.0-++20210203115409+1fdec59bffc1-1~exp1~20210203230038.161
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang-11 -g -O0 test.c
Start under the debugger and then interrupt with Ctrl-C to break inside the
loop.
$ lldb-11 a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (x86_64).
(lldb) run
Process 9476 launched: 'a.out' (x86_64)
Process 9476 stopped
* thread #1, name = 'a.out', stop reason = signal SIGSTOP
frame #0: 0x00000000004004c9 a.out`loop at test.c:3:3
1 static void loop()
2 {
-> 3 while(1);
4 }
5
6 int main()
7 {
(lldb)
Define a breakpoint at the line of the loop and then disassemble to check the
machine code:
(lldb) break set -l 3
Breakpoint 1: where = a.out`loop + 4 at test.c:3:3, address =
0x00000000004004c4
(lldb) disassemble
a.out`loop:
0x4004c0 <+0>: pushq %rbp
0x4004c1 <+1>: movq %rsp, %rbp
0x4004c4 <+4>: jmp 0x4004c9 ; <+9> at test.c:3:3
-> 0x4004c9 <+9>: jmp 0x4004c9 ; <+9> at test.c:3:3
(lldb)
Note that the actual spin is at the instruction at address 0x4004c9.
But the breakpoint is inserted at the fall-through jump at address 0x4004c4.
For this reason, the program does not hit the breakpoint when resumed.
It simply keeps spinning.
The reason for this behavior is the line table:
$ llvm-dwarfdump-11 --debug-line a.out
a.out: file format elf64-x86-64
...
Address Line Column File ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x00000000004004a0 7 0 1 0 0 is_stmt
0x00000000004004af 8 3 1 0 0 is_stmt prologue_end
0x00000000004004b6 10 3 1 0 0 is_stmt
0x00000000004004c0 2 0 1 0 0 is_stmt
0x00000000004004c4 3 3 1 0 0 is_stmt prologue_end
0x00000000004004ce 3 3 1 0 0 is_stmt end_sequence
Or, perhaps, the jump at 0x4004c4 should not have been emitted at all.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>