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 statement within a nested for statement by si (step instruction) #45265

Open
llvmbot opened this issue May 14, 2020 · 7 comments
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party debuginfo lldb

Comments

@llvmbot
Copy link
Member

llvmbot commented May 14, 2020

Bugzilla Link 45920
Version trunk
OS Linux
Blocks #38116
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@JDevlieghere,@jmorse,@jdm,@pogo59,@zygoloid,@vedantk

Extended Description

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

$ clang --version
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

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) b main
Breakpoint 1: where = a.out`main + 11 at small.c:4:10, address = 0x000000000040111b
(lldb) r
Process 13529 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 13529 stopped

  • thread #​1, name = 'a.out', stop reason = breakpoint 1.1
    frame #​0: 0x000000000040111b a.out`main at small.c:4:10
    1 int main ()
    2 {
    3 int x, y;
    -> 4 for (x = INT_MAX - 1; x < INT_MAX; x++)
    5 for (y = -1; y <= 0; y++)
    6 if ((x + 1 - y) != (int) (x + 1U - y))
    7 return 1;
    (lldb) si -c 35
    Process 13529 stopped
  • thread #​1, name = 'a.out', stop reason = instruction step into
    frame #​0: 0x000000000040113a a.out`main at small.c:5:5
    2 {
    3 int x, y;
    4 for (x = INT_MAX - 1; x < INT_MAX; x++)
    -> 5 for (y = -1; y <= 0; y++)
    6 if ((x + 1 - y) != (int) (x + 1U - y))
    7 return 1;
    8 return 0;
    (lldb) var
    (int) x = 2147483646
    (int) y = 1
    (lldb) si
    Process 13529 stopped
  • thread #​1, name = 'a.out', stop reason = instruction step into
    frame #​0: 0x0000000000401179 a.out`main at small.c:7:16
    4 for (x = INT_MAX - 1; x < INT_MAX; x++)
    5 for (y = -1; y <= 0; y++)
    6 if ((x + 1 - y) != (int) (x + 1U - y))
    -> 7 return 1;
    8 return 0;
    9 }
    (lldb)

/******************************
lldb is wrongly stopped at Line 7.
However, when setting breakpoint at Line 7. The program is directly exit.
*******************************/

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) b 7
Breakpoint 1: where = a.out`main + 74 at small.c:7:9, address = 0x000000000040115a
(lldb) r
Process 13589 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 13589 exited with status = 0 (0x00000000)

$ cat small.c
int main ()
{
int x, y;
for (x = INT_MAX - 1; x < INT_MAX; x++)
for (y = -1; y <= 0; y++)
if ((x + 1 - y) != (int) (x + 1U - y))
return 1;
return 0;
}

@jmorse
Copy link
Member

jmorse commented May 14, 2020

Thanks for the bug report -- could you include the command line used to compile the source too please. Assuming -O0, this looks very similar to bug 45676 and its related bug 19864 -- clang is labelling the exit of the inner loop with what we would consider the wrong location:

for.end: ; preds = %for.cond1
br label %for.inc7, !dbg !​51

51 = !DILocation(line: 8, column: 16, scope: !​29)

Where line 8 is the line with "return 1;". I can replicate this with gdb, so switching component to clang.

@llvmbot
Copy link
Member Author

llvmbot commented May 14, 2020

I am sorry! I forgot to include the commands, here is the command I used to compile this code:

$ clang -g small.c

@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
@iamanonymouscs
Copy link

The latest reproducible code is as follow.
$ cat small.c

#include <limits.h>

int main ()
{
    int x, y;
    for (x = INT_MAX - 1; x < INT_MAX; x++)
        for (y = -1; y <= 0; y++)
            if ((x + 1 - y) != (int) (x + 1U - y))
                return 1;
    return 0;
}

I updated clang and lldb to the latest trunk version and found that lldb can still incorrectly reaches to line 9 at instruction-level stepping.

$ clang --version
Ubuntu clang version 16.0.0-++20221107091524+a2620e00ffa2-1exp120221107091626.847

@llvmbot
Copy link
Member Author

llvmbot commented Nov 9, 2022

@llvm/issue-subscribers-debuginfo

@llvmbot
Copy link
Member Author

llvmbot commented Nov 9, 2022

@llvm/issue-subscribers-lldb

@dwblaikie
Copy link
Collaborator

yeah, I'll have to look back a long ways - this is a long-standing bug/issue, I think Chandler filed it years ago so there's something to dup this against eventually.

The issue is that we set the jump back to the start of the loop at the end of the loop (with {}, that'd be the } but without them it's the last statement in the loop) - GCC I think does something similar, but due to a code layout choice it doesn't come up in the same way/isn't as obvious if I recall correctly.

@dwblaikie
Copy link
Collaborator

ah, here. #44948 refers to #20238

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 lldb
Projects
None yet
Development

No branches or pull requests

5 participants