I'm writing a compiler, and it emitted the following (Intel-syntax) assembly code for Linux (x86-64):
lea r13, _s1
mov qword ptr [rbp + -2*8], r13
mov r10, qword ptr [rbp + -2*8]
lea r13, qword ptr [r10 + 8]
If I'm reading this correctly, this code is supposed to load the address of label _s1 into r13, store it on the stack, read it from the stack into r10, add 8, and store the reuslt in r13. That matches the expected behaviour of my program, and it seems to work as expected (program doesn't crash here) when I am not debugging the program.
However, when I try to debug the program using VSCode with CodeLLDB, as I step through the program, I see behaviour that I can't understand. This is what seems to happen according to CodeLLDB:
lea r13, [0x425290]:0x425290is loaded intor13mov qword ptr [rbp - 0x10], r13:0x425290is written to address0x7fffffffe1f0; I confirmed this by runningmemory read -s1 $rbp-0x10in LLDBmov r10, qword ptr [rbp - 0x10]:0xffffe6f400000000is read intor10. Why?lea r13, [r10 + 0x8]:0xffffe6f400000008is loaded intor13
Why is the value that I read back from the stack different from the value that I wrote into it?
Edit: It seems like this weird behaviour doesn't happen when I use VSCode's built-in GDB debugger. Am I misusing LLDB?