事实上很简单,只在需要打印地址的变量前加上取地址符& 即可。具体操作如下:
imaginemiracle@ubuntu:test$ gdb a.out
如下显示则说明加载调试文件成功。
Reading symbols from a.out...
(gdb)
(gdb) l
1 int main(int argc, char **argv)
2 {
3 int a = 10;
4 int b = 20;
5
6 int result = 0;
7
8 result = a + b / a;
9
10 return 0;
(gdb) b 9
Breakpoint 1 at 0x115e: file test.c, line 10.
(gdb) r
Starting program: /home/imaginemiracle/Miracle/Source_Code/abstract_syntax_tree/test/a.out
Breakpoint 1, main (argc=1, argv=0x7fffffffe058) at test.c:10
10 return 0;
(gdb) p a
$1 = 10
(gdb) pb
Undefined command: "pb". Try "help".
(gdb) p b
$2 = 20
(gdb) p &a
$3 = (int *) 0x7fffffffdf54
(gdb) p &b
$4 = (int *) 0x7fffffffdf58
- (6) 也可以反过来使用变量的地址和变量的类型来打印出变量的值,这种同样适用于结构体等其它类型。
(gdb) p *(int *) 0x7fffffffdf54
$5 = 10
(gdb) p *(int *) 0x7fffffffdf58
$6 = 20
|