The Watch Window may be used to inspect any collected expression, including global variables, static variables, local variables, function arguments, and registers.
Watch Window topics:
To add an expression to the Watch Window from the Source Window, use the "Add to Watch" option of the Source Window Pop-up Menu.
Any legal expression may be added to the Watch Window, which will
evaluate each of its expressions everytime the program runs. Be cautious
adding expressions which cause assignments, such as "i++
".
Adding a register to the Watch Window can be advantages when debugging
via a slow serial line. In this case, keeping the entire Register Window open
may be inefficient. Consider adding the register to the Watch Window. Simply
enter the name of the register preceded with a dollar sign ($) into the
Entry. For example, to watch the PC register, enter "$pc
" into
the Watch Window Entry. The program counter is added to the Display.
To cast pointers, simply enter the cast into the
Watch Window Entry at the bottom of the window. Use the same syntax for the
cast that the source file uses. If the source file uses C, the a simple
cast of "ptr
" of type "void *
" can be cast to type
"my_struct
" by entering "(my_struct *) ptr
" into
the Entry.
Pointers, structures, and classes appear in the display with a small exapansion box before their names. To dereference pointers or view the members of classes or structures, click the closed expansion box (which appears as a small plus sign, "+") to "expand" the listing. The expansion box changes to a minus sign, "-", indicating that the display is now open. Pointers, structures and classes may be expanded recursively to allow multiple pointer dereferences and embedded structure viewing.
The Locals Display updates as the trace buffer is navigated, highlighting in blue those variables whose values have changed.
The Watch Window will, by default, display all pointers in hexadecimal and all
other variables in decimal. To change the default display of variables, use the
"set output-radix" command in the console window. (Type "help set output-radix" in the
console window for help. To make this change permanent, it must be added to the user's
init file -- .gdbinit.) To change the display
format for a variable, select the Format option from either the Variable Menu or the
Watch Pop-up Menu.