Perché quando eseguo il codice da gdb, ottengo gli stessi indirizzi per le variabili dichiarate, ma mentre eseguo il file binario non ottengo gli stessi indirizzi.Perché l'indirizzo di una variabile locale varia quando si esegue più volte, ma non quando si esegue il debugging con GDB?
#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));
}
Ho eseguito il programma tramite gdb e mai Segfault.
$ 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
$
Tuttavia, l'esecuzione normale del programma produce sempre un SEGFAULT.
$ ./a.out
Segmentation fault
Non so se questa domanda è un duplicato di Is this always the address for GDB debug program?
NOTA: Non ho spento ASLR
Great Answer, grazie –