Go to main content
Oracle® Developer Studio 12.6: Debugging a Program with dbx

Exit Print View

Updated: June 2017
 
 

Sample dbx Session

The following examples use a sample program called my_program.

Main program for debugging, a1.f:

    PARAMETER ( n=2 )
    REAL twobytwo(2,2) / 4 *-1 /
    CALL mkidentity( twobytwo, n )
    PRINT *, determinant( twobytwo )
    END

Subroutine for debugging, 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

Function for debugging, 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

How to Run the Sample dbx Session

  1. Compile and link with the - g option.

    You can do this in one or two steps.

    • To compile and link in one step:
       demo% f95 -o my_program -g a1.f a2.f a3.f
    • To compile and link in separate steps:
       demo% f95 -c -g a1.f a2.f a3.f
       demo% f95 -o my_program a1.o a2.o a3.o
  2. Start dbx on the executable named my_program.
     demo% dbx my_program
     Reading symbolic information…
  3. Set a simple breakpoint.

    To stop at the first executable statement in a main program.

     (dbx) stop in MAIN
     (2) stop in MAIN

    Although the main program MAIN must be all uppercase, the names of subroutines, functions, or block data subprogramas can be uppercase or lowercase.

  4. Run the program in the executable files named when you started 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.

  5. Print a value.

    Print the value of n:

     (dbx) print n
     n = 2

    To print the matrix twobytwo, the format might vary:

     (dbx) print twobytwo
     twobytwo =
        (1,1)       -1.0
        (2,1)       -1.0
        (1,2)       -1.0
        (2,2)       -1.0

    Note that you cannot print the matrix array because array is not defined here, only in mkidentity.

  6. 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.

  7. Quit dbx.
    (dbx)quit        
    demo%