在 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
关于linux - 为什么 gdb 告诉我指针在 x86-64 上是 4 个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3232279/