It's something that puzzle me for a long time. I can observe that there is a difference between the real execution of a program and the gdb
-controlled one.
But, here is an example:
First, here is the example code (we use an automatic variable to get the location of the stack):
#include <stdio.h> #include <stdlib.h> int main () { char c = 0; printf ("Stack address: %p\n", &c); return EXIT_SUCCESS; }
Then, we disable the ASLR (we use the personality flags of the process and not the system-wide method through
/proc/sys/kernel/randomize_va_space
):$> setarch `uname -m` -R /bin/bash
Then, get a run in the real memory environment:
Stack address: 0x7fffffffe1df
And, the same through
gdb
:(gdb) r Starting program: ./gdb-against-reality Stack address: 0x7fffffffe17f [Inferior 1 (process 5374) exited normally] (gdb)
So, here we have a difference of 96 bytes between the two runs. But, how can I predict this difference for a given program without having it running in the real memory layout (just by knowing the gdb
memory layout) ?
And, also, from where/what is coming this difference ?