Supported on windows
Supported on linux
Supported on embedded
Supported on android

display command

Enables automatic displaying of certain expressions each time GDB stops at a breakpoint or after a step.

Syntax

display [Expression]
x /[Format] [Expression]
display

Parameters

Expression
Specifies the expression that will be automatically evaluated and displayed after each step. Run the display command without any arguments to show the current list expressions enabled for auto-displaying.
Format
If specified, allows overriding the output format used by the command. Valid format specifiers are:
  • o - octal
  • x - hexadecimal
  • d - decimal
  • u - unsigned decimal
  • t - binary
  • f - floating point
  • a - address
  • c - char
  • s - string
  • i - instruction

The following size modifiers are supported:

  • b - byte
  • h - halfword (16-bit value)
  • w - word (32-bit value)
  • g - giant word (64-bit value)

Remarks

To remove an expression from the auto-display list use the undisplay command.

Examples

We will demonstrate the display command using a basic program that displays its arguments in a loop:

#include <stdio.h>

int main(int argc, char **argv)
{
  for(int i = 0; i < argc; i++)
    printf("Arg %d: %s\n", i, argv[i]);
  return 0;
}

We will use the display command to let GDB display the value of the loop counter and the currently displayed argument after each step:

(gdb) set args arg1 arg2 arg3
(gdb) start
Temporary breakpoint 1 at 0x8048426: file test.cpp, line 5.
Starting program: /home/bazis/test arg1 arg2 arg3

Temporary breakpoint 1, main (argc=4, argv=0xbffff024) at test.cpp:5
5 for(int i = 0; i < argc; i++)
(gdb) next
6 printf("Arg %d: %si, argv[i]);
(gdb) display/x i
1: /x i = 0x0
(gdb) display argv[i]
2: argv[i] = 0xbffff204 "/home/bazis/test"
(gdb) next
Arg 0: /home/bazis/test
5 for(int i = 0; i < argc; i++)
2: argv[i] = 0xbffff204 "/home/bazis/test"
1: /x i = 0x0
(gdb) next
6 printf("Arg %d: %si, argv[i]);
2: argv[i] = 0xbffff215 "arg1"
1: /x i = 0x1
(gdb) display
2: argv[i] = 0xbffff215 "arg1"
1: /x i = 0x1
(gdb) undisplay 1
(gdb) next
Arg 1: arg1
5 for(int i = 0; i < argc; i++)
2: argv[i] = 0xbffff215 "arg1"
(gdb) next
6 printf("Arg %d: %si, argv[i]);
2: argv[i] = 0xbffff21a "arg2"
(gdb) undisplay
Delete all auto-display expressions? (y or n) y
(gdb) next
Arg 2: arg2
5 for(int i = 0; i < argc; i++)
(gdb) next
6 printf("Arg %d: %si, argv[i]);
(gdb) print i
$1 = 3

Compatibility with VisualGDB

Normally you don't need to use the display command under VisualGDB. Use the Watch window in Visual Studio instead.

See also