[llvm-bugs] [Bug 49614] New: Misleading line table for the spinning infinite loop

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 17 08:51:34 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49614

            Bug ID: 49614
           Summary: Misleading line table for the spinning infinite loop
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tankut.baris.aktemur at intel.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210317/7df56798/attachment.html>


More information about the llvm-bugs mailing list