0
我有一些我想要檢查的全局變量。但「info var my_global」不顯示地址。有沒有辦法獲得全局變量的真實地址?在GDB中我如何獲取全局變量的地址
我有一些我想要檢查的全局變量。但「info var my_global」不顯示地址。有沒有辦法獲得全局變量的真實地址?在GDB中我如何獲取全局變量的地址
print &my_global
應該可以正常工作。一個簡單的例子:
#include <stdio.h>
int x = 12;
int main(int argc, char **argv)
{
printf("%d\n", x);
return 0;
}
然後建立&調試:
$ 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