Seen with gdb on openSUSE, CentOS, Fedora, and Ubuntu:
在openSUSE、CentOS、Fedora和Ubuntu中看到gdb:
This gdb was configured as "x86_64-unknown-linux-gnu".
这个gdb被配置为“x86_64-unknown-linux-gnu”。
(gdb) p sizeof(void *)
(gdb)p sizeof(void *)
$1 = 4
1美元= 4
(gdb) p sizeof(long)
(gdb)p sizeof(长)
$2 = 4
2 = 4美元
Why is gdb giving me the wrong answers on all of my 64-bit systems?
为什么gdb在我所有的64位系统上都给了我错误的答案?
1 个解决方案
#1
25
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似乎选择了一些令人惊讶的默认值。如果加载一个64位的可执行文件,如:gdb /bin/sh,您会得到一个不那么令人惊讶的结果:
(gdb) p sizeof(void *)
$1 = 8
You can also specifically tell gdb what to do:
你也可以特别告诉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
#1
25
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似乎选择了一些令人惊讶的默认值。如果加载一个64位的可执行文件,如:gdb /bin/sh,您会得到一个不那么令人惊讶的结果:
(gdb) p sizeof(void *)
$1 = 8
You can also specifically tell gdb what to do:
你也可以特别告诉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