zekethegeke
zekethegeke

Reputation: 61

In GDB how do I get globals' addresses

I have some globals that I want to inspect. but "info var my_global" doesn't show the address. is there a way to get the real address of the globals?

Upvotes: 0

Views: 145

Answers (1)

Carl Norum
Carl Norum

Reputation: 224834

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

Upvotes: 2

Related Questions