为什么gdb告诉我x86-64上的指针是4个字节? [英] Why does gdb tell me a pointer is 4 bytes on x86-64?
问题描述
在openSUSE,CentOS,Fedora和Ubuntu上与gdb一起观看:
Seen with gdb on openSUSE, CentOS, Fedora, and Ubuntu:
此gdb被配置为"x86_64-unknown-linux-gnu".
This gdb was configured as "x86_64-unknown-linux-gnu".
(gdb)p sizeof(void *)
(gdb) p sizeof(void *)
$ 1 = 4
(gdb)p sizeof(long)
(gdb) p sizeof(long)
$ 2 = 4
为什么gdb在我所有的64位系统上给我错误的答案?
Why is gdb giving me the wrong answers on all of my 64-bit systems?
推荐答案
当您不调试任何特定代码时,似乎gdb选择了一些令人惊讶的默认值.如果您按以下方式加载64位可执行文件: gdb/bin/sh
,您会得到意想不到的结果:
It seems like gdb chooses some surprising defaults when you're not debugging any particular piece of code. If you load up a 64-bit executable as in: gdb /bin/sh
you get a less-surprising result:
(gdb) p sizeof(void *)
$1 = 8
您还可以明确告诉gdb该怎么做:
You can also specifically tell gdb what to do:
(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
这篇关于为什么gdb告诉我x86-64上的指针是4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!