简体   繁体   中英

How to Print 64-bit Value in 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?

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

Try casting the value:

(gdb) p/x (unsigned long long) 1024*1024*1024*4
$1 = 0x100000000

in my gdb script. I used a gdb-script file, in order to reproduce the debugging process by gdb bin -x gdb.txt , so printf is used:

printf "0x%llx\n", $rax

works.

pwndbg> printf "0x%llx\n", $rax
0x7ffff77c0068

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM