Compaq Fortran
User Manual for
Tru64 UNIX and Linux Alpha Systems


Previous Contents Index

4.6.3 Compaq Fortran Derived-Type Variables

Variables in a Fortran 95/90 derived-type (TYPE statement) are represented in Ladebug commands such as print or whatis using Fortran 95/90 syntax form.

For derived-type structures, use the derived-type variable name, a percent sign (%), and the member name. For example:


(ladebug) list 3,11
    3  TYPE X 
    4      INTEGER A(5) 
    5    END TYPE X 
    6  
    7   TYPE (X) Z 
    8 
    9   Z%A = 1 
   10 
   11   PRINT *,Z%A
(ladebug) PRINT Z%A 
(1) 1 
(2) 1 
(3) 1 
(4) 1 
(5) 1 
(ladebug) 

4.6.4 Compaq Fortran Record Variables

To display the value of a field in a record structure, type the variable name as: the record name, a delimiter (either a period (.) or a percent sign (%)), and the field name.

To view all fields in a record structure, type the name of the record structure, such as REC (instead of REC.CHR or REC%CHR) in the previous example.

4.6.5 Compaq Fortran Pointer Variables

Compaq Fortran supports two types of pointers:

Fortran 95/90 pointers display their corresponding target data with a print command. You must specify the -ladebug option to provide Ladebug with information about pointers to arrays.


% f90 -g -ladebug point.f90
% ladebug ./a.out
Welcome to the Ladebug Debugger Version x.x-xx 
------------------ 
object file name: ./a.out 
Reading symbolic information ...done
(ladebug) stop in ptr
[#1: stop in ptr ] 
(ladebug) list 1:13
      1       program ptr 
      2 
      3       integer, target :: x(3) 
      4       integer, pointer :: xp(:) 
      5 
      6       x = (/ 1, 2, 3/) 
      7       xp => x 
      8 
      9       print *, "x = ", x 
     10       print *, "xp = ", xp 
     11 
     12       end
(ladebug) run
[1] stopped at [ptr:6 0x120001838] 
      6        x = (/ 1, 2, 3/)
(ladebug) whatis x
int x(1:3) 
(ladebug) whatis xp  (1)
int xp(:) 
(ladebug) s
stopped at [ptr:7 0x120001880] 
      7       xp => x
(ladebug) s
stopped at [ptr:9 0x120001954] 
      9       print *, "x = ", x
(ladebug) s
x =            1           2           3 
stopped at [ptr:10 0x1200019c8]
(ladebug) s
 xp =            1           2           3 
stopped at [point:12 0x120001ad8] 
     12       end
(ladebug) S  
 xp =            1           2           3
(ladebug) whatis xp (2)
int xp(1:3)
(ladebug) print xp
(1) 1 
(2) 2 
(3) 3
(ladebug) quit
%

  1. For the first whatis xp command, xp has not yet been assigned to point to variable x and is a generic pointer.
  2. Since xp has been assigned to point to variable x, for the second whatis xp command, xp takes the same size, shape, and values as x.

Like Fortran 95/90 pointers, Compaq Fortran (CRAY-style) pointers (POINTER statement) display the target data in their corresponding source form with a print command.


(ladebug) stop at 14
[#1: stop at "dfpoint.f90":14 ] 
(ladebug) run
[1] stopped at [dfpoint:14 0x1200017e4]
(ladebug) list 1,14
      1       program dfpoint 
      2 
      3       real i(5) 
      4       pointer (p,i) 
      5 
      6       n = 5 
      7 
      8       p = malloc(sizeof(i(1))*n) 
      9 
     10       do j = 1,5 
     11          i(j) = 10*j 
     12       end do 
     13 
>    14       end
(ladebug) whatis p
float (1:5) pointer p
(ladebug) print p
0x140003060 = (1) 10 
(2) 20 
(3) 30 
(4) 40 
(5) 50
(ladebug) quit
% 

4.6.6 Compaq Fortran Array Variables

For array variables, put subscripts within parentheses (( )), as with Fortran 95/90 source statements. For example:


(ladebug) assign arrayc(1)=1

You can print out all elements of an array using its name. For example:


(ladebug) print arrayc
(1) 1 
(2) 0 
(3) 0 
(ladebug) 

Avoid displaying all elements of a large array. Instead, display specific array elements or array sections. For example, to print array element arrayc(2):


(ladebug) print arrayc(2)
(2) 0

4.6.6.1 Array Sections

An array section is a portion of an array that is an array itself. An array section can use subscript triplet notation consisting of a three parts: a starting element, an ending element, and a stride.

Consider the following array declarations:


INTEGER, DIMENSION(0:99)    :: arr 
INTEGER, DIMENSION(0:4,0:4)  :: FiveByFive 

Assume that each array has been initialized to have the value of the index in each position, for example, FiveByFive(4,4) = 44, arr(43) = 43. The following examples are array expressions that will be accepted by the debugger:


(ladebug) print arr(2)
2
(ladebug) print arr(0:9:2) 
(0) = 0 
(2) = 2 
(4) = 4 
(6) = 6 
(8) = 8
(ladebug) print FiveByFive(:,3)
(0,3) = 3 
(1,3) = 13 
(2,3) = 23 
(3,3) = 33 
(4,3) = 43 
(ladebug) 

The only operations permissible on array sections are whatis and print .

4.6.6.2 Assignment to Arrays

Assignment to array elements are supported by Ladebug.

For information about assigning values to whole arrays and array sections, see the Fortran chapter in the Compaq Tru64 UNIX Ladebug Debugger Manual.

4.6.7 Complex Variables

Ladebug supports COMPLEX or COMPLEX*8, COMPLEX*16, and COMPLEX*32 variables and constants in expressions.

Consider the following Fortran program:


    PROGRAM complextest 
      COMPLEX*8 C8 /(2.0,8.0)/ 
      COMPLEX*16 C16 /(1.23,-4.56)/ 
      REAL*4     R4 /2.0/ 
      REAL*8     R8 /2.0/ 
      REAL*16    R16 /2.0/ 
 
      TYPE *, "C8=", C8 
      TYPE *, "C16=", C16 
    END PROGRAM 

Ladebug supports the display and assignment of COMPLEX variables and constants as well as basic arithmetic operators. For example:


Welcome to the Ladebug Debugger Version x.x-xx 
------------------ 
object file name: complex 
Reading symbolic information ...done
(ladebug) stop in complextest
[#1: stop in complextest ]
(ladebug) run
[1] stopped at [complextest:15 0x1200017b4] 
     15       TYPE *, "C8=", C8
(ladebug) whatis c8
complex c8
(ladebug) whatis c16
double complex c16
(ladebug) print c8
(2, 8)
(ladebug) print c16
(1.23, -4.56)
(ladebug) assign c16=(-2.3E+10,4.5e-2)
(ladebug) print c16
(-23000000512, 0.04500000178813934)
(ladebug)  

4.6.8 Compaq Fortran Data Types

The Compaq Fortran data types and their equivalent built-in debugger names are as follows:
Fortran 95/90 Data Type Declaration Debugger Equivalent
CHARACTER character
INTEGER, INTEGER(KIND= n) integer, integer*n
LOGICAL, LOGICAL (KIND= n) logical, logical*n
REAL, REAL(KIND=4) real
DOUBLE PRECISION, REAL(KIND=8) real*8
REAL(KIND=16) real*16
COMPLEX, COMPLEX(KIND=4) complex
DOUBLE COMPLEX, COMPLEX(KIND=8) double complex
COMPLEX(KIND=16), COMPLEX*32 long double complex

4.7 Expressions in Debugger Commands

Expressions in debugger commands use Fortran 95/90 source language syntax for operators and expressions.

4.7.1 Fortran Operators

The Compaq Fortran operators include the following:

For a complete list of operators, see the Compaq Fortran Language Reference Manual.

Enclose debugger command expressions between curly braces ({ }). For example, the expression print k in the following statement is enclosed between curly braces ({ }):


(ladebug) when at 12 {print k}

4.7.2 Procedures

The Ladebug debugger supports invocation of user-defined specific procedures using Fortran 95/90 source language syntax. Ladebug also supports the invocation of some of the Fortran 95/90 generic and specific procedures, currently limited to scalar arguments.

For a complete list of intrinsic procedures, see the Compaq Fortran Language Reference Manual.

For a list of supported intrinsic procedures and known limitations of that support, see the Compaq Tru64 UNIX Ladebug Debugger Manual.

4.8 Debugging Mixed-Language Programs with Ladebug

The Ladebug debugger lets you debug mixed-language programs. Program flow of control across subprograms written in different languages is transparent.

The debugger automatically identifies the language of the current subprogram or code segment on the basis of information embedded in the executable file. For example, if program execution is suspended in a subprogram in Fortran, the current language is Fortran. If the debugger stops the program in a C function, the current language becomes C. The debugger uses the current language to determine the valid expression syntax and the semantics used to evaluate an expression.

The debugger sets the $lang variable to the language of the current subprogram or code segment. By manually setting the $lang debugger variable, you can force the debugger to interpret expressions used in commands by the rules and semantics of a particular language. For example, you can check the current setting of $lang and change it as follows:


(ladebug) print $lang
"C++"
(ladebug) set $lang = "Fortran"

When the $lang environment variable is set to "Fortran", names are case insensitive. To make names case-sensitive when the program was compiled with the -names as_is option, specify another language for the $lang environment variable, such as C, view the variable, then set the $lang environment variable to "Fortran".

4.9 Debugging a Program that Generates an Exception

If your program encounters an exception at run-time, to make it easier to debug the program, you should recompile and relink with the following f90 options before debugging the cause of the exception:

If requested, Ladebug will catch and handle exceptions before the Compaq Fortran run-time library. This prevents the Compaq Fortran run-time library from displaying exception handling messages.

Use the Ladebug commands catch and ignore to control whether Ladebug handles (catches) exceptions or ignores them:

To obtain the appropriate Compaq Fortran run-time error message when debugging a program that generates an exception (especially one that allows program continuation), you may need to use the appropriate ignore command before running the program. For instance, use the following command to tell the debugger to ignore floating-point exceptions and pass them through to the Compaq Fortran run-time library:


(ladebug) ignore fpe

In cases where you need to locate the part of the program causing an exception, consider using the where command.

4.10 Locating Unaligned Data

As discussed in Chapter 5, unaligned data can slow program execution. You should determine the cause of the unaligned data, fix the source code (if necessary), and recompile and relink the program.

If your program encounters unaligned data at run-time, to make it easier to debug the program, you should recompile and relink with the following f90 options before debugging the cause of the exception:

Locating Unaligned Data With Ladebug

To determine the cause of the unaligned data when using Ladebug, follow these steps:

  1. Run the Ladebug debugger, specifying the program with the unaligned data (shown as testprog in the following example):


    % ladebug testprog
    

  2. Before you run the program, enter the catch unaligned command:


    (ladebug) catch unaligned
    

  3. Run the program:


    (ladebug) run 
    Unaligned access pid=28413 <a.out> va=140000154 pc=3ff80805d60 
        ra=1200017e8 type=stl 
    Thread received signal BUS 
    stopped at [oops:13 0x120001834] 
         13       end
    

  4. Enter a list command to display the source code at line 12:


    (ladebug) list 12
      12        i4 = 1
    > 13          end
    

  5. Enter the where command to find the location of the unaligned access:


    (ladebug) where
    

  6. Use any other appropriate debugger commands needed to isolate the cause of the unaligned data, such as up , list , and down .
  7. Repeat these steps for other areas where unaligned data is reported. Use the rerun command to run the program again instead of exiting the debugger and running it from the shell prompt.
    After fixing the causes of the unaligned data (see Section 5.3), compile and link the program again.

Locating Unaligned Data With dbx

To determine the cause of the unaligned data when using dbx (TU*X ONLY), follow these steps:

  1. Write down the addresses reported in the run-time message (see Section 5.3.2). For this example, assume the pc address in the "Unaligned access" message is 0x1200017f0.
  2. Run the debugger, specifying the program with the unaligned data (shown as testprog in the following example):


    % dbx testprog
    

  3. Set a breakpoint at the address reported in the warning message by using the stopi at command (shown as 0x1200017f0 below):


    (dbx) stopi at 0x1200017f0
     stopi at 0x1200017f0] 
    

  4. Run the program. It will stop at the breakpoint:


    (dbx) run
    [2] stopi at 0x1200017f0] 
    [2] stopped at >*[oops:12, 0x1200017f0]         stl     r3, 0(r1)
    

  5. Type the where command to find the location of the unaligned access:


    (dbx) where
    

  6. Use any other appropriate debugger commands needed to isolate the cause of the unaligned data, such as list , up , and down .
  7. Repeat these steps for other addresses that warning messages report.
  8. After fixing the causes of the unaligned data (see Section 5.3), compile and link the program again.

4.11 Using Alternate Entry Points

If a subprogram uses alternate entry points (ENTRY statement within the subprogram), Ladebug handles alternate entry points as separate subprograms, including:

4.12 Debugging Optimized Programs

The Compaq Fortran compiler performs code optimizations ( -O4 ) by default, unless you specify -g (or -g2 ).

Debugging optimized code is recommended only under special circumstances; for example, if a problem disappears when you specify the -O0 option.

One aid to debugging optimized code is to use one of the following command-line options:

By referring to a listing of the generated code, you can see how the compiler optimizations affected your code. This lets you determine the debugging commands you need in order to isolate the problem.

For a discussion of compiler optimizations, see Section 5.8 and Section 5.7.

When you try to perform a debugger operation on a variable or language construct that has been optimized, the variable or line may not exist in the debugging environment. For example:

For more information on optimizations, see Section 5.7 and Section 5.8.


Previous Next Contents Index