作为引用,我使用以下代码:
#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/