找到变量Buf的确切地址 [英] Find the exact address of variable Buf
本文介绍了找到变量Buf的确切地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为参考,我使用以下代码:
#include
#include< string.h>
int main(void){
char buf [100]; // ------>我如何在gdb中找到地址?
printf(Buffer is at memory location:%08x \\\
,& buf);
strcpy(buf,一些随机文本);
printf(Text is [%s] \\\
,buf);
返回0;
如何获得 gdb
向我显示 buf
变量的地址
a
的地址,(gdb)p& a
一个变量可能被缓存在一个寄存器中,在这种情况下,GDB会告诉你请求的标识符a的地址在$ xxx
中。 旁注:不要使用 gets
,参见这里。
As reference, I'm using the following code:
#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;
}
How can I get gdb
to show me the address of the buf
variable?
解决方案
(gdb) p &a
if you need the address of variable a
. A variable might be cached in a register though, in which case GDB would tell you address requested for identifier "a" which is in register $xxx
.
Sidenote: do not use gets
, see here.
这篇关于找到变量Buf的确切地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文