linux - 为什么 gdb 告诉我指针在 x86-64 上是 4 个字节?

标签 linux gdb

在 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/

相关文章:

linux - 预期的二元运算符

c - 如何修复GDB的错误 "Invalid address specified to RtlFreeHeap"

c - 反汇编 C 代码并检查堆栈

c++ - 如何获取gdb中数据成员的值?

linux - gdb 不显示非剥离可执行文件的源代码

c++ - Qt应用程序启动崩溃

linux - ecryptfs 大小与主目录大小不同

linux - Shell 读取并保存到 config.cfg 文件?

json - 使用 jq 和引用值处理 json 数组

python - 无法找到 python 字节码解释器的 gdb 框架