Sun Studio 12 Update 1: Debugging a Program With dbx

Array Slicing

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

Array Slicing Syntax for C and C++

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


print array-expression [first-expression .. last-expression : stride-expression]

where:

array-expression

Expression that should evaluate to an array or pointer type.

first-expression

First element to be printed. Defaults to 0.

last-expression

Last element to be printed. Defaults to upper bound.

stride-expression

Length of the stride (the number of elements skipped is stride-expression-1). Defaults to 1.

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

For example:


(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..6:2] =
[2] = 2
[4] = 4
[6] = 6

Array Slicing Syntax for Fortran

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


print array-expression [first-expression : last-expression : stride-expression]

where:

array-expression

Expression that should evaluate to an array type.

first-expression

First element in a range, also first element to be printed. Defaults to lower bound.

last-expression

Last element in a range, but might not be the last element to be printed if stride is not equal to 1. Defaults to upper bound.

stride-expression

Length of the stride. Defaults to 1.

The first expression, last expression, and stride expression are optional expressions that should evaluate to integers. For an n-dimensional slice, separate the definition of each slice with a comma.

For example:


(dbx) print arr(2:6)
arr(2:6) =
(2) 2
(3) 3
(4) 4
(5) 5
(6) 6

(dbx) print arr(2:6:2)
arr(2:6:2) =
(2) 2
(4) 4
(6) 6

To specify rows and columns, type:


demo% f95 -g -silent ShoSli.f
demo% dbx a.out
Reading symbolic information for a.out
(dbx) list 1,12
    1         INTEGER*4 a(3,4), col, row
    2         DO row = 1,3
    3             DO col = 1,4
    4               a(row,col) = (row*10) + col
    5             END DO
    6         END DO
    7         DO row = 1, 3
    8                WRITE(*,’(4I3)’) (a(row,col),col=1,4)
    9        END DO
    10        END
(dbx) stop at 7
(1) stop at "ShoSli.f":7
(dbx) run
Running: a.out
stopped in MAIN at line 7 in file "ShoSli.f"
    7          DO row = 1, 3

To print row 3, type:


(dbx) print a(3:3,1:4)
’ShoSli’MAIN’a(3:3, 1:4) =
        (3,1)   31
        (3,2)   32
        (3,3)   33
        (3,4)   34
(dbx)

To print column 4, type:


(dbx) print a(1:3,4:4)
’ShoSli’MAIN’a(1:3, 1:4) =
        (1,4)   14
        (2,4)   24
        (3,4)   34
(dbx)