爲什麼從gdb運行代碼時,我得到的聲明變量的地址相同,但是在執行二進制文件時,我沒有得到相同的地址。爲什麼一個局部變量的地址在執行多次時會有所不同,但在使用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));
}
我通過gdb運行程序,它從來沒有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
$
但是,正常執行程序總是會產生一個SEGFAULT。
$ ./a.out
Segmentation fault
我不知道這個問題是Is this always the address for GDB debug program?
注意重複:我還沒有關閉ASLR
很好的答案,謝謝 –