gpt4 book ai didi

gdb - 找到变量 Buf 的确切地址

转载 作者:行者123 更新时间:2023-12-03 10:51:20 27 4
gpt4 key购买 nike

作为引用,我使用以下代码:

#include <stdio.h>
#include <string.h>

int main (void) {
char buf[100]; // ------> How do I find the address in gdb?

printf ("Buffer is at memory location: %08x\n", &buf);
strcpy (buf, "some random text");
printf ("Text is [%s]\n", buf);

return 0;
}

我怎样才能得到 gdb给我看 buf 的地址多变的?

最佳答案

(gdb) p &a如果你需要变量的地址 a .但是,变量可能会缓存在寄存器中,在这种情况下,GDB 会告诉您 address requested for identifier "a" which is in register $xxx .

旁注:不要使用 gets ,见 here .

关于gdb - 找到变量 Buf 的确切地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4462915/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com