V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Kristd
V2EX  ›  程序员

gdb 设置了 disable-randomization off, 那么数组依然打印的这些固定地址是为什么呢?{0xad8010, 0x500000000, 0x0, 0x7f889b8fc76d, 0x0}

  •  
  •   Kristd · 2019-04-10 20:16:58 +08:00 · 1447 次点击
    这是一个创建于 1814 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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}
    

    首地址变成动态了, 后面的固定地址是什么原理

    3 条回复    2019-04-11 01:10:40 +08:00
    bumz
        1
    bumz  
       2019-04-10 20:23:00 +08:00
    The addresses of stack variables will not change across different debugging sessions.

    http://visualgdb.com/gdbreference/commands/set_disable-randomization

    你这是堆的,取决于 glibc 的 malloc 怎么实现,和 kernel 提供的 aslr 没关系
    ashlord
        2
    ashlord  
       2019-04-10 20:48:29 +08:00
    p@5 没有意义吧,显示的实际是*(&p + 0)到*(&p + 4)的值,而不是 p 指向的 array 后续元素的地址啊
    amosasas
        3
    amosasas  
       2019-04-11 01:10:40 +08:00
    @bumz 学到了。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   947 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:29 · PVG 05:29 · LAX 14:29 · JFK 17:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.