找到变量 Buf 的确切地址 [英] Find the exact address of variable Buf

查看:22
本文介绍了找到变量 Buf 的确切地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为参考,我使用以下代码:

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
", &buf);
    strcpy (buf, "some random text");
    printf ("Text is [%s]
", buf);

    return 0;
}

如何让 gdb 显示 buf 变量的地址?

How can I get gdb to show me the address of the buf variable?

推荐答案

(gdb) p &a 如果需要变量a的地址.不过,变量可能会缓存在寄存器中,在这种情况下,GDB 会告诉您 为寄存器 $xxx 中的标识符a"请求的地址.

(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.

旁注:不要使用 gets,请参阅此处.

Sidenote: do not use gets, see here.

这篇关于找到变量 Buf 的确切地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆