I was debugging an android program using ndk-gdb,in Android Studio i got a variable's true address 0x5a1f2e24, while in ndk-gdb, the variable's address printed became 0x5a1f2d24, 256 bytes less than it's true address, how can it happen. I am new to ndk, any advice is appreciated.
ndk-gdb variable address shifted
Variables move between runs.
Variables on the stack are created wherever the stack happens to be. The stack position moves every time a function is called.
Variables on the heap are created wherever the system assigns them to be, and this is likely to be different every run of the program.
Now if you detached one debugger then attached the other without stopping/restarting the program then it would be a different instance of the variable or something fishy going on.
While i printed the variable's value with p *(int*)0x5a1f2e24, the result is right, even though i restarted the program,so i am sure the variable's address shifted 256 bytes.
I mean i restarted the program,and it's address was still 0x5a1f2e24.btw this variable is declared in main function,it's address won't change during execution.