在openSUSE,CentOS,Fedora和Ubuntu上看到gdb:
这个gdb配置为"x86_64-unknown-linux-gnu".
(gdb)p sizeof(void*)
1美元= 4美元
(gdb)p sizeof(长)
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