C H A P T E R 5 |
Program Analysis and Debugging |
This chapter presents a number of compiler features that facilitate program analysis and debugging.
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.
Programs compiled with -Xlist options have their analysis data built into the binary files automatically. This enables global program checking over programs in libraries.
Global program checking (GPC), invoked by the -Xlistx option, does the following:
In particular, global checking reports problems such as:
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:
Normally, output listings produced by -Xlistx are written to a file. To display directly to the screen, use -Xlisto to write the output file to /dev/tty.
demo% f95 -Xlisto /dev/tty any1.f |
The -Xlist option provides a combination of features available for output. With no other -Xlist options, you get the following by default:
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.
Here is a listing of the Repeat.f source code used in the following examples:
Example: Use -XlistX to show errors, warnings, and cross-reference
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.
Add suboptions according to the following rules:
Combine suboptions according to the following rules:
Example: Each of these two command lines performs the same task:
demo% f95 -Xlistc -Xlist any.f |
demo% f95 -Xlistc any.f |
The following table shows the reports generated by these basic -Xlist suboptions alone:
The following table shows all -Xlist suboptions.
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 command ld -Dhelp at a shell prompt to see the online documentation.
If you compile with -C, the compiler adds checks at runtime for out-of-bounds references on each array subscript, and array conformance. This action helps catch some situations that cause segmentation faults.
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 an IMPLICIT 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.
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.
Sun ONE Studio provides a tightly integrated development environment for debugging applications written in Fortran, C, and C++.
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:
To debug optimized programs, use the dbx fix command to recompile the routines you want to debug:
1. Compile the program with the appropriate -On optimization level.
2. Start the execution under dbx.
3. Use fix -g any.f without optimization on the routine you want to debug.
4. Use continue with that routine compiled.
Some optimizations will be inhibited by the presence of -g on the compilation command. See the dbx documentation for details.
For details, see the Sun ONE Studio Debugging a Program With dbx manual, and the dbx(1) man pages.
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.