Go backward to The where Command
Go up to Debugging Facilities
Go forward to Traversing the Call Stack

Displaying Variables

printvar variable specification
globalvar [ variable specification ]
localvar [ variable specification ]
The values of variables defined in a C program run using either of the WC340x0 interpreters may be displayed using the "printvar', `globalvar" and "localvar" commands. These command takes a variable specification an as argument. The value and memory address of the variable specified are displayed. The argument may be omitted in either the "localvar" or "globalvar" commands. If this is done in a `globalvar" command, the values of all global variables are displayed. Similarly a "localvar" command with no arguments will display all variables local to the debugger's current environment. If any of the variables selected is an array or structure, all of its component values will be displayed.

The interpretation of the variable specification in a "printvar" or `localvar" command is relative to the debugger's current local environment . When the debugger first becomes active, the current local environment is the environment of the function executing when the breakpoint occurred. The user can change the current local environment using the "up" and "down" commands described below.

The "printvar" command first searches the debugger's current environment for a definition of the variable it is asked to display. If the variable cannot be found, it then searches the set of global variables. The `localvar" command only searches the current environment and the `globalvar" command only searches global variables. In practice, you will normally use "printvar'. The "localvar" command, however, provides a convenient way to display all the variables defined in a current procedure. Also, you may want to use "globalvar" to display a global variable whose name is the same as a local variable in the current environment.

These command supports the normal C syntax for variables including array subscripts, component selection and pointer dereferencing. Thus, it is possible to issue a command like

globalvar htable[4]->key

Parentheses, however, can not be used to override the standard precedence rules. The only context in which this lack of support for parentheses might be significant is if one wanted to access an element of an array using a variable declared as a pointer to an array. If the variable was named "arrayptr', the correct C syntax to reference the third component would be

(*arrayptr)[3]
rather than
*arrayptr[3]
since the second form would be interpreted as *(arrayptr[3]). To avoid this problem, the globalvar command recognizes a special subscripting operator that combines dereferencing and subscripting in the same way that the standard C "->" operator combines dereferencing and component selection. This form of subscripting is specified by using braces ( "{" and "}" ) rather than square brackets when subscripting. Thus, to display the element that would be referenced as (*arrayptr)[3] in a C program, type the command
globalvar arrayptr{3}


Prev Up Next