How to Print 64-bit Value in GDB

2

If I start a gdb session and type:

(gdb) p/x 1024*1024*1024*2
$2 = 0x80000000

But if I cross the 32 bit threshold I get:

(gdb) p/x 1024*1024*1024*4
$3 = 0x0

How does one display the entire 64 bit value in gdb?

gcc
gdb
asked on Stack Overflow Dec 11, 2017 by Whome

2 Answers

8

In addition to Yaniv's answer, you can use the ll suffix on one of the numbers (just one l may work depending on your system):

(gdb) p/x 1024*1024*1024*4ll
$2 = 0x100000000

If you need to do unsigned arithmetic, you can of course use ull.

If you want to print memory contents as 64-bit values with the x command instead, you can use the g size modifier:

(gdb) x/8xg  
0x7fffffffe008: 0x0000000000400e44  0x00007ffff7fe3000
0x7fffffffe018: 0x0000000000000000  0x0000000000000000
0x7fffffffe028: 0x0000000000f0b5ff  0x00000000000000c2
0x7fffffffe038: 0x0000000000000100  0x0000000000000001
answered on Stack Overflow Aug 5, 2018 by Calculuswhiz • edited Sep 18, 2020 by Calculuswhiz
1

Try casting the value:

(gdb) p/x (unsigned long long) 1024*1024*1024*4
$1 = 0x100000000
answered on Stack Overflow Dec 11, 2017 by Yaniv Shaked • edited Dec 11, 2017 by Yaniv Shaked

User contributions licensed under CC BY-SA 3.0