在openSUSE,CentOS,Fedora和Ubuntu上看到gdb:
此gdb配置为“x86_64-unknown-linux-gnu”。
(gdb)p sizeof(void *)
$ 1 = 4
(gdb)p sizeof(长)
$ 2 = 4
为什么gdb会在我的所有64位系统上给出错误的答案?
答案 0 :(得分:26)
当你没有调试任何特定的代码时,gdb似乎会选择一些令人惊讶的默认值。如果您在gdb /bin/sh
中加载64位可执行文件,则会得到一个不太令人惊讶的结果:
(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