Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Print 64-bit Value in GDB

Tags:

gcc

gdb

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?

like image 288
Whome Avatar asked Oct 15 '25 04:10

Whome


2 Answers

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
like image 104
General Grievance Avatar answered Oct 18 '25 02:10

General Grievance


Try casting the value:

(gdb) p/x (unsigned long long) 1024*1024*1024*4
$1 = 0x100000000
like image 39
Yaniv Shaked Avatar answered Oct 18 '25 01:10

Yaniv Shaked



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!