Debugging a Program With dbx

Syntax for Array Slicing and Striding

Array-slicing is supported in the print and display commands for C, C++, and Fortran.

Array-slicing syntax for C and C++, where:


print arr-exp [first-exp
 .. last-exp : stride-exp
]

arr-exp

Expression that should evaluate to an array or pointer type. 

first-exp

First element to be printed. Defaults to 0. 

last-exp

Last element to be printed. Defaults to its upper bound. 

stride-exp

Stride. Defaults to 1. 

The first, last, and stride expressions are optional expressions that should evaluate to integers.


(dbx) print arr[2..4]
arr[2..4] =
[2] = 2
[3] = 3
[4] = 4
(dbx) print arr[..2]
arr[0..2] =
[0] = 0
[1] = 1
[2] = 2
 
(dbx) print arr[2..6:2]
arr[2..8:2] =
[2] = 2
[4] = 4
[6] = 6

For each dimension of an array, the full syntax of the print command to slice the array is the following:


(dbx) print arr(exp1:exp2:exp3)

exp1

start_of_slice 

exp2

end_of_slice 

exp3

length_of_stride (the number of elements skipped is exp3 - 1)

For an n-dimensional slice, separate the definition of each slice with a comma:


(dbx) print arr(exp1:exp2:exp3, exp1:exp2:exp3,...)
 

Slices

Here is an example of a two-dimensional, rectangular slice, with the default stride of 1 omitted:


print arr(201:203, 101:105)

Graphic

The first two expressions (201:203) specify a slice in the first dimension of this two-dimensional array (the three-row column). The slice starts at the row 201 and ends with 203. The second set of expressions, separated by a comma from the first, defines the slice for the 2nd dimension. The slice begins at column 101 and ends after column 105.

Strides

When you instruct print to stride across a slice of an array, dbx evaluates certain elements in the slice only, skipping over a fixed number of elements between each one it evaluates.

The third expression in the array slicing syntax, (exp3), specifies the length of the stride. The value of exp3 specifies the elements to print; the number of elements skipped is equal to exp3 -1. The default stride value is 1, meaning: evaluate all of the elements in the specified slices.

Here is the same array used in the previous example of a slice; this time the print command includes a stride of 2 for the slice in the second dimension.


print arr(201:203, 101:105:2)

Graphic

For any expression you omit, print takes a default value equal to the declared size of the array. Here are examples showing how to use the shorthand syntax.

print arr

Prints entire array, default boundaries. 

print arr(:)

Prints entire array, default boundaries and default stride of 1. 

print arr(::exp3)

Prints the whole array with a stride of exp3.

For a one-dimensional array:

For a two-dimensional array the following command prints the entire array:


print arr

To print every third element in the second dimension of a two-dimensional array:


print arr (:,::3)