Watch Expressions debut in TPF/GI
The new Watch Expressions window allows C/C++ programmers using TPF/GI to monitor and edit expressions containing absolutely any variable. Expressions can include literals and operators and can be quite complex.
TPF/GI has broken a new barrier in its quest to deliver greater power into the hands of TPF programmers.
The Watch Expressions window, new in TPF/GI 2.6.1, allows C and C++ programmers to view and edit the values of ALL variables while they debug their TPF programs.
That's right: we said all variables.
Previous versions of TPF/GI allowed programmers to view and edit the values of local variables only (local variables are variables that are declared inside of functions).
Now, however, the new Watch Expressions window allows the viewing and editing of any variable that can be manipulated by the current statement. This includes extern and static variables.
Any type of variable can be viewed and edited, including classes, structs, arrays, pointers, and null-terminated strings as well as ints, chars, doubles, and other basic C/C++ types.
The values for these variables are displayed by the Watch Expressions window in human-friendly formats: numbers can be viewed in decimal as well as hex, char can be viewed as characters, and enum values can be viewed by their symbolic names rather than their ordinal values only.
Expressions, Not Just Variables
But the description so far just scratches the surface of the Watch Expressions window's power. The window actually allows you to look at expressions, not just variables. Expressions can be made up of more than one variable as well as literals and operators.
Among other things, the power to use expressions rather than simple variable names means that you can view and edit individual elements in an array and individual member variables of a struct or class without viewing the entire array, struct, or class.
For example, if a is an array of int, you can enter the epxression a into the Watch Expresisions window to view and edit only the first integer in the array.
Even more advanced, if i is an int variable that your code is using to loop through the values in a, you can enter the expression a[i] into the Watch Expressions window. Each time i changes value, a different int from a will be displayed.
Other expression examples:
- Structs and Classes. If s is a struct and m is a member variable of s, s.m monitors the value of one member variable.
- Pointers. If pn is a pointer to an int, then the expression *pn will dereference that pointer and display the value of the int. If pc is a pointer to a class instance and m is a member variable of that class, pc–>m monitors the value of one member variable.
- Logical Operators. n == i returns 1 if the values of n and i are equal, 0 if they are not. <, >, >=, <=, !=, &&, ||, and ! behave as expected.
- Mathematical and Bitwise Operators. Operators such as +, -, *, /, %, &, |, <<, >>, and ! work as you would expect. Parentheses group subexpressions, or the normal rules of C/C++ precedence apply. For example, (x + n) * a[i % 3] / j * i is handled easily by the Watch Expressions window.
Using Watch Expressions
The Watch Expressions window (see figure) is made up of four pages — Watch1, Watch2, Watch3, and Watch4. Each page contains a table with expressions in the left-hand column and the values for those expressions in the right-hand column.
As you step through your program, values that change are highlighted in the Watch Expression window, and values known to be invalid take on a grayed appearance.
Expressions can be added to the window in several ways. To place the name of one variable in the window, you can right click on that variable in your code and choose Add to Watch from the local menu that pops up.
To place an entire expression in the window (not just a single variable name), you can select the entire expression in your source code before right clicking. You can also drag and drop a selected expression into the window.
At any time, you can type a new value into the right-hand column or a new expression into the left-hand column. Typing a new value into the right-hand column will actually change the value of that variable on the host, allowing you to interactively test how your program behaves under different conditions. Typing a new expression into the left-hand column will change which expression is being watched.
Expressions can be removed from the window by hitting the Delete key or by right clicking and selecting Delete.