<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70477>70477</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLDB] Single Instruction Step not working as expected
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Andy53
</td>
</tr>
</table>
<pre>
I have come across an issue whereby the `si` does not work as intended.
According to the documentation [here](https://lldb.llvm.org/use/map.html#do-an-instruction-level-single-step-in-the-currently-selected-thread) it should single step through instructions.
Taking a program like this, compiling with clang (`clang test.c -o printf_test -g`) and running with lldb:
```
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello \n");
printf("world\n");
printf("!\n");
exit(0);
}
```
I start by running process launch and then setting a breakpoint at the `main` function using `process launch -s` then `b main`. Now when I run `dis` I am looking at this:
```
Process 2051 resuming
Process 2051 stopped
* thread #1, name = 'test', stop reason = breakpoint 1.1
frame #0: 0x000000000040114f test`main at printf_test.c:5:2
2 #include <stdlib.h>
3
4 int main(){
-> 5 printf("Hello ");
6 printf("world");
7 printf("\n");
8 exit(0);
(lldb) dis
test`main:
0x401140 <+0>: pushq %rbp
0x401141 <+1>: movq %rsp, %rbp
0x401144 <+4>: subq $0x10, %rsp
0x401148 <+8>: movl $0x0, -0x4(%rbp)
-> 0x40114f <+15>: leaq 0xeae(%rip), %rdi
0x401156 <+22>: movb $0x0, %al
0x401158 <+24>: callq 0x401030 ; symbol stub for: printf
0x40115d <+29>: leaq 0xea7(%rip), %rdi
0x401164 <+36>: movb $0x0, %al
0x401166 <+38>: callq 0x401030 ; symbol stub for: printf
0x40116b <+43>: leaq 0xe9f(%rip), %rdi
0x401172 <+50>: movb $0x0, %al
0x401174 <+52>: callq 0x401030 ; symbol stub for: printf
0x401179 <+57>: xorl %edi, %edi
0x40117b <+59>: callq 0x401040 ; symbol stub for: exit
```
Now if I use `si` to single step to the next instruction we do not land at the next instruction `0x401156 <+22>: movb $0x0, %al` instead we land at:
```
(lldb) si
Process 2051 stopped
* thread #1, name = test', stop reason = instruction step into
frame #0: 0x00007ffff7e92eee libc.so.6`__GI___fstatat64(fd=1, file="", buf=0x00007fffffffd7e0, flag=4096) at fstatat64.c:168:3
(lldb) dis
libc.so.6`__GI___fstatat64:
0x7ffff7e92ee0 <+0>: endbr64
0x7ffff7e92ee4 <+4>: movl %ecx, %r10d
0x7ffff7e92ee7 <+7>: movl $0x106, %eax ; imm = 0x106
0x7ffff7e92eec <+12>: syscall
-> 0x7ffff7e92eee <+14>: cmpl $0xfffff000, %eax ; imm = 0xFFFFF000
0x7ffff7e92ef3 <+19>: ja 0x7ffff7e92f00 ; <+32> at fstatat64.c:167:5
0x7ffff7e92ef5 <+21>: xorl %eax, %eax
0x7ffff7e92ef7 <+23>: retq
0x7ffff7e92ef8 <+24>: nopl (%rax,%rax)
0x7ffff7e92f00 <+32>: movq 0x104f09(%rip), %rdx
0x7ffff7e92f07 <+39>: negl %eax
0x7ffff7e92f09 <+41>: movl %eax, %fs:(%rdx)
0x7ffff7e92f0c <+44>: movl $0xffffffff, %eax ; imm = 0xFFFFFFFF
0x7ffff7e92f11 <+49>: retq
```
If I keep executing `si` I can hit it 3 more times before the program completes and we never go back to main to hit the other `printf` methods however you can see the output from them as you keep running the `si` commands.
```
(lldb) si
Process 2692 stopped
* thread #1, name = 'test', stop reason = instruction step into
frame #0: 0x00007ffff7dc5c87 libc.so.6`__GI___getrandom(buffer=0x00007ffff7f9f4d8, length=8, flags=1) at getrandom.c:29:10
(lldb) si
Process 2692 stopped
* thread #1, name = 'test', stop reason = instruction step into
frame #0: 0x00007ffff7e999db libc.so.6`__brk(addr=0x0000000000000000) at brk.c:36:12
(lldb) si
Hello
Process 2692 stopped
* thread #1, name = 'test', stop reason = instruction step into
frame #0: 0x00007ffff7e93a37 libc.so.6`__GI___libc_write(fd=1, buf=0x00000000004052a0, nbytes=7) at write.c:26:10
(lldb) si
world
!
Process 2692 exited with status = 0 (0x00000000)
```
Using the [n](https://lldb.llvm.org/use/map.html#do-a-source-level-single-step-over-in-the-currently-selected-thread) command will move you through source code lines as expected and the step [s](https://lldb.llvm.org/use/map.html#do-a-source-level-single-step-in-the-currently-selected-thread) command produces the same results as `si`.
OS: Linux Mint (21.2 Cinnamon) running on VirtualBox
VirtualBox: 7.0.10 r158379
Host: MacOS Ventura 13.6 I9
LLDB Version: 17.0.2 (installed using `bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"`)
Architecture: x86-64
If there is any other information that would help in diagnosing this issue please reply in the thread and I will provide it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWV9v47gR_zTMy8AGRf2zHvLgrC-9AHe9Atvea0BJI4sXivSSVOx8-4KU5MixnO62PaA1FlmLmhnOP85vhubWir1CvCfpA0l3d7x3rTb3W1W_pfFdqeu3-ydo-StCpTsEXhltLXAFwtoe4diiwfINXItAMmoFySjUGi0o7eCozQtwC0I5VDXWayB0R-h2-LutKm1qofbgdBBQ66rvUDnuhFZA0gcvnKQ7wjatcwdL4i1hj4Q9SlmXaylfu7U2e8Iee4uEPXb8sG5dJwmLa73iaiWUdaavvLSVxFeUKyvUXuLKOjyshFq5FldVbwwqJ99WFiVWDuuVaw3ymrAChAPb6l7WMHCC5wTXGt3vW5jJt-u5ZX_nL94sDgej94Z3IMULgmuFJeyLd-RBSE9wFK6FSnK1B8I2JKPDd4fWrStYaTgYoVzz7BdgtScZ9UpxVYPplTpL8O7wvhk0yOj4b3hksVCV7GsEEn-xrhZ63ZL4pxtvpSjnr8NfoRx0XCivIitI_jC9LAb1wjr7GaXUQNIvijDm6eKRDgBgTnjURtZLdHMiwqIbovAkHGEbOl8n-W7R-CewjhsH5dvZYQejK7QWJO9V1QZfuhYVWHRuiFlpkL8ctLeauymxg_0ZhaZXId7Q-4Twbz4IXFlPFkSSjJYwMq7hr_roT4uCJ6-Lf1mLQPsEPkG0HlLGDWl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