Why, when I run the code from gdb, I get the same addresses for the declared variables, but when I simply execute the binary code, I donโt get the same addresses.
#include<stdio.h> void main() { int *x,q; //I saw the address of the variable q in this program through gdb during the __1st__ execution. //I re-compiled the program to make x to point to this address. x=0x7fffffffe2bc; *x=3; printf("%d",(*x)); }
I ran the program through gdb and it was never Segfaulted.
$ gdb -q ./a.out Reading symbols from /home/eknath/needed2/a.out...done. (gdb) r Starting program: /home/eknath/needed2/a.out 3 Program exited normally. (gdb) q $
But normal program execution always causes SEGFAULT.
$ ./a.out Segmentation fault
I do not know if this question is a duplicate. Is it always the address for the GDB debugging program?
NOTE. I did not disable ASLR
source share