HP Fortran Programmer Guide (766160-001, March 2014)

4 Debugging
This chapter describes different HP Fortran features for debugging programs. These features include
compile-line options, compiler directives, and programming tools that are useful for locating errors
in your program. More specifically, this chapter discusses the following topics:
Using the HP WDB debugger
Stripping debugging information
Handling runtime exceptions
Using debugging lines
Using the HP WDB debugger
The HP WDB debuggeris the primary tool for debugging HP Fortran programs. The debugger
provides such basic debugging functions as program control, process control, program and data
monitoring, and expression evaluation. The debugger has both a graphical interface and a
line-mode interface.
The debugger software includes different managers that enable it to handle different source
languages, target machines, object file formats, and user formats. The Fortran language manager
allows you to use Fortran syntax when entering expressions on the debugger command line.
Before beginning a debugging session, you must compile the program with the -gcompile-line
option. If you compile and link separately, you must use the -goption on both command lines. The
option causes the compiler to generate additional information needed by the debugger and to
insert it into the output code.
After compiling your program with the -goption, invoke the debugger with the wdbcommand,
supplying the name of the executable as an argument. For example, the following command
compiles prog.f90for debugging:
$ f90 -g prog.f90 -o db_prog
Here is the command to start debugging the executable program:
$ wdb db_prog
You can use the debugger to debug code that has been optimized at levels 0, 1, and 2. To debug
optimized code, compile the program with both the -gand +Oopt-leveloptions, where opt-level
is 0, 1, or 2. The following command line prog.f90at optimization level 2 and prepares for
debugging:
$ f90 +O2 -g prog.f90 -o db_prog
Compiling with the -goption increases the size of both the object file and the executable file. After
you have debugged your program and are ready to build the production version, you may want
to recompile without the -goption.
For complete information about HP WDB debugger, see http://www.hp.com/go/wdb. Printed
and online documentation are available at this site.
Stripping debugging information
Programs compiled with HP Fortran include minimal debugging information in the executable
program. This information consists of a symbol table—a list of all the symbols in your program
and their offset addresses. The symbol table provides the information needed to produce a procedure
traceback. It is also used by the debugger and by the CXperf performance analysis tool.
However, the symbol table is not the same as the debugging information that is added to your
program when you compile with the -goption. The symbol table is added to an executable even
if the program is not compiled with the -goption.
76 Debugging