![]() |
![]() HP OpenVMS Systems Documentation |
![]() |
OpenVMS Debugger Manual
10.5 Examining and Manipulating VariablesThis section explains how to:
See Section 10.6, which also applies to all operations on variables.
Use the following techniques to select variable names from windows for the operations described in the sections that follow (see Section 10.5.2 for examples). When selecting names, follow the syntax of the source programming language:
Select character strings from windows as follows:
10.5.2 Displaying the Current Value of a VariableTo display the current value of a variable:
Figure 10-8, Figure 10-9, and Figure 10-10 show how to display the value of an integer variable, array aggregate, and array element, respectively. Figure 10-8 Displaying the Value of an Integer Variable ![]() Figure 10-9 Displaying the Value of an Array Aggregate ![]() Figure 10-10 Displaying the Value of an Array Element ![]() To display the current value in a different type or radix, use the following alternative method:
The value, altered to your specification, appears in the command view. Figure 10-11 shows that the variable j has been typecast as long. Figure 10-11 Typecasting the Value of a Variable ![]() 10.5.3 Changing the Current Value of a VariableTo change the current value of a variable:
The new value, altered to your specification, appears in the command view and is assigned to the variable. Figure 10-12 shows a new value for the variable safe. Figure 10-12 Changing the Value of a Variable ![]()
To monitor a variable (see Figure 10-13):
You can typecast the output value when monitoring variables by choosing the Typecast item in the Monitor menu. You can change the output radix when monitoring variables as follows:
To remove a monitored element from the monitor view, choose Remove from the Monitor menu. Figure 10-13 Monitoring a Variable ![]() 10.5.4.1 Monitoring an Aggregate (Array or Structure) VariableIf you select the name of an aggregate variable, such as an array or structure (record) and click on the MON button, the debugger displays the word Aggregate in the Value/Deposit column of the monitor view. To display the values of all elements (components) of an aggregate variable, double click on the variable name in the Monitor Expression column (or choose Expand in the Monitor menu). The displayed element names are indented relative to the parent name (see Figure 10-14). If an element is also an aggregate, you can double click on its name to display its elements, and so on. Figure 10-14 Expanded Aggregate Variable (Array) in Monitor View ![]() To collapse an expanded display so that only the aggregate parent name is shown in the monitor view, double click on the name in the Monitor Expression column (or choose Collapse from the Monitor menu).
If you have selected a component of an aggregate variable, and the
component expression is itself a variable, the debugger monitors the
component that was active when you made the selection. For example, if
you select the array component
arr[i]
and the current value of
i
is
9
, the debugger monitors
arr[9]
even if the value of
i
subsequently changes to
10
.
If you select the name of a pointer (access) variable and click on the
MON button, the debugger displays the address of the referenced object
in the
To monitor the value of the referenced object (to dereference the pointer variable), double click on the pointer name in the Monitor Expression column. This adds an entry for the referenced object in the monitor view, indented under the pointer entry (see the bottom entry in Figure 10-15). If a referenced object is an aggregate, you can double click on its name to display its elements, and so on. Figure 10-15 Pointer Variable and Referenced Object in Monitor View ![]() 10.5.5 Watching a VariableWhenever the program changes the value of a watched variable, the debugger suspends execution and displays the old and new values in the command view. To watch a variable (also known as setting a watchpoint on a variable):
Figure 10-16 Watched Variable in Monitor View ![]() To deactivate a watchpoint, clear its Watched button in the monitor view (by clicking on the button) or choose Toggle Watchpoint in the Monitor menu. To activate a watchpoint, fill in its Watched button or choose Toggle Watchpoint in the Monitor menu. Section 10.6.1 explains static and nonstatic (automatic) variables and how to access them. The debugger deactivates a nonstatic watchpoint when execution moves out of (returns from) the variable's defining routine. When a nonstatic variable is no longer active, its entry is dimmed in the monitor view and its Watched button is cleared.
The debugger does not automatically reactivate nonstatic watchpoints if
execution later returns to the variable's defining routine. You must
reactivate nonstatic watchpoints explicitly.
To change the value of a scalar (nonaggregate) variable, such as an integer or Boolean type (see Figure 10-17):
Figure 10-17 Changing the Value of a Monitored Scalar Variable ![]() To cancel a text entry and dismiss the dialog box, click on X (Cancel). You can change the value of only one component of an aggregate variable (such as an array or structure) at a time. To change the value of an aggregate-variable component (see Figure 10-18):
Figure 10-18 Changing the Value of a Component of an Aggregate Variable ![]() 10.6 Accessing Program VariablesThis section provides some general information about accessing program variables while debugging. If your program was optimized during compilation, you might not have access to certain variables while debugging. When you compile a program for debugging, it is best to disable optimization, if possible (see Section 1.2.1).
Before you check on the value of a variable, always execute the program
beyond the point where the variable is declared and initialized. The
value contained in any uninitialized variable should be considered
invalid.
A static variable is associated with the same memory address throughout execution of the program. You can always access a static variable. A nonstatic variable is allocated on the stack or in a register and has a value only when its defining routine or block is active (on the call stack). Therefore, you can access a nonstatic variable only when program execution is paused within the scope of its defining routine or block (which includes any routine called by the defining routine). A common technique for accessing a nonstatic variable is first to set a breakpoint on the defining routine and then to execute the program to the breakpoint. Whenever the execution of your program makes a nonstatic variable inaccessible, the debugger notifies you as follows:
10.6.2 Setting the Current Scope Relative to the Call StackWhile debugging a routine in your program, you can set the current scope to a calling routine (a routine down the stack from the routine in which execution is currently paused). This enables you to:
The Call Stack menu on the main window lists the names of the routines (and, under certain conditions, the images and modules) of your program that are currently active on the stack, up to the maximum number of lines that can be displayed on your screen (see Figure 10-19). The numbers on the left side of the menu indicate the level of each routine on the stack relative to level 0, which denotes the routine in which execution is paused. To set the current scope to a particular routine on the stack, choose the routine's name from the Call Stack menu (see Figure 10-19). This causes the following to occur:
Figure 10-19 Current Scope Set to a Calling Routine ![]()
When you set the scope to a calling routine, the current-location
pointer (which is cleared) marks the source line to which execution
will return in that routine. Depending on the source language and
coding style used, this might be the line that contains the call
statement or some subsequent line.
Symbol ambiguities can occur when a symbol (for example, a variable name X) is defined in more than one routine or other program unit. In most cases, the debugger automatically resolves symbol ambiguities. First, it uses the scope and visibility rules of the currently set language. In addition, because the debugger permits you to specify symbols in arbitrary modules (to set breakpoints and so on), the debugger uses the ordering of routine calls on the call stack to resolve symbol ambiguities. In some cases, however, the debugger might respond as follows when you specify a symbol that is defined multiple times:
To resolve such problems, you must specify a scope where the debugger should search for the particular declaration of the symbol:
10.7 Displaying and Modifying Values Stored in RegistersThe register view displays the current contents of all machine registers (see Figure 10-20). To display the register view, choose Views... from the Options menu on the main window or the optional views window, then click on Registers when the Views dialog box appears. By default, the register view automatically displays the register values associated with the routine in which execution is currently paused. Any values that change as your program executes are highlighted whenever the debugger regains control from your program. To display the register values associated with any routine on the call stack, choose its name from the Call Stack menu on the main window (see Section 10.6.2). To change the value stored in a register:
To change the radix used to display register values:
Figure 10-20 Register View ![]()
|