Previous | Contents | Index |
To find out what happens at critical points in your program, you need to stop execution at these points and look at the contents of program variables to see if they contain the correct values. Points at which the debugger stops program execution are called breakpoints.
To set a breakpoint, use one of the forms of the stop or stopi commands.
Using the program created in Section 4.3.1, the following debugger commands set a breakpoint at line 4, run the program, continue the program, delete the breakpoint, rerun the program, and return to the shell:
(ladebug) stop at 4 [#1: stop at "squares.for":4 ] (ladebug) run [1] stopped at [squares:4 0x120001880] > 4 OPEN(UNIT=8, FILE='datafile.dat', STATUS='OLD') (ladebug) cont Process has exited with status 0 (ladebug) delete 1 (ladebug) rerun Process has exited with status 0 (ladebug) quit % |
Other debugger commands include the following:
(ladebug) sh grep FUNCTION data.for INTEGER*4 FUNCTION SUBSORT (A,B) (ladebug) stop in subsort (ladebug) |
For a list of known Ladebug limitations, see the Compaq Tru64 UNIX Ladebug Debugger Manual.
4.4 Sample Program and Debugging Session
Example 4-1 shows a program called SQUARES that requires debugging. The program was compiled and linked without diagnostic messages from either the compiler or the linker. However, this program contains a logic error in an arithmetic expression.
Compiler-assigned line numbers have been added in the example so that you can identify the source lines to which the explanatory text refers.
Example 4-1 Sample Program SQUARES |
---|
1 PROGRAM SQUARES 2 INTEGER INARR(20), OUTARR(20) 3 C ! Read the input array from the data file. 4 OPEN(UNIT=8, FILE='datafile.dat', STATUS='OLD') 5 READ(8,*,END=5) N, (INARR(I), I=1,N) 6 5 CLOSE (UNIT=8) 7 C ! Square all nonzero elements and store in OUTARR. 8 K = 0 9 DO I = 1, N 10 IF (INARR(I) .NE. 0) THEN 11 OUTARR(K) = INARR(I)**2 12 ENDIF 13 END DO 14 15 C ! Print the squared output values. Then stop. 16 PRINT 20, K 17 20 FORMAT (' Number of nonzero elements is',I4) 18 DO I = 1, K 19 PRINT 30, I, OUTARR(I) 20 30 FORMAT(' Element',I4,' has value',I6) 21 END DO 22 END PROGRAM SQUARES |
The program SQUARES performs the following functions:
When you run SQUARES, it produces the following output, regardless of the number of nonzero elements in the data file:
% squares Number of nonzero elements is 0 |
The error occurs because variable K, which keeps track of the current index into OUTARR, is not incremented in the loop on lines 9 through 13. The statement K = K + 1 should be inserted just before line 11.
Example 4-2 shows how to start the debugging session and how to use the character-cell interface to the Ladebug debugger to find the error in the sample program in Example 4-1. Comments keyed to the callouts follow the example.
Example 4-2 Sample Debugging Session Using Program Squares |
---|
% f90 -g -ladebug -o squares squares.f90 (1) % ladebug squares (2) Welcome to the Ladebug Debugger Version x.x-xx --------------- object file name: squares reading symbolic information ... done (ladebug) list 1,9 (3) 1 PROGRAM SQUARES 2 INTEGER INARR(20), OUTARR(20) 3 C ! Read the input array from the data file. > 4 OPEN(UNIT=8, FILE='datafile.dat', STATUS='OLD') 5 READ(8,*,END=5) N, (INARR(I), I=1,N) 6 5 CLOSE (UNIT=8) 7 C ! Square all nonzero elements and store in OUTARR. 8 K = 0 9 DO 10 I = 1, N (ladebug) stop at 8 (4) [#1: stop at "squares.f90":8] (ladebug) run (5) [1] stopped at ["squares.f90":4 0x120001a88] > 8 K = 0 (ladebug) step (6) stopped at [squares:9 0x120001a90] 9 DO 10 I = 1, N (ladebug) print n, k (7) 4 0 (ladebug) step (8) stopped at [squares:10 0x120001ab0]] 10 IF(INARR(I) .NE. 0) THEN (ladebug) s stopped at [squares:11 0x1200011acc] 11 OUTARR(K) = INARR(I)**2 (ladebug) print i, k (9) 1 0 (ladebug) assign k = 1 (10) (ladebug) watch variable k (11) [#2: watch variable (write) k 0x1400002c0 to 0x1400002c3 ] (ladebug) cont (12) Number of nonzero elements is 1 Element 1 has value 4 Process has exited with status 0 (ladebug) quit (13) % vi squares.f90 (14) . . . 10: IF(INARR(I) .NE. 0) THEN 11: K = K + 1 12: OUTARR(K) = INARR(I)**2 13: ENDIF . . . % f90 -g -ladebug -o squares squares.f90 (15) % ladebug squares Welcome to the Ladebug Debugger Version x.x-xx Reading symbolic information ...done (ladebug) when at 12 {print k} (16) [#1: when at "squares.for":12 { print K} ] (ladebug) run (17) [1] when [squares:12 0x120001ae0] 1 [1] when [squares:12 0x120001ae0] 2 [1] when [squares:12 0x120001ae0] 3 [1] when [squares:12 0x120001ae0] 4 Number of nonzero elements is 4 Element 1 has value 9 Element 2 has value 4 Element 3 has value 25 Element 4 has value 4 Process has exited with status 0 (ladebug) quit (18) % |
% dbx squares dbx version x.x Type 'help' for help. squares: 4 OPEN(UNIT=8, FILE='datafile.dat', STATUS='OLD') (dbx) |
Table 4-2 lists some of the more frequently used debugging commands available in Ladebug and dbx. Many of these commands can be abbreviated (such as typing c instead of cont ). When using the debugger with a windowing interface, you can access these commands by using the windowing interface (command buttons and command menu). For a complete list of available debugger commands, see the ladebug(1) reference page.
Command Example | Description |
---|---|
catch | Displays all signals that the debugger is currently set to catch (see also ignore ). |
catch fpe | Tells the debugger to catch the fpe signal (or the signal specified). This prevents the specified signal from reaching the Compaq Fortran RTL. The signals that the Compaq Fortran RTL arranges to catch are listed in Section 8.3. |
catch unaligned | Tells the debugger to catch the unaligned signal, as further described in Section 4.10. The signals that the Compaq Fortran RTL arranges to catch are listed in Section 8.3. |
cont | Resumes execution of the program that is being debugged. Note that there is no Ladebug command named continue . |
delete 2 | Removes the breakpoint or tracepoint identified by event number 2 (see also status ). |
delete all | Removes all breakpoints and tracepoints. |
help | Displays debugger help text. |
history 5 | Displays the last 5 debugger commands. |
ignore | Displays the signals the debugger is currently set to ignore. The ignored signals are allowed to pass directly to the Compaq Fortran RTL. (see also catch ). |
ignore fpe | Tells the debugger to ignore the fpe signal (or the signal specified). This allows the specified signal to pass directly to the Compaq Fortran RTL, allowing message display. The signals that the Compaq Fortran RTL arranges to catch are listed in Section 8.3. |
ignore unaligned | Tells the debugger to ignore the unaligned signal (the default). |
kill | Terminates the program process, leaving the debugger running and its breakpoints and tracepoints intact for when the program is rerun. |
list | Displays source program lines. To list a range of lines, add the starting line number, a comma (,), and the ending line number, such as list 1,9 . |
print k | Displays the value of the specified variable, such as K. |
printregs | Displays all registers and their contents. |
next | Steps one source statement but does not step into calls to subprograms (compare with step ). |
quit | Ends the debugging session. |
run | Runs the program being debugged. You can specify program arguments and redirection. |
rerun | Runs the program being debugged again. You can specify program arguments and redirection. |
return [ routine-name] |
When using the
step
command, if you step into a subprogram that does not require further
investigation, use the
return
command to continue execution of the current function until it returns
to its caller. If you include the name of a routine with the
return
command, execution continues until control is returned to that routine.
The routine-name is the name of the routine, usually named by a PROGRAM, SUBROUTINE, or FUNCTION statement. If there is no PROGRAM statement, the debugger refers to the main program with a prefix of main$ followed by the file name. |
sh more progout.f90 | Executes the shell command more to display file progout.f90 , then returns to the debugger environment. |
show thread | Lists all threads known to the Ladebug debugger. |
status | Displays breakpoints and tracepoints with their event numbers (see also delete ). |
step | Steps one source statement, including stepping into calls of a subprogram. For Compaq Fortran I/O statements, intrinsic procedures, 3f library routines, or other subprograms, use the next command instead of step to step over the subprogram call. Compare with next ; also see return . |
stop in foo | Stops execution (breakpoint) at the beginning of routine foo. |
stop at 100 | Stops execution at line 100 (breakpoint) of the current source file. |
stopi at xxxxxxx | Stops execution at address xxxxxxx of the current executable program. |
thread [ n] | Identifies or sets the current thread context (ladebug). |
watch location | Displays a message when the debugger accesses the specified memory location. For example, watch 0x140000170 . |
watch variable m | Displays a message when the debugger accesses the variable specified by m. |
whatis sum | Displays data type of specified symbol. |
when at 9 { command} | When a specified line (such as 9) is reached, the command or commands are executed. For example, when at 9 {print k} prints the value of variable K when the program executes source code line 9. |
when in name { command} | When a procedure specified by name is reached, the command or commands are executed. For example, when in calc_ave {print k} prints the value of variable K when the program begins executing the procedure named calc_ave. |
where | Displays the call stack. |
where thread all | Displays the stack traces of all threads. |
The debuggers support other special-purpose commands. For example:
To refer to a variable, use either the uppercase or lowercase letters. For example:
(ladebug) print J (ladebug) print j |
You can enter command names in uppercase:
(ladebug) PRINT J |
If you compile the program with the
f90
command option
-names as_is
and you need to examine case-sensitive names, you can control whether
Ladebug is case sensitive by setting the
$lang
environment variable to the name of a case-sensitive language (see
Section 4.8).
4.6.1 Compaq Fortran Module Variables
To refer to a variable defined in a module, insert a dollar sign ($), the module name, and another dollar sign ($) before the variable name. For example, with a variable named J defined in a module named modfile (statement MODULE MODFILE), enter the following command to display its value:
(ladebug) list 5,9 5 USE MODFILE 6 INTEGER*4 J 7 CHARACTER*1 CHR 8 J = 2**8 (ladebug) PRINT $MODFILE$J 256 |
You can display the values of variables in a Fortran common block by using debugger commands such as print or whatis .
To display the entire common block, use the common block name.
To display a specific variable in a common block, use the variable name. For example:
(ladebug) list 1,11 1 PROGRAM EXAMPLE 2 3 INTEGER*4 INT4 4 CHARACTER*1 CHR 5 COMMON /COM_STRA/ INT4, CHR 6 7 CHR = 'L' 8 9 END (ladebug) PRINT COM_STRA COMMON INT4 = 0 CHR = "L" (ladebug) (ladebug) PRINT CHR "L" |
If the name of a data item in a common block has the same name as the common block itself, the data item is accessed.
Previous | Next | Contents | Index |