HP/DDE Debugger User's Guide: HP 9000 Series 700/800 Computers > Chapter 4 Viewing and Manipulating Target
Program Data Examining Variables and Expressions |
|
Variables are evaluated in the scope of the current location, as indicated in the Current Location: line above the source file display. Usually the current location follows the PC (program counter) location, so variables are evaluated in the environment where your program is executing. For example, when you are single-stepping through your source, the current location is in the procedure you are stepping through. If you want to evaluate a variable in the scope of another function on the current call stack, use the up arrow and down arrow buttons next to the Stack Frame: label in the current location line. (Or choose Show:Stack and choose a stack frame in the Stack View dialog box.) This sets the current location to the specified function in the call stack. To evaluate in the scope of a function that is not in the current call stack, enter the function name in the ( ): input box and choose Visit:Procedure() to set the current location to that function. Finally, you can always specify the variable fully with the appropriate DDE syntax (see Chapter 7 “Identifying Program Objects ”). This syntax overrides the current location. The PC arrow points to the line that will be executed next. (The PC location arrow changes to a broken variant to indicate when the current point of execution is either at another source statement on the same line or at an instruction beyond the statement's first instruction.) When the arrow points to an assignment statement, the assignment has not yet been executed. To see the result of an assignment statement, step past it (or step over it if it calls a function). When reporting a value, the debugger uses qualifiers in the form:
For example, the following print command output indicates that x is local to the routine sum of the module test:
You can eliminate qualifiers by entering the command property qual_max 0. For more information on qualifiers, see “Using Qualified Names ”. There are two command buttons that allow you to display values of variables. The values are printed in the debugger output area. The following buttons are located below the source file display area:
You can double-click or highlight the variable name or expression in the program source to copy it to the ( ): input box. If the current location points to the procedure containing the variable, you can use the name of the variable without any qualifiers. If not, specify it according to the rules defined in “Using Qualified Names ”. Another method for examining variables and expressions is to use the mouse as follows:
As shown in Figure 4-1 “The Data Value Tear-Off Menu ”, a number of print commands are available from the Data Value menu. Invoke it from Show:Data Value. The Data Value menu is a Tear-off Menu. When you click on the dashed line at the top, the menu is displayed in its own window The menu persists so that you can invoke commands from it without having to redisplay it. You can also move the menu to a convenient place in your workspace. If you prefer to use debugger commands, the following list shows some common usages:
The next sections give you some idea of the the versatility and flexibility of these commands. They describe how to use debugger commands to examine arrays, pointers, linked lists, and buffers. The online command reference gives more examples and describes all the options for each command. To print an entire array, enter the print command and specify the array name without a subscript. For example, suppose the array list is declared as follows:
The following command prints the array list:
To print a portion of an array, enter the range as the subscript. Specify a range in the form element..element for C, C++, and Pascal, and as element:element for FORTRAN. For example, the following command prints list[1] through list[3] in the C language array list:
To specify a limit on the number of elements the print command displays, use the property array_dim_max command. For example, property array_dim_max 10 sets the limit at 10. To examine an object referenced by a pointer, enter the print command and either dereference the pointer using language-specific syntax or use the print command's -indirect option. For example, assume that C is the current language and that int_ptr contains the address of the variable num, whose value is 7. You could print the value pointed to by int_ptr using C language syntax for dereferencing pointers, as the following example illustrates:
In languages that support special interpretation of pointers to characters:
For example, assume that C is the current language and that char_ptr points to the first element in the string success:
Instead of using language-specific syntax, you can use the -indirect option to the print command as follows:
Use the print command's -indirect option to examine linked lists. Enter -indirectcount to print a specific number of records in a linked list. For example, the following command prints the record pointed to by first_item, as well as the next record in the linked list:
To print an entire linked list you could specify -indirect all. But if the linked list is large, the output may become unwieldy, since every link to each record is shown. To print all the records in a large linked list, you can make the debugger walk through the list and print each record separately. Use the while command, as shown in the following example:
The set command assigns the value of first_item to the pointer item. The while command then executes the commands between the brackets as long as item points to an address. The commands between the brackets print the current record and increment item. All output is redirected to the file tmp.out. For more information on grouping commands to perform useful tasks, see “Combining Debugger Commands Using Action Lists ”. Use the describe, print, and dump commands to examine buffers. The describe command with the -va option is useful for finding the virtual address of an element in a buffer. In the following example, the describe command is used to display the virtual address of an element in a character buffer (called buff) from a C language program:
The print command can also display the address of an element. However, it also displays the contents of the buffer starting from the specified element. Notice the use of the & operator in the following example:
Use print with the following syntax to display the contents of a single element in the buffer:
For large buffers, the dump command is useful because you can use the -from and -to options to specify address ranges. Also, dump takes a number of options that allow you to format the output. The following example shows a sequence of commands that determine an address range in a buffer. Then, the dump command prints the data in the address range:
Notice that the -char option causes the output to be displayed as characters. The -bits 256 option specifies that the output should be formatted in units of 256 bits or 32 characters. See the online command reference for more information on the describe, print, and dump commands. |