How to print register values in GDB?

前端 未结 6 1436
北恋
北恋 2020-12-02 04:53

How do I print the value of %eax and %ebp?

(gdb) p $eax
$1 = void
6条回答
  •  悲&欢浪女
    2020-12-02 05:32

    p $eax works as of GDB 7.7.1

    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 = 1
    

    This 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.u
    

    From 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 http://f.osdev.org/viewtopic.php?f=1&t=25968 || 2005 feature request https://www.sourceware.org/ml/gdb/2005-03/msg00158.html || alt.lang.asm 2013 https://groups.google.com/forum/#!topic/alt.lang.asm/JC7YS3Wu31I

    ARM floating point registers

    See: https://reverseengineering.stackexchange.com/questions/8992/floating-point-registers-on-arm/20623#20623

提交回复
热议问题