# The Watch Window

### Overview

The Watch Window may be used to inspect and edit any expression, including global variables, static variables, local variables, function arguments, and registers.

Watch Window topics:

- Watch Menu
  - Edit
  - Format
  - Remove
- Adding Watch Expressions
  - In the Watch Window
  - In the Source Window
  - Casting Pointers
- Watch Display
  - Dereferencing Pointers
  - Viewing a Structure or Class
  - Editing an Expression
  - Watch Pop-up Menu

### Watch Menu

The Watch Menu gives on-screen access to the funtions of the Watch Window. To use any of these functions, first use the left mouse button to select an expression from the display. Then select:

Edit
  Edit the value of the expression
Format
  Change the display format of the expression
Remove
  Remove the expression from the Watch Window

### Adding Watch Expressions

To add an expression to the Watch Window, simply enter the expression into the entry at the bottom of the window and press return or click the "Add Watch" button. The expression is validated and added to the Watch Window Display.

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.

### Watch Display

The Watch Window Display consists of a scrolled listbox which contains all watch expressions, one per line. To use any of the functions of the Watch Window, use the left mouse button to select any element from the Display.

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 derefernces and embedded structure viewing.

The Watch Display updates after every execution of the program and highlights in blue those expressions whose values have changed.

The Watch Window will, by default, display all pointers and registers in hexadecimal and all other expressions in decimal. To change the display format for an expression, select the Format option from either the Watch Menu or the Watch Pop-up Menu.

#### Editing an Expression

To edit an expression, either double-click the left mouse button on the expression in the Display or select the Edit option from either the Watch Menu or the Watch Pop-up Menu. To abort editing an expression's value, simply press the escape key on the keybaord. The expression's original value is restored.

#### Watch Pop-up Menu

The Watch Pop-up Menu provides quick access to the functions of the Watch Window. To use the Locals Pop-up Menu, first select an expression from the Display (by clicking the left mouse button on it) and click the right mouse button, choosing from the pop-up:

Edit
  Edit the expression's value. See Editing an Expression
Format
  Change the display format of the expression. The expression may be displayed as:
  Hex
    hexadecimal (base 16)
  Decimal
    decimal (base 10)
  Binary
    binary (base 2)
  Octal
    octal (base 8)