Previous | Contents | Index |
This series of STEP and EXAMINE commands shows the content of the union as the different members are assigned values:
DBG> step stepped to STRUCT\main\%LINE 31 31: uv.cm = 'a'; DBG> examine uv.fm STRUCT\main\uv.fm: 3.0000001E+10 DBG> step stepped to STRUCT\main\%LINE 32 33: } DBG> examine/ascii uv.cm STRUCT\main\uv.cm: "a" |
Example C-5 shows the DEC C program ARSTRUCT.C used in the examples that follow.
Example C-5 Debugging Sample Program ARSTRUCT.C |
---|
/* ARSTRUCT.C This program contains a structure definition * * and a for loop to demonstrate the debugger's * * support for DEC C operators. */ main() { int count, i = 1; char c = 'A'; struct { int digit; char alpha; } tbl[27], *p; for (count = 0; count <= 26; count++) { tbl[count].digit = i++; tbl[count].alpha = c++; } } |
The following examples are based on executing ARSTRUCT.EXE and show the use of C expressions on the debugger command line.
Relational operators can be used in expressions (such as count == 2 ) in a WHEN clause to set a conditional breakpoint:
DBG> set break %line 20 when (count == 2) DBG> go break at ARSTRUCT\main\%LINE 20 20: } |
The first EVALUATE command that follows uses C syntax to refer to the address of a variable. It is equivalent to the second command, which uses the /ADDRESS qualifier to obtain the address of the variable. The addresses of these variables might not be the same every time you execute the program if you relink the program.
DBG> evaluate &tbl 2146736881 DBG> evaluate/address tbl 2146736881 |
Individual members of an aggregate can be evaluated; the debugger returns the value of the member:
DBG> evaluate tbl[2].digit 3 |
When you perform pointer arithmetic, the debugger displays a message indicating the scale factor that has been applied. It then returns the address resulting from the arithmetic operation. A subsequent EXAMINE command at that address returns the value of the variable:
DBG> evaluate tbl + 4 %DEBUG-I-SCALEADD, pointer addition: scale factor of 5 applied to right argument 2146736901 DBG> examine 2146736901 ARSTRUCT\main\tbl[4].digit: 5 |
The EVALUATE command can perform arithmetic operations on program variables:
DBG> evaluate tbl[4].digit * 2 10 |
The EVALUATE command can also perform arithmetic calculations that may or may not be related to your program. In effect, this command can be used as a calculator that uses C syntax for arithmetic expressions:
DBG> evaluate 7 % 3 1 |
The debugger enters a message when you use an unsupported operator:
DBG> evaluate count++ %DEBUG-W-SIDEFFECT, operators with side effects not supported (++, --) |
Example C-6 shows the DEC C program POWER.C to be used in the sample debugging session shown in Example C-7.
Example C-6 Debugging Sample Program POWER.C |
---|
/* POWER.C This program contains two functions: "main" and * * "power." The main function passes a number to * * "power", which returns that number raised to the * * second power. */ main() { static int i, j; int power(int); i = 2; j = power(i); } power(int j) { return (j * j); } |
Although this program contains no errors, Example C-7 shows some simple debugger commands that can be used to evaluate its execution. The callout numbers in this sample debugging session are keyed to the notes that follow.
Example C-7 A Sample Debugging Session |
---|
(1) $ CC/DEBUG/NOOPTIMIZE POWER $ LINK/DEBUG POWER $ RUN POWER OpenVMS DEBUG Version 6.n (2) %DEBUG-I-INITIAL, language is C, module set to 'POWER' (3) DBG> set break %LINE 13 (4) DBG> go (5) break at POWER\main\%LINE 13 (6) 13: j = power(i); (7) DBG> step/into (8) stepped to routine POWER\power 16: int j; DBG> step stepped to POWER\power\%LINE 18 18: return (j * j) (9) DBG> examine J (10) %DEBUG-W-NOSYMBOL, symbol 'J' is not in the symbol table DBG> examine j (11) POWER\power\j: 2 DBG> step stepped to POWER\main\%LINE 13+9 13: j = power(i); DBG> step stepped to POWER\main\%LINE 14 14: } DBG> examine j (12) POWER\main\j: 4 DBG> go (13) %DEBUG-I-EXITSTATUS, is '%SYSTEM-S-NORMAL, normal successful completion' (14) DBG> exit $ |
Key to Example C-7:
DBG> |
The DIGITAL Text Processing Utility (DECTPU) (provided with the OpenVMS operating system) is a high-performance, programmable utility. DECTPU provides a number of special features, such as multiple buffers and windows, definable keys and key sequences, a procedural language, and a callable interface.
DECTPU serves as a base on which to layer other text processing applications, for example, text editors. The Extensible VAX Editor (EVE) is the editor provided with DECTPU. To invoke EVE, enter the following command at the DCL prompt:
$ EDIT/TPU USER.C |
To exit from EVE, press the Do key to get the Command: prompt. If you want to save modifications to your file, enter the EXIT command. If you do not want to save the file or any modification to the file, enter the QUIT command.
For information on DECTPU and EVE, see the Guide to VMS Text Processing.
C.3 Language-Sensitive Editor and the Source Code Analyzer
The DIGITAL Language-Sensitive Editor (LSE) and the DIGITAL Source Code Analyzer (SCA) must be purchased separately from the OpenVMS operating system. LSE is a text editor intended specifically for software development. SCA is an interactive tool for program analysis.
These products are closely integrated; generally, SCA is invoked through LSE. LSE provides additional editing features that make SCA program analysis more efficient. In addition, LSE and SCA, in conjunction with the DEC C compiler, provide a set of new enhancements supporting source code design and review.
In addition to text editing features, LSE provides the following software development features:
SCA performs the following types of program analysis:
LSE and SCA together, in conjunction with DIGITAL language compilers, provide the following software design features:
The following sections provide entry, exit, and language-specific
information on the combined use of LSE and SCA. For more information on
LSE and SCA, see the Guide to Language-Sensitive Editor for VMS Systems and the Guide to Source Code Analyzer for VMS Systems. For more
information on CMS, see the Guide to Code Management System for VMS Systems.
C.3.1 Preparing an SCA Library
SCA stores data generated by the DEC C compiler in an SCA library. The data in an SCA library contains information about all symbols, modules, and files encountered during a specific compilation of the source. You must prepare this library before you enter LSE to invoke SCA. This preparation involves the following steps:
$ CREATE/DIRECTORY PROJ:[USER.LIB1] |
$ SCA CREATE LIBRARY [.LIB1] |
$ SCA SET LIBRARY [.EXISTING_SCA_LIBARAY] |
$ CC/ANALYSIS_DATA PG1,PG2,PG3 |
$ SCA LOAD PG1,PG2,PG3 |
To invoke LSE, enter the following command at the DCL prompt:
$ LSEDIT USER.C |
To end an LSE session, press Ctrl/Z to get the LSE> prompt. If you want to save modifications to your file, enter the EXIT command. If you do not want to save the file or any modification to the file, enter the QUIT command.
To invoke SCA from the LSE prompt, enter the SCA command that you want to execute using the following syntax:
LSE> command [parameter] [/qualifier...] |
To invoke SCA from the DCL command line for the execution of a single command, use the following syntax:
$ SCA command [parameter] [/qualifier...] |
If you have several SCA commands to invoke, you might want to first invoke the SCA subsystem and then enter SCA commands:
$ SCA SCA> command [parameter] [/qualifier...] |
Typing EXIT (or pressing Ctrl/Z) ends an SCA subsystem session and
returns you to the DCL level.
C.3.3 Programming Language Placeholders and Tokens
The LSE language-sensitive features simplify the tasks of developing and maintaining software systems. These features include language-specific placeholders and tokens, aliases, comment and indentation control, and templates for subroutine libraries.
You can use LSE as a traditional text editor. In addition, you can use the power of LSE's tokens and placeholders to step through each program construct and supply text for those constructs that need it.
Placeholders are markers in the source code that indicate where you can provide program text. These placeholders help you to supply the appropriate syntax in a given context. You do not need to type placeholders; they are inserted for you by LSE. Placeholders are surrounded by brackets or braces and at (@) signs.
Placeholders are either optional or required. Required placeholders, indicated by braces ({}), represent places in the source code where you must provide program text. Optional placeholders, indicated by brackets ([]), represent places in the source code where you can either provide additional constructs or erase the placeholder.
You can move forward or backward from placeholder to placeholder. In addition, you can delete or expand placeholders as needed.
Tokens typically represent keywords in DEC C. When expanded, tokens provide additional language constructs. You can type tokens directly into the buffer. You use tokens in situations, such as modifying an existing program, where you want to add additional language constructs and there are no placeholders. For example, typing IF and entering the EXPAND command causes a template for an IF construct to appear on your screen. You can also use tokens to bypass long menus in situations where expanding a placeholder, such as {@statement@}, will result in a lengthy menu.
You can use tokens to insert text when editing an existing file by typing the name for a function or keyword and entering the EXPAND command.
LSE provides commands for manipulating tokens and placeholders. Table C-1 shows these commands and their default key bindings.
Command | Key Binding | Function |
---|---|---|
EXPAND | Ctrl/E | Expands a placeholder. |
UNEXPAND | PF1-Ctrl/E | Reverses the effect of the most recent placeholder expansion. |
GOTO PLACEHOLDER/FORWARD | Ctrl/N | Moves the cursor forward to the next placeholder. |
GOTO PLACEHOLDER/REVERSE | Ctrl/P | Moves the cursor backward to the next placeholder. |
ERASE PLACEHOLDER/FORWARD | Ctrl/K | Erases a placeholder. |
UNERASE PLACEHOLDER | PF1-Ctrl/K | Restores the most recently erased placeholder. |
<downarrow symbol> | Down-arrow | Moves the indicator downward through a screen menu. |
<uparrow symbol> | Up-arrow | Moves the indicator upward through a screen menu. |
[Enter]
[Return] |
|
Selects a menu option. |
To display a list of all the defined tokens provided by DEC C, enter the following LSE command:
LSE> SHOW TOKEN |
To display a list of all the defined placeholders provided by DEC C, enter the following LSE command:
LSE> SHOW PLACEHOLDER |
To put either list into a separate file, first enter the appropriate SHOW command to put the list into the $SHOW buffer. Then enter the following commands:
LSE> GOTO BUFFER $SHOW LSE> WRITE filename |
To obtain a hard copy of the list, use the PRINT command at DCL level to print the file you created.
To obtain information about a particular token or placeholder, specify
a token name or placeholder name after the SHOW TOKEN or SHOW
PLACEHOLDER command.
C.3.4 Compiling Source Code
To compile your source code and to review compilation errors without leaving the editing session, use the LSE commands COMPILE and REVIEW. The COMPILE command issues a DCL command in a subprocess to invoke the DEC C compiler. The compiler then generates a file of compile-time diagnostic information that LSE uses to review compilation errors. The diagnostic information is generated with the /DIAGNOSTICS qualifier that LSE appends to the compilation command.
For example, if you enter the COMPILE command while in the buffer USER.C, the following DCL command is executed:
$ CC USER.C/DIAGNOSTICS=USER.DIA |
LSE supports all the DEC C compiler's command qualifiers as well as user-supplied command procedures.
The REVIEW command displays any diagnostic messages that result from a compilation. LSE displays the compilation errors in one window and the corresponding source code in a second window. This multiwindow capability allows you to review your errors while examining the associated source code.
To compile a DEC C program that contains placeholders and design comments, include the following qualifiers to the COMPILE command:
LSE> COMPILE $/ANALYSIS_DATA/DESIGN |
The /ANALYSIS_DATA qualifier generates a data analysis file containing source code analysis information. This information is provided to the SCA library.
The /DESIGN qualifier instructs the compiler to recognize placeholders and design comments as valid program elements. If the /ANALYSIS_DATA qualifier is also specified, the compiler includes information on placeholders and design comments in the data analysis file.
Previous | Next | Contents | Index |