Why does gdb tell me a pointer is 4 bytes on x86-64?

老子叫甜甜 提交于 2020-12-08 05:26:39

问题


Seen with gdb on openSUSE, CentOS, Fedora, and Ubuntu:

This gdb was configured as "x86_64-unknown-linux-gnu".

(gdb) p sizeof(void *)

$1 = 4

(gdb) p sizeof(long)

$2 = 4

Why is gdb giving me the wrong answers on all of my 64-bit systems?


回答1:


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

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


来源:https://stackoverflow.com/questions/3232279/why-does-gdb-tell-me-a-pointer-is-4-bytes-on-x86-64

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!