| Previous | Contents | Index |
You can use the following debugger commands when debugging any program:
DBG> SPAWN MAIL |
The OpenVMS Debugger supports breakpoints, tracepoints, and watchpoints to help you find out what happens at critical points in your program.
Set a breakpoint if you want the debugger to stop program execution at a certain point in your program (routine, line number, and so on). After you set a breakpoint and begin program execution, execution stops at the breakpoint, allowing you to look at the contents of program variables to see if they contain the correct values.
Use the following commands to control breakpoints:
Set a tracepoint to request that the debugger display messages when certain parts of your program execute. You can also specify an action for the tracepoint, such as displaying the value of a variable. Unlike breakpoints, execution continues past the tracepoint. For example, a tracepoint lets you see how many times a routine gets called.
Use the following commands to control tracepoints:
Set a watchpoint to request that the debugger stop execution when the values of certain variables (or memory locations) change. A breakpoint stops execution when a certain part of program is reached. In contrast, a watchpoint stops execution when a certain value changes.
The following commands are usually used to control watchpoints:
Before you set a breakpoint, tracepoint, or watchpoint, you can define
the scope to be used (by using the SET SCOPE or SET MODULE command, for
instance) or you can add a pathname prefix before a symbol name.
4.2.6 Ending a Debugging Session
To end a debugging session and return to the DCL level, enter EXIT or press Ctrl/Z:
DBG> EXIT $ |
The following message, displayed during a debugging session, indicates that your program has completed normally:
%DEBUG-I-EXITSTATUS, is '%SYSTEM-S-NORMAL, normal successful completion' DBG> |
To continue debugging after seeing this message, enter EXIT and start a new debugging session with the DCL RUN command.
If you specified the DEBUG command with the /KEEP qualifier when you
invoked the debugger, you can run the same program again from within
the debugging session (RERUN) and perform other functions.
4.2.7 Notes on Debugger Support for HP Fortran
In general, the debugger supports the data types and operators of HP Fortran and the other debugger-supported languages. However, the following are language-specific limitations and differences:
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. Compiler-assigned line numbers have been added in the example so that you can identify the source lines referenced in the explanatory text.
| Example 4-1 Sample Program SQUARES |
|---|
1 PROGRAM SQUARES
2 INTEGER (KIND=4) :: INARR(20), OUTARR(20)
3 ! 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 ! 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 ! 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:
$ RUN 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 use the debugger to find the error in the program in Example 4-1. Comments keyed to the callouts follow the example.
| Example 4-2 Sample Debugging Session Using Program SQUARES |
|---|
$ FORTRAN/DEBUG/NOOPTIMIZE SQUARES (1) $ LINK/DEBUG SQUARES (2) $ SHOW LOGICAL DBG$PROCESS (3) %SHOW-S-NOTRAN, no translation for logical name DBG$PROCESS $ RUN SQUARES (4) OpenVMS DEBUG (IA64 Debug64) Version x.x-xxx %DEBUG-I-INITIAL, language is FORTRAN, module set to SQUARES DBG> STEP 5 (5) stepped to SQUARES\%LINE 9 9: DO 10 I = 1, N DBG> EXAMINE N,K (6) SQUARES\N: 4 SQUARES\K: 0 DBG> STEP 2 (7) stepped to SQUARES\%LINE 11 11: OUTARR(K) = INARR(I)**2 DBG> EXAMINE I,K (8) SQUARES\I: 1 SQUARES\K: 0 DBG> DEPOSIT K = 1 (9) DBG> SET TRACE/SILENT %LINE 11 DO (DEPOSIT K = K + 1) (10) DBG> GO (11) 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 %DEBUG-I-EXITSTATUS, is 'SYSTEM-S-NORMAL, normal successful completion' DBG> EXIT (12) $ EDIT SQUARES.FOR (13) . . . 10: IF(INARR(I) .NE. 0) THEN 11: K = K + 1 12: OUTARR(K) = INARR(I)**2 13: ENDIF . . . $ FORTRAN/DEBUG/NOOPTIMIZE SQUARES (14) $ LINK/DEBUG SQUARES $ RUN SQUARES (15) OpenVMS DEBUG (IA64 Debug64) Version x.x-xxx %DEBUG-I-INITIAL, language is FORTRAN, module set to SQUARES DBG> SET BREAK %LINE 12 DO (EXAMINE I,K) (16) DBG> SHOW BREAK breakpoint at SQUARES\%LINE 12 do (EXAMINE I,K) DBG> TYPE 7:14 module SQUARES 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: K = K + 1 12: OUTARR(K) = INARR(I)**2 13: ENDIF 14: END DO DBG> GO (17) break at SQUARES\%LINE 12 12: OUTARR(K) = INARR(I)**2 SQUARES\I: 1 SQUARES\K: 1 DBG> GO break at SQUARES\%LINE 12 12: OUTARR(K) = INARR(I)**2 SQUARES\I: 2 SQUARES\K: 2 DBG> GO break at SQUARES\%LINE 12 12: OUTARR(K) = INARR(I)**2 SQUARES\I: 3 SQUARES\K: 3 DBG> GO break at SQUARES\%LINE 12 12: OUTARR(K) = INARR(I)**2 SQUARES\I: 4 SQUARES\K: 4 DBG> GO 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 %DEBUG-I-EXITSTATUS, is '%SYSTEM-S-NORMAL, normal successful completion' DBG> EXIT (18) $ |
You usually display the values of variables by using the debugger
EXAMINE command, which accepts numerous qualifiers.
4.4.1 Accessing HP Fortran Common Block Variables
To display common block variables, enter the EXAMINE command followed by the variable names that make up the common block. For example:
DBG> TYPE 1:8
1:
2: PROGRAM TEST
3: INTEGER*4 INT4
4: CHARACTER(LEN=1) CHR
5: COMMON /COM_STRA/ INT4, CHR
6: CHR = 'L'
7: INT4 = 0
8: END PROGRAM TEST
DBG> STEP 3
stepped to TEST\%LINE 8
8: END PROGRAM TEST
DBG> EXAMINE CHR, INT4
TEST\CHR: 'L'
TEST\INT4: 0
|
To display derived-type structure variables, enter the EXAMINE command followed by the derived-type variable name, a period (.) (or a %), and the member name. For example:
DBG> TYPE 1:6
1: PROGRAM TEST
2:
3: TYPE X
4: INTEGER A(5)
5: END TYPE X
6: TYPE (X) Z
7:
8: Z%A = 1
DBG> STEP 2
stepped to TEST\%LINE 10
10: END PROGRAM TEST
DBG> EXAMINE Z.A
TEST\Z.A(1:5)
(1): 1
(2): 1
(3): 1
(4): 1
(5): 1
|
To display a field in a record structure, enter the EXAMINE command followed by the record name, a period (.), and the field name. To display the entire record structure, enter EXAMINE followed by the record name. For example:
DBG> TYPE 1:9
module TEST
1: PROGRAM TEST
2: STRUCTURE /STRA/
3: INTEGER*4 INT4
4: CHARACTER(LEN=1) CHR
5: END STRUCTURE
6: RECORD /STRA/ REC
7:
8: REC.CHR = 'L'
9: END PROGRAM TEST
DBG> STEP 2
stepped to TEST\%LINE 11
11: END PROGRAM TEST
DBG> EXAMINE REC.CHR
TEST\REC.CHR: 'L'
DBG> EXAMINE REC.INT4
TEST\REC.INT4: 0
DBG> EXAMINE REC
TEST\REC
INT4: 0
CHR: 'L'
|
To display one or more array elements, enter the EXAMINE command followed by the array name and subscripts in parentheses, as in Fortran source statements. To display the entire array, enter EXAMINE following by the array name. For example:
DBG> TYPE 1:5
module ARRAY1
1: PROGRAM ARRAY1
2: INTEGER (KIND=4) ARRAY1(6)
3: ARRAY1 = 0
4: ARRAY1(1) = 1
5: ARRAY1(2) = 2
DBG> STEP 5
stepped to ARRAY1\%LINE 8
DBG> EXAMINE ARRAY1(1:2)
ARRAY\ARRAY1(1): 1
ARRAY\ARRAY1(2): 2
DBG> EXAMINE ARRAY1
ARRAY\ARRAY1(1:6)
(1): 1
(2): 2
(3): 0
(4): 0
(5): 0
(6): 0
|
To display a variable defined in a module, enter a SET MODULE command before examining module variables. For example, with a variable named PINTA defined in a module named MOD1, enter the following EXAMINE command to display its value:
DBG> SET MODULE MOD1
DBG> TYPE 1:6
1: PROGRAM USEMODULE
2: USE MOD1
3: INT4=0
4: INT4(1)=1
5: PINTA = 4
6: END PROGRAM USEMODULE
DBG> STEP 4
stepped to USEMODULE\%LINE 6
6: END PROGRAM USEMODULE
DBG> EXAMINE PINTA
USEMODULE\PINTA: 4
|
| Previous | Next | Contents | Index |