The following examples use a sample program called my_program.
Compile and link with the dbx- -g flag. You can do this in one or two steps.
Compile and link in one step, with --g:
demo% f77 -o my_program -g a1.f a2.f a3.f
Or, compile and link in separate steps:
demo% f77 -c -g a1.f a2.f a3.f demo% f77 -o my_program a1.o a2.o a3.o
Start dbx on the executable named my_program:
demo% dbx my_program Reading symbolic information...
Set a simple breakpoint by typing stop in subnam, where subnam names a subroutine, function, or block data subprogram.
To stop at the first executable statement in a main program:
(dbx) stop in MAIN (2) stop in MAIN
Although MAIN must be in uppercase, subnam can be uppercase or lowercase.
Type the run command, which runs the program in the executable files named when you started dbx.
Run the program from within dbx:
(dbx) run Running: my_program stopped in MAIN at line 3 in file "a1.f" 3 call mkidentity( twobytwo, n )
When the breakpoint is reached, dbx displays a message showing where it stopped--in this case, at line 3 of the a1.f file.
To print a value, type the print command.
(dbx) print n n = 2
Print the matrix twobytwo; the format may vary:
(dbx) print twobytwo twobytwo = (1,1) -1.0 (2,1) -1.0 (1,2) -1.0 (2,2) -1.0
(dbx) print array dbx: "array" is not defined in the current scope (dbx)
The print fails because array is not defined here--only in mkidentity.
To advance execution to the next line, type the next command.
Advance execution to the next line:
(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%
The next command executes the current source line and stops at the next line. It counts subprogram calls as single statements.
Compare next with step. The step command executes the next source line or the next step into a subprogram. If the next executable source statement is a subroutine or function call, then:
step sets a breakpoint at the first source statement of the subprogram.
next sets the breakpoint at the first source statement after the call, but still in the calling program.
To quit dbx, type the quit command.
(dbx)quit demo%