HP-UX Fortran77 Traceback

The 3 step plan to printing a traceback instead of dumping core

(1) include the directive

$OPTION CODE_OFFSETS

as the first line in each source file (easily automated, esp. dynamically); this creates a table which maps the hex offsets reported in a traceback to source code line numbers. Requires -V compiler flag.

(2) compile with the additional f77 options +T -V

Compiler flags and their meaning
flag meaning
+T produces a traceback with hex offsets on failures, not a core dump
-V produce a source listing file, with line numbers and hex offset map
Other useful options
+R include cross-reference listing
-C check array subscripts at execute time
-K make arrays static, zero arrays; equivalent to save, zero options on historic compilers; often makes code run slower, but some "dusty deck" source assumes this behavior, and fails without -K

(3) trap floating point underflow errors

Since +T disables all the standard f.p. error routines, one usually has to add an f.p. underflow trap to do useful work. In the initialization code I put:

      ON REAL UNDERFLOW CALL HPREALUF
      ON DOUBLE PRECISION UNDERFLOW CALL HPDBLEUF

This enables 2 user trap handlers; the code for them is simple--

      SUBROUTINE HPREALUF(U)
      REAL U
      U = 0.0
      RETURN
      END

      SUBROUTINE HPDBLEUF(U)
      DOUBLE PRECISION U
      U = 0.d0
      RETURN
      END

This is all that's required to get tracebacks which can (indirectly) point to the source code line number, even for code compiled with -O or +O3, with no cryptic and tedious debugger syntax to deal with. The traeback itself includes the routine names and a hexadecimal offset; the listing file produced by the -V option contains a cross reference between source line numbers and hexadecimal offsets. The correspondence is approximate, however, for optimized code.
Information and HTML pages provided by:
NHLBI/LBC Computational Biophysics Section
CBER/OVRR Biophysics Laboratory