Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldb wrongly stopped at a break statement when using step-by-step #45021

Open
llvmbot opened this issue Apr 26, 2020 · 6 comments
Open

lldb wrongly stopped at a break statement when using step-by-step #45021

llvmbot opened this issue Apr 26, 2020 · 6 comments
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party debuginfo wrong-debug

Comments

@llvmbot
Copy link
Member

llvmbot commented Apr 26, 2020

Bugzilla Link 45676
Version trunk
OS Linux
Blocks #38116
Reporter LLVM Bugzilla Contributor
CC @adrian-prantl,@dwblaikie,@JDevlieghere,@jmorse,@jimingham,@jdm,@walkerkd,@labath,@pogo59,@vedantk

Extended Description

$ clang -v
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project 871beba)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

$ lldb -v
lldb version 11.0.0
clang revision 871beba
llvm revision 871beba

$ clang -g small.c; lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/home/yibiao/a.out' (x86_64).
(lldb) b small.c:14
Breakpoint 1: where = a.out`main + 57 at small.c:14:16, address = 0x0000000000401149
(lldb) run
Process 237374 launched: '/home/yibiao/a.out' (x86_64)
Process 237374 stopped

  • thread #​1, name = 'a.out', stop reason = breakpoint 1.1
    frame #​0: 0x0000000000401149 a.out`main at small.c:14:16
    11 for (; g <= 32; ++g)
    12 {
    13 i = 0;
    -> 14 for (; i < 1; i++)
    15 while (1 > d)
    16 if (c[b])
    17 break;
    (lldb) step
    Process 237374 stopped
  • thread #​1, name = 'a.out', stop reason = step in
    frame #​0: 0x0000000000401153 a.out`main at small.c:15:9
    12 {
    13 i = 0;
    14 for (; i < 1; i++)
    -> 15 while (1 > d)
    16 if (c[b])
    17 break;
    18 L:
    (lldb) step
    Process 237374 stopped
  • thread #​1, name = 'a.out', stop reason = step in
    frame #​0: 0x0000000000401193 a.out`main at small.c:14:22
    11 for (; g <= 32; ++g)
    12 {
    13 i = 0;
    -> 14 for (; i < 1; i++)
    15 while (1 > d)
    16 if (c[b])
    17 break;
    (lldb) step
    Process 237374 stopped
  • thread #​1, name = 'a.out', stop reason = breakpoint 1.1
    frame #​0: 0x0000000000401149 a.out`main at small.c:14:16
    11 for (; g <= 32; ++g)
    12 {
    13 i = 0;
    -> 14 for (; i < 1; i++)
    15 while (1 > d)
    16 if (c[b])
    17 break;
    (lldb) step
    Process 237374 stopped
  • thread #​1, name = 'a.out', stop reason = step in
    frame #​0: 0x00000000004011a1 a.out`main at small.c:17:13
    14 for (; i < 1; i++)
    15 while (1 > d)
    16 if (c[b])
    -> 17 break;
    18 L:
    19 if (j)
    20 break;

##################
We can found that, lldb is wrongly stopped at Line:17 when using step command.
However, it behaves as expected when we set breakpoint at line:17 as follows:

$ clang -g small.c; lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/home/yibiao/a.out' (x86_64).
(lldb) b small.c:17
Breakpoint 1: where = a.out`main + 116 at small.c:17:13, address = 0x0000000000401184
(lldb) run
Process 236754 launched: '/home/yibiao/a.out' (x86_64)
Process 236754 exited with status = 0 (0x00000000)

$ cat small.c
char a;
short b, d = 5, h;
char c[1];
int e, f = 4, g, j;
int main()
{
int i;
for (; f; f = a)
{
g = 0;
for (; g <= 32; ++g)
{
i = 0;
for (; i < 1; i++)
while (1 > d)
if (c[b])
break;
L:
if (j)
break;
}
}
return 0;
}

@jmorse
Copy link
Member

jmorse commented Apr 27, 2020

Many thanks for the bug report -- I experience the same behaviour in gdb, so this is probably a compiler issue. I see that when the 'for' loop on line 14 terminates, it exits via the 'break' on line 17, instead of stepping to lines 18 or 19. Worse, this is happening at -O0 too, which should give a perfect debug experience.

I'm attaching the IR I get with "-g -O0 -Xclang -disable-llvm-passes" and a recent trunk -- the for loop on line 14 appears to form the blocks "for.cond3", "for.body5", "for.inc" and "for.end".

"for.cond3" exits the loop via "for.end", which is given the metadata "!dbg !​71":

!​71 = !DILocation(line: 17, column: 13, scope: !​55)

To me it looks like clang is producing the wrong metadata. (Clang is also way out of my familiarity zone).

@jmorse
Copy link
Member

jmorse commented Apr 27, 2020

@jimingham
Copy link
Collaborator

That's definitely where the line table tells lldb the program has landed. If you "step-i" through the function it definitely arrives at a line marked 17, for instance:

(lldb)
Process 80840 stopped

  • thread #​1, queue = 'com.apple.main-thread', stop reason = instruction step into
    frame #​0: 0x0000000100000f0c examplemain at example.c:14 examplemain:
    -> 0x100000f0c <+60>: cmpl $0x1, -0x8(%rbp)
    0x100000f10 <+64>: jge 0x100000f68 ; <+152> at example.c:17:13
    0x100000f16 <+70>: jmp 0x100000f1b ; <+75> at example.c:15:20
    0x100000f1b <+75>: movswl 0xde(%rip), %eax ; d
    0x100000f22 <+82>: movl $0x1, %ecx
    0x100000f27 <+87>: cmpl %eax, %ecx
    0x100000f29 <+89>: jle 0x100000f55 ; <+133> at example.c:15:9
    0x100000f2f <+95>: leaq 0xd6(%rip), %rax ; c
    Target 0: (example) stopped.
    (lldb)
    Process 80840 stopped
  • thread #​1, queue = 'com.apple.main-thread', stop reason = instruction step into
    frame #​0: 0x0000000100000f10 examplemain at example.c:14 examplemain:
    -> 0x100000f10 <+64>: jge 0x100000f68 ; <+152> at example.c:17:13
    0x100000f16 <+70>: jmp 0x100000f1b ; <+75> at example.c:15:20
    0x100000f1b <+75>: movswl 0xde(%rip), %eax ; d
    0x100000f22 <+82>: movl $0x1, %ecx
    0x100000f27 <+87>: cmpl %eax, %ecx
    0x100000f29 <+89>: jle 0x100000f55 ; <+133> at example.c:15:9
    0x100000f2f <+95>: leaq 0xd6(%rip), %rax ; c
    0x100000f36 <+102>: leaq 0xcd(%rip), %rcx ; b
    Target 0: (example) stopped.
    (lldb)
    Process 80840 stopped
  • thread #​1, queue = 'com.apple.main-thread', stop reason = instruction step into
    frame #​0: 0x0000000100000f68 examplemain at example.c:17 examplemain:
    -> 0x100000f68 <+152>: jmp 0x100000f6d ; <+157> at example.c
    0x100000f6d <+157>: leaq 0xa8(%rip), %rax ; j
    0x100000f74 <+164>: cmpl $0x0, (%rax)
    0x100000f77 <+167>: je 0x100000f82 ; <+178> at example.c:21:5
    0x100000f7d <+173>: jmp 0x100000f9a ; <+202> at example.c:22:3
    0x100000f82 <+178>: jmp 0x100000f87 ; <+183> at example.c
    0x100000f87 <+183>: leaq 0x86(%rip), %rax ; g
    0x100000f8e <+190>: movl (%rax), %ecx
    Target 0: (example) stopped.
    (lldb)

And there we are at line 17.

This is a bug with the debug information. Doesn't look like we have a separate category for clang debug info, however. Not sure where to put this.

@jmorse
Copy link
Member

jmorse commented Apr 30, 2020

NB: I noticed that in bug 45609 dblaike identified bug 19864 as a long term issue. Reading through 19864, it sounds fairly similar to this one -- the end of a loop is attributed to the end of its scope, but that means stepping onto an unreached line.

@labath
Copy link
Collaborator

labath commented Jun 30, 2020

Moving to the debug info component, per the previous comments.

@dwblaikie
Copy link
Collaborator

NB: I noticed that in bug 45609 dblaike identified bug 19864 as a long term
issue. Reading through 19864, it sounds fairly similar to this one -- the
end of a loop is attributed to the end of its scope, but that means stepping
onto an unreached line.

Yeah, sounds like a dup of 19864

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party debuginfo wrong-debug
Projects
None yet
Development

No branches or pull requests

5 participants