答案 0 :(得分:1)
在gdb命令行上,您可以将地址转换为指针值。
(gdb) list
1 #include <stdio.h>
2
3 char * m = "this is a test\n";
4
5 main()
6 {
7 printf("%s",m);
8 }
(gdb) b 7
Breakpoint 1 at 0x400531: file example.c, line 7.
(gdb) r
Starting program: /tmp/example
Breakpoint 1, main () at example.c:7
7 printf("%s",m);
(gdb) p m
$1 = 0x4005d4 "this is a test\n"
(gdb) p *(char*)0x4005d4
$2 = 116 't'
(gdb) p *(int*)0x4005d4
$3 = 1936287860
(gdb) p *(double**)0x4005d4
$5 = (double *) 0x2073692073696874
最后两个当然是垃圾,因为值是char *。
dump命令对于查看十六进制值也很有用。
(gdb) x/20c m
0x4005d4: 116 't' 104 'h' 105 'i' 115 's' 32 ' ' 105 'i' 115 's' 32 ' '
0x4005dc: 97 'a' 32 ' ' 116 't' 101 'e' 115 's' 116 't' 10 '\n' 0 '\000'
0x4005e4: 37 '%' 115 's' 0 '\000' 0 '\000'