用gdb在openSUSE,CentOS,Fedora和Ubuntu上看到:
这个gdb被configuration为“x86_64-unknown-linux-gnu”。
(gdb)p sizeof(void *)
$ 1 = 4
(gdb)p sizeof(long)
$ 2 = 4
为什么gdb在我所有的64位系统上给我错误的答案?
当你不调试任何特定的代码时 ,似乎gdb选择了一些令人惊讶的默认值。 如果你加载了一个64位的可执行文件,如: gdb /bin/sh
你会得到一个不那么令人惊讶的结果:
(gdb) p sizeof(void *) $1 = 8
你也可以专门告诉gdb做什么:
(gdb) show architecture The target architecture is set automatically (currently i386) (gdb) p sizeof(void *) $1 = 4 (gdb) set architecture Requires an argument. Valid arguments are i386, i386:x86-64, i8086, i386:intel, i386:x86-64:intel, auto. (gdb) set architecture i386:x86-64 The target architecture is assumed to be i386:x86-64 (gdb) p sizeof(void *) $2 = 8