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

set print array-indexes command

Enables or disables display of array element indicies.


set print array-indexes on
set print array-indexes off
show print array-indexes


GDB will display the array contents in a simple list format (e.g. $1 = {1, 2, 3}).
GDB will display the array contents in a longer format tha includes element indicies (e.g. $1 = {[0] = 1, [1] = 2, [2] = 3}).

Default mode

The default value for the print array-indexes setting is 'off'.


The set print array-indexes command can be used together with the set print array command to further customize the output of the array contents.


Below is a log of sample GDB session illustrating how set print array-indexes command affects the output of the print command:

(gdb) start
Temporary breakpoint 1 at 0x80483f3: file test.cpp, line 5.
Starting program: /home/bazis/test

Temporary breakpoint 1, main (argc=1, argv=0xbffff064) at test.cpp:5
5 int testArray[] = {1, 2, 3};
(gdb) next
6 return 0;
(gdb) print testArray
$1 = {1, 2, 3}
(gdb) show print array-indexes
Printing of array indexes is off.
(gdb) set print array-indexes on
(gdb) print testArray
$2 = {[0] = 1, [1] = 2, [2] = 3}

Compatibility with VisualGDB

Do not use the set print array-indexes command with VisualGDB. VisualGDB relies on the default array output format used by GDB and disabling this feature can stop VisualGDB from functioning correctly.

See also