Sun Studio 12: Debugging a Program With dbx

Locating Exceptions

If a program gets an exception, there are many possible causes. One approach to locating the problem is to find the line number in the source program where the exception occurred, and then look for clues there.

Compiling with -ftrap=common forces trapping on all common exceptions.

To find where an exception occurred:

demo% cat wh.f
                 call joe(r, s)
                 print *, r/s
                 subroutine joe(r,s)
                 r = 12.
                 s = 0.
demo% f95 -g -o wh -ftrap=common wh.f
demo% dbx wh
Reading symbolic information for wh
(dbx) catch FPE
(dbx) run
Running: wh
(process id 17970)
signal FPE (floating point divide by zero) in MAIN at line 2 in file “wh.f”
   2                     print *, r/s