How to print register values in GDB?
Sebastian Wright
How do I print the value of %eax and %ebp?
(gdb) p $eax
$1 = void 1 7 Answers
info registers shows all the registers; info registers eax shows just the register eax. The command can be abbreviated as i r
If you're trying to print a specific register in GDB, you have to omit the % sign. For example,
info registers eipIf your executable is 64 bit, the registers start with r. Starting them with e is not valid.
info registers ripThose can be abbreviated to:
i r rip There is also:
info all-registersThen you can get the register name you are interested in -- very useful for finding platform-specific registers (like NEON Q... on ARM).
2- If only want check it once,
info registersshow registers. - If only want watch one register, for example,
display $espcontinue display esp registers in gdb command line. - If want watch all registers,
layout regscontinue show registers, with TUI mode.
Gdb commands:
i r <register_name>: print a single register, e.gi r rax,i r eaxi r <register_name_1> <register_name_2> ...: print multiple registers, e.gi r rdi rsi,i r: print all register except floating point & vector register (xmm, ymm, zmm).i r a: print all register, include floating point & vector register (xmm, ymm, zmm).i r f: print all FPU floating registers (st0-7and a few otherf*)
Other register groups besides a (all) and f (float) can be found with:
maint print reggroupsas documented at:
Tips:
xmm0~xmm15, are 128 bits, almost every modern machine has it, they are released in 1999.ymm0~ymm15, are 256 bits, new machine usually have it, they are released in 2011.zmm0~zmm31, are 512 bits, normal pc probably don't have it (as the year 2016), they are released in 2013, and mainly used in servers so far.- Only one serial of xmm / ymm / zmm will be shown, because they are the same registers in different mode. On my machine ymm is shown.
p $eax works as of GDB 7.7.1
Tested as of GDB 7.7.1, the command you've tried works:
set $eax = 0
p $eax
# $1 = 0
set $eax = 1
p $eax
# $2 = 1This syntax can also be used to select between different union members e.g. for ARM floating point registers that can be either floating point or integers:
p $s0.f
p $s0.uFrom the docs:
Any name preceded by ‘$’ can be used for a convenience variable, unless it is one of the predefined machine-specific register names.
and:
You can refer to machine register contents, in expressions, as variables with names starting with ‘$’. The names of registers are different for each machine; use info registers to see the names used on your machine.
But I haven't had much luck with control registers so far: OSDev 2012 || 2005 feature request || alt.lang.asm 2013
ARM floating point registers
See:
3Easiest for me is:
(gdb) x/x $eaxFirst x stands for examine and second x is hex. You can see other formats using:
(gdb) help xYou can easily print strings with x/s $eax or return addresses with x/a $ebp+4.