Created attachment 23523
the binary
$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ lldb --version
lldb version 11.0.0
clang revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af
llvm revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af
$ clang -O1 -g small.c
$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Debugger/a.out' (x86_64).
(lldb) b 5
Breakpoint 1: where = a.out`f + 21 at small.c:5:1, address = 0x0000000000401125
(lldb) r
Process 46982 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 46982 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000000000401125 a.out`f(x=-216) at small.c:5:1
2 if (x==-216 || x==-132)
3 return 1;
4 return 0;
-> 5 }
6
7 int main () {
8 volatile int i;
(lldb) fr var x
(int) x = -216
(lldb)
/************************************
As showed, when setting breakpoint on Line 5 (first hit), the value of "x" is -
216.
However, when step-i to Line 5, the value of "x" is -230 which is as expected:
************************************/
$ clang -O1 -g small.c; 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 + 5 at small.c:9:10, address =
0x0000000000401135
(lldb) r
Process 45549 launched: '/home/yibiao/Debugger/a.out' (x86_64)
Process 45549 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000000000401135 a.out`main at small.c:9:10
6
7 int main () {
8 volatile int i;
-> 9 for (i = -230; i < -120; i++)
10 if (f(i) != (i==-216 || i==-132))
11 return 1;
12 return 0;
(lldb) si -c 14
Process 45549 stopped
* thread #1, name = 'a.out', stop reason = instruction step into
frame #0: 0x0000000000401128 a.out`f(x=-230) at small.c:5:1
2 if (x==-216 || x==-132)
3 return 1;
4 return 0;
-> 5 }
6
7 int main () {
8 volatile int i;
(lldb) fr var x
(int) x = -230
(lldb)
/******************* the small.c *************/
$ cat small.c
int f(int x) {
if (x==-216 || x==-132)
return 1;
return 0;
}
int main () {
volatile int i;
for (i = -230; i < -120; i++)
if (f(i) != (i==-216 || i==-132))
return 1;
return 0;
}
a.out
(17440 bytes, application/x-executable)