HPlogo HP/DDE Debugger User's Guide: HP 9000 Series 700/800 Computers > Chapter 4 Viewing and Manipulating Target Program Data

Examining Variables and Expressions

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Glossary

 » Index

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:

\\module_name[\routine_name[\subroutine_name]...]\object_name

For example, the following print command output indicates that x is local to the routine sum of the module test:

print x \\test\sum\x:3

You can eliminate qualifiers by entering the command property qual_max 0.

For more information on qualifiers, see “Using Qualified Names ”.

Using Command Buttons

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:

Print()

Print the value of the contents of the ( ): input box.

You can also evaluate expressions and assign values to expressions. For example, in C syntax, if n/2 is in the input box, the result of n divided by 2 is printed. If n = 4 is in the input box, the value 4 is assigned to the variable n.

If the expression, ptr, is a pointer, printing ptr displays the address of the variable pointed to. Printing *ptr displays the value pointed to.

Print*()

Print the value pointed to by the pointer in the ( ): input box.

For example, if ptr (declared as int *ptr;) is in the input box, the integer pointed to by ptr is displayed.

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 ”.

Using the Mouse

Another method for examining variables and expressions is to use the mouse as follows:

  1. Position the cursor over an expression in the source file display area.

  2. Click the right mouse button. The Source Actions popup menu appears.

  3. Select either Print or Print*. Note that the expression under the cursor appears as an argument to these commands.

Using the Data Value Menu

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.

Figure 4-1 The Data Value Tear-Off Menu

[The Data Value Tear-Off Menu]

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.

Using Debugger Commands

If you prefer to use debugger commands, the following list shows some common usages:

print x

Displays the value of x.

print y + z

Displays the sum of y plus z.

print x = y + z

Assigns the value of y + z to x (using C syntax). Displays the result in the debugger output area.

set x = y + z

Assigns the value of y + z to x (using C syntax). Does not display the result in the debugger output area.

declare int idx

Creates the temporary variable idx of type int (using C syntax).

list declares

Show all user-defined (temporary) variables.

args

Show the values of arguments of the current routine

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.

Examining Arrays

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:

static int list[5] = {3,4,2,0,5};

The following command prints the array list:

print list
\\parray\list: (array)
\\parray\list[0]: 3
\\parray\list[1]: 4
\\parray\list[2]: 2
\\parray\list[3]: 0
\\parray\list[4]: 5

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:

print list[1..3]
\\parray\list[1]: 4
\\parray\list[2]: 2
\\parray\list[3]: 0

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.

Examining Objects Referenced by Pointers

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:

print int_ptr
\\test_program\main\int_ptr: 7B03A558
print *int_ptr
*\\test_program\main\int_ptr: 7

In languages that support special interpretation of pointers to characters:

  • Printing the value of a pointer will also print the string that is pointed to.

  • Printing the value of a dereferenced pointer will print a single character.

For example, assume that C is the current language and that char_ptr points to the first element in the string success:

print char_ptr
\\test_program\main\char_ptr: 7B03A541
*\\test_program\main\char_ptr: "success"
print *char_ptr
*\\test_program\main\char_ptr: 's'

Instead of using language-specific syntax, you can use the -indirect option to the print command as follows:

-indirect all

Follow all pointers encountered and show the value of the object pointed to.

-indirect count

Follow pointers no further than count levels.

-indirect

Follow pointers one level.

Examining Linked Lists

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:

print first_item -indirect 2
\\main\first_item: 00088000
*\\main\first_item: (record)
\\main\first_item->item_text: "Class"
\\main\first_item->font: "<F21>"
\\main\first_item->next: 00088C00
*\\main\first_item->next: (record)
\\main\first_item->next->item_text: "Type"
\\main\first_item->next->font: "<F21>"
\\main\first_item->next->next: 00089800

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:

set item = first_item; \
while item != 0 -loop [print item -indirect 1; \
set item = item->next] >tmp.out

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 ”.

Examining Buffers

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:

describe buff[60] -va
4000110C

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:

print &buff[60]
4000110C
*: "a rather serious crime\nTo marry two wives at a time."

Use print with the following syntax to display the contents of a single element in the buffer:

print buff[60]
*: 'a'

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:

describe buff[60] -va
4000110C
describe buff[92] -va
4000112A
dump -from 4000110C -to 4000112A -char -bits 256
"a rather serious crime\nTo marry "

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.