
int main() { int* p = 0; p = (int*)malloc(5*sizeof(int)); unsigned int i = 0; for (i = 0; i < 5; i++) { p[i] = i+1; } free(p); return 0; } 每次执行的打印结果
(gdb) p p@5 $3 = {0xad8010, 0x500000000, 0x0, 0x7f889b8fc76d, 0x0} (gdb) p p@5 $4 = {0x1522010, 0x500000000, 0x0, 0x7f58f8f1676d, 0x0} 首地址变成动态了, 后面的固定地址是什么原理
1 bumz 2019 年 4 月 10 日 The addresses of stack variables will not change across different debugging sessions. http://visualgdb.com/gdbreference/commands/set_disable-randomization 你这是堆的,取决于 glibc 的 malloc 怎么实现,和 kernel 提供的 aslr 没关系 |
2 ashlord 2019 年 4 月 10 日 p@5 没有意义吧,显示的实际是*(&p + 0)到*(&p + 4)的值,而不是 p 指向的 array 后续元素的地址啊 |