Fortran Programming Guide | ![]() ![]() ![]() ![]() ![]() |
Program Analysis and Debugging
This chapter presents a number of Sun Fortran compiler features that facilitate program analysis and debugging.
Global Program Checking (
-Xlist
)The
-Xlist
options provide a valuable way to analyze a source program for inconsistencies and possible runtime problems. The analysis performed by the compiler is global, across subprograms.
-Xlist
reports errors in alignment, agreement in number and type for subprogram arguments, common block, parameter, and various other kinds of errors.
-Xlist
also can be used to make detailed source code listings and cross-reference tables.
Note Not all the-Xlist
suboptions are available withf95
.
GPC Overview
Global program checking (GPC), invoked by the
-Xlist
x option, does the following:
- Enforces type-checking rules of Fortran more stringently than usual, especially between separately compiled routines
- Enforces some portability restrictions needed to move programs between different machines or operating systems
- Detects legal constructions that nevertheless might be suboptimal or error-prone
- Reveals other potential bugs and obscurities
In particular, global checking reports problems such as:
- Interface problems
- Conflicts in number and type of dummy and actual arguments
- Wrong types of function values
- Possible conflicts due to data type mismatches in common blocks between different subprograms
- Usage problems
- Function used as a subroutine or subroutine used as a function
- Declared but unused functions, subroutines, variables, and labels
- Referenced but not declared functions, subroutines, variables, and labels
- Usage of unset variables
- Unreachable statements
- Implicit type variables
- Inconsistency of the named common block lengths, names, and layouts
How to Invoke Global Program Checking
The
-Xlist
option on the command line invokes the compiler's global program analyzer. There are a number of suboptions, as described in the sections that follow.Example: Compile three files for basic global program checking:
demo%
f95 -Xlist any1.f any2.f any3.f
In the preceding example, the compiler:
- Produces output listings in the file
any1.lst
- Compiles and links the program if there are no errors
Screen Output
Normally, output listings produced by
-Xlist
x are written to a file. To display directly to the screen, use-Xlisto
to write the output file to/dev/tty
.Example: Display to terminal:
demo%
f77 -Xlisto /dev/tty any1.f
Default Output Features
The
-Xlist
option provides a combination of features available for output. With no other-Xlist
options, you get the following by default:
- The listing file name is taken from the first input source or object file that appears, with the extension replaced by
.lst
- A line-numbered source listing
- Error messages (embedded in listing) for inconsistencies across routines
- Cross-reference table of the identifiers
- Pagination at 66 lines per page and 79 columns per line
- No call graph
- No expansion of
include
filesFile Types
The checking process recognizes all the files in the compiler command line that end in
.f
,.f90
,.f95
,.for
,.F
,.F95
, or.o
. The.o
files supply the process with information regarding only global names, such as subroutine and function names.Analysis Files (
.fln
Files)Programs compiled with
-Xlist
options have their analysis data built into the binary files automatically. This enables global program checking over programs in libraries.Alternatively, the compiler will save individual source file analysis results into files with a
.fln
suffix if the-Xlistfln
dir option is also specified. dir indicates the directory to receive these files.
demo%f77 -Xlistfln/tmp *.f
Some Examples of
-Xlist
and Global Program CheckingHere is a listing of the
Repeat.f
source code used in the following examples:
Example: Use
-XlistE
to show errors and warnings:
Compiling the same program with
-Xlist
also produces a cross-reference table on standard output:
Output from compiling
f77 -Xlist Repeat.f
(Continued)
In the cross-reference table in the preceding example:
ix
is a 4-byte integer:
- Used as an argument in the routine
nwfrk
- At line 14, used as a declaration of argument
- At line 17, used as an actual argument
pn1
is a 4-byte real in the routinerepeat:
rp1
is a 4-byte real in the routine,repeat
. At line 2, it is an argument.x
is a 4-byte real in the routinessubr1
andprnok
:Suboptions for Global Checking Across Routines
The basic global cross-checking option is
-Xlist
with no suboption. It is a combination of suboptions, each of which could have been specified separately.The following sections describe options for producing the listing, errors, and cross-reference table. Multiple suboptions may appear on the command line.
Suboption Syntax
Add suboptions according to the following rules:
- Append the suboption to
-Xlist.
- Put no space between the
-Xlist
and the suboption.- Use only one suboption per
-Xlist.
-Xlist
and its SuboptionsCombine suboptions according to the following rules:
- The most general option is
-Xlist
(listing, errors, cross-reference table).- Specific features can be combined using
-Xlistc
,-XlistE
,-XlistL
, or -XlistX.
- Other suboptions specify further details.
Example: Each of these two command lines performs the same task:
demo%
f77 -Xlistc -Xlist any.f
demo%
f77 -Xlistc any.f
The following table shows the reports generated by these basic
-Xlist
suboptions alone:
The following table summarizes all
-Xlist
suboptions.
-Xlist
Suboption ReferenceThis section describes the
-Xlist
suboptions. As noted, some are only available withf77
.
f77: -Xlistc
-- Show call graphs and cross-routine errorsUsed alone,
-Xlistc
does not show a listing or cross-reference. It produces the call graph in a tree form, using printable characters. If some subroutines are not called fromMAIN
, more than one graph is shown. EachBLOCKDATA
is printed separately with no connection toMAIN
.The default is not to show the call graph.
-XlistE
- Show cross-routine errorsUsed alone,
-XlistE
shows only cross-routine errors and does not show a listing or a cross-reference.
-Xlisterr
[nnn] - Suppress error nnnUse
-Xlisterr
to suppress a numbered error message from the listing or cross-reference.For example:
-Xlisterr338
suppresses error message 338. If nnn is not specified, all error messages are suppressed. To suppress additional specific errors, use this option repeatedly.
-Xlistf
- Produce faster outputUse
-Xlistf
to produce source file listings and a cross-checking report and to verify sources, but without generating object files.The default without this option is to generate object files.
f77:
-Xlistfln
dir - Put.fln
files into dir directoryUse
-Xlistfln
to specify the directory to receive.fln
source analysis files. The directory specified (dir) must already exist. The default is to include the source analysis information directly within the object.o
files (and not generate.fln
files).
f77: -Xlisth
- Halt on errorsWith
-Xlisth
, compilation stops if errors are detected while cross-checking the program. In this case, the report is redirected tostdout
instead of the*.lst
file.
-XlistI
- List and cross-check include filesIf
-XlistI
is the only suboption used,include
files are shown or scanned along with the standard-Xlist
output (line numbered listing, error messages, and a cross-reference table).
- Listing--If the listing is not suppressed, then the
include
files are listed in place. Files are listed as often as they are included. The files are:- Cross-Reference Table--If the cross reference table is not suppressed, the following files are all scanned while the cross reference table is generated:
- The default is not to show
include
files.
-XlistL
- Show listing and cross routine errorsUse
-XlistL
to produce only a listing and a list of cross routine errors. This suboption by itself does not show a cross reference table. The default is to show the listing and cross reference table.
-Xlistl
n - Set the page length for pagination to n linesUse
-Xlistl
to set the page length to something other than the default page size. For example,-Xlistl45
sets the page length to 45 lines. The default is 66.With n=0 (
-Xlistl0)
this option shows listings and cross-references with no page breaks for easier on-screen viewing.
-Xlisto
name - Rename the-Xlist
output report file
Use
-Xlisto
to rename the generated report output file. (A space betweeno
and name is required.) With-Xlisto name,
the output is toname.lst
.To display directly to the screen, use the command:
-Xlisto /dev/tty
f77: -Xlists
- Suppress unreferenced identifiersUse
-Xlists
to suppress from the cross reference table any identifiers defined in theinclude
files but not referenced in the source files.This suboption has no effect if the suboption
-XlistI
is used.The default is not to show the occurrences in
#include
orINCLUDE
files.
f77: -Xlistv
n - Set level of checking strictnessn is
1,2
,3
, or4
. The default is2
(-Xlistv2
):
-Xlistv1
- Shows the cross-checked information of all names in summary form only, with no line numbers. This is the lowest level of checking strictness--syntax errors only.
-Xlistv2
- Shows cross-checked information with summaries and line numbers. This is the default level of checking strictness and includes argument inconsistency errors and variable usage errors.
-Xlistv3
- Shows cross-checking with summaries, line numbers, and common block maps. This is a high level of checking strictness and includes errors caused by incorrect usage of data types in common blocks in different subprograms.
-Xlistv4
- Shows cross-checking with summaries, line numbers, common block maps, and equivalence block maps. This is the strictest level of checking with maximum error detection.
f77: -Xlistw
[nnn] - Set width of output line to n columnsUse
-Xlistw
to set the width of the output line. For example,-Xlistw132
sets the page width to 132 columns. The default is 79.
-Xlistwar
[nnn] - Suppress warning nnn in the reportUse
-Xlistwar
to suppress a specific warning message from the output reports. If nnn is not specified, then all warning messages are suppressed from printing. For example,-Xlistwar338
suppresses warning message number 338. To suppress more than one, but not all warnings, use this option repeatedly.
-XlistX
- Show cross-reference table and cross routine errors
-XlistX
produces a cross reference table and cross routine error list but no source listing.Some Examples Using Suboptions
Example: Use
-Xlistwar
nnn to suppress two warnings from a preceding example:
Example: Explain a message and find a type mismatch in program
ShoGetc.f
:
Special Compiler Options
Some compiler options are useful for debugging. They check subscripts, spot undeclared variables, show stages of the compile-link sequence, display versions of software, and so on.
The Solaris linker has additional debugging aids. See
ld
(1), or run the commandld
-Dhelp
at a shell prompt to see the online documentation.Subscript Bounds (
-C
)The
-C
option adds checks for out-of-bounds array subscripts.If you compile with
-C
, the compiler adds checks at runtime for out-of-bounds references on each array subscript. This action helps catch some situations that cause segmentation faults.Example: Index out of range:
Undeclared Variable Types (
-u
)The
-u
option checks for any undeclared variables.The
-u
option causes all variables to be initially identified as undeclared, so that all variables that are not explicitly declared by type statements, or by anIMPLICIT
statement, are flagged with an error. The-u
flag is useful for discovering mistyped variables. If-u
is set, all variables are treated as undeclared until explicitly declared. Use of an undeclared variable is accompanied by an error message.Version Checking (
-V
)The
-V
option causes the name and version ID of each phase of the compiler to be displayed. This option can be useful in tracking the origin of ambiguous error messages and in reporting compiler failures, and to verify the level of installed compiler patches.Interactive Debugging With
dbx
and Sun WorkShopThe Sun WorkShop provides a tightly integrated development environment for building and browsing, as well as debugging applications written in Fortran, C, and C++.
The Sun WorkShop debugging facility is a window-based interface to
dbx
, whiledbx
itself is an interactive, line-oriented, source-level symbolic debugger. Either can be used to determine where a program crashed, to view or trace the values of variables and expressions in a running code, and to set breakpoints.Sun WorkShop adds a sophisticated graphical environment to the debugging process that is integrated with tools for editing, building, and source code version control. It includes a data visualization capability to display and explore large and complex datasets, simulate results, and interactively steer computations.
For details, see the Sun manual Debugging a Program With Sun WorkShop, and the
dbx
(1) man pages.The
dbx
program provides event management, process control, and data inspection. You can watch what is happening during program execution, and perform the following tasks:
- Fix one routine, then continue executing without recompiling the others
- Set watchpoints to stop or trace if a specified item changes
- Collect data for performance tuning
- Graphically monitor variables, structures, and arrays
- Set breakpoints (set places to halt in the program) at lines or in functions
- Show values--once halted, show or modify variables, arrays, structures
- Step through a program, one source or assembly line at a time
- Trace program flow--show sequence of calls taken
- Invoke procedures in the program being debugged
- Step over or into function calls; step up and out of a function call
- Run, stop, and continue execution at the next line or at some other line
- Save and then replay all or part of a debugging run
- Examine the call stack, or move up and down the call stack
- Program scripts in the embedded Korn shell
- Follow programs as they fork(2) and exec(2)
To debug optimized programs, use the
dbx fix
command to recompile the routines you want to debug:1. Compile the program with the appropriate-O
n optimization level.2. Start the execution underdbx
.3. Usefix -g
any.f
without optimization on the routine you want to debug.4. Usecontinue
with that routine compiled.Some optimizations will be inhibited by the presence of
-g
on the compilation command. See thedbx
documentation for details.
f77
: Viewing Compiler Listing DiagnosticsUse the
error
utility program to view compiler diagnostics merged with the source code.error
inserts compiler diagnostics above the relevant line in the source file. The diagnostics include the standard compiler error and warning messages, but not the-Xlist
error and warning messages.
Note Theerror
utility rewrites your source files and does not work if the source files are read-only, or are in a read only directory.
error
(1) is included as part of a "developer" installation of the Solaris operating environment; it can also be installed from the package,SUNWbtool
.
Facilities also exist in the Sun WorkShop for viewing compiler diagnostics. See Introduction to Sun WorkShop.
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |