Search code examples
gdb

GDB: How to remove a variable from the auto display


I stumbled upon the auto-display functionality of gdb, which is pretty powerful and convenient. After calling

(gdb) display/i $pc
(gdb) display $rax

the watched values are displayed automatically after every step:

(gdb) si
0x0804805e in print_loop_start ()
2: $rax = 0
1: x/i $pc
=> 0x804805e <print_loop_start+6>:  mov    0x4(%ebp,%eax,4),%ecx

But how can I "unwatch" the value in $rax, if it is no longer of interest?


Solution

  • Gdb help for display says:

    "Use undisplay to cancel display requests previously made."

    So if you do display a, then display b, and display c gdb will give numbers to this requests (which you can see by issuing replay with no arguments). Then you can use this numbers with undisplay.

    Example:

    (gdb) display a
    1: a = 32767
    (gdb) display b
    2: b = 0
    (gdb) display c
    3: c = 0
    (gdb) undisplay 2
    (gdb) step
    6     b = 2;
    1: a = 1
    3: c = 0
    

    Details in gdb documentation.