次の例では、サンプルプログラム my_program を使用します。
デバッグのためのメインプログラム、a1.f:
PARAMETER ( n=2 ) REAL twobytwo(2,2) / 4 *-1 / CALL mkidentity( twobytwo, n ) PRINT *, determinant( twobytwo ) END
デバッグのためのサブルーチン、a2.f:
SUBROUTINE mkidentity ( array, m ) REAL array(m,m) DO 90 i = 1, m DO 20 j = 1, m IF ( i .EQ. j ) THEN array(i,j) = 1. ELSE array(i,j) = 0. END IF 20 CONTINUE 90 CONTINUE RETURN END
デバッグのための関数 a3.f
REAL FUNCTION determinant ( a ) REAL a(2,2) determinant = a(1,1) * a(2,2) - a(1,2) * a(2,1) RETURN END
この処理は、まとめて 1 回または 2 回に分けて実行することができます。
demo% f95 -o my_program -g a1.f a2.f a3.f
demo% f95 -c -g a1.f a2.f a3.f demo% f95 -o my_program a1.o a2.o a3.o
demo% dbx my_program Reading symbolic information…
main プログラム中の最初の実行可能文で停止します。
(dbx) stop in MAIN (2) stop in MAIN
メインプログラム MAIN はすべて大文字である必要がありますが、サブルーチン、関数、またはブロックデータサブプログラムの名前は大文字と小文字のどちらでもかまいません。
(dbx) run Running: my_program stopped in MAIN at line 3 in file "a1.f" 3 call mkidentity( twobytwo, n )
ブレークポイントに到達すると、dbx はどこで停止したかを示すメッセージを表示します。前述の例では、a1.f ファイルの行番号 3 で停止しています。
n の値を出力します。
(dbx) print n n = 2
行列 twobytwo を出力するには、形式が変わる可能性があります。
(dbx) print twobytwo twobytwo = (1,1) -1.0 (2,1) -1.0 (1,2) -1.0 (2,2) -1.0
array はここではなく、mkidentity でしか定義されていないため、行列 array は出力できないことに注意してください。
(dbx) next stopped in MAIN at line 4 in file "a1.f" 4 print *, determinant( twobytwo ) (dbx) print twobytwo twobytwo = (1,1) 1.0 (2,1) 0.0 (1,2) 0.0 (2,2) 1.0 (dbx) quit demo%
next コマンドは現在のソース行を実行し、次のソース行で停止します。これは副プログラムの呼び出しを 1 つの文として数えます。
(dbx)quit demo%