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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With