开发者

In GDB how do I get globals' addresses

I have some globals that I want to inspect. but "info var my_glob开发者_StackOverflow中文版al" doesn't show the address. is there a way to get the real address of the globals?


print &my_global should work fine. A quick example:

#include <stdio.h>

int x = 12;

int main(int argc, char **argv)
{
  printf("%d\n", x);
  return 0;
}

Then build & debug:

$ make example
clang -g    example.c   -o example
$ gdb example
(gdb) break main
Breakpoint 1 at 0x100000f04: file example.c, line 8.
(gdb) run
Starting program: example 
Reading symbols for shared libraries +. done

Breakpoint 1, main () at example.c:8
8     printf("%d\n", x);
(gdb) print &x
$1 = (int *) 0x100001068
Current language:  auto; currently minimal
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜