【发布时间】:2011-10-11 01:25:02
【问题描述】:
为什么从 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 运行程序,它从未出现过 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
$
但程序的正常执行总是会产生 SEGFAULT。
$ ./a.out
Segmentation fault
我不知道这个问题是否与Is this always the address for GDB debug program?重复
注意:我没有关闭 ASLR
【问题讨论】:
标签: c memory-management gdb