136

Currently, when I print the value of a variable v in GDB (print v) I get an integer.

Is it possible to have GDB print such integer variables in hexadecimal or binary?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Randomblue
  • 112,777
  • 145
  • 353
  • 547

1 Answers1

225

Sure it is. Try these:

# Hexadecimal
p/x variable

# Binary
p/t variable

See output formats.

remcycles
  • 1,246
  • 13
  • 14
cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • 2
    if you are using DDD(data display debuger, a GUI wrapper for a debugger like GDB), you can use the hex format also in graphic display by doing `graph disp /x val1`. Beware you should put space before `/x`. otherwise it doesn't work. – Chan Kim Sep 18 '17 at 06:10
  • 3
    and to set the default output radix setting, see https://stackoverflow.com/questions/6618670/how-to-make-gdb-print-out-all-values-in-hexadecimal-mode – Chan Kim Sep 10 '18 at 01:19
  • To show the values of an [array](https://www.sourceware.org/gdb/onlinedocs/gdb/Arrays.html) in hex, use `p/x *my_arr@arr_len`. – Matthias Braun Jun 16 '23 at 22:07