为什么从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
很好的答案,谢谢 –