Watches¶
A watch is an expression that is re-evaluated on every stop and kept on screen. Ctrl+W opens the panel.
Use watches for the thing you are actually tracking — a counter, a flag, a field buried deep in a structure — instead of re-expanding the same path in Variables after every step.
Adding and removing¶
| Key | Effect |
|---|---|
| Enter | enter the input field to type an expression |
| Esc | leave the input field |
| J / K | move between existing expressions |
| D / Del | remove the selected expression |
Expressions are written in the debuggee's language, exactly as you would write them in the code at that point.
They are evaluated in the selected frame¶
A watch is evaluated in the stack frame currently selected in the Call Stack, not always the topmost one. Selecting a different frame re-evaluates every watch against it.
That means a watch can be valid in one frame and meaningless in another, which
is expected: self exists in a method and not in main.
Results are trees too¶
A watch result is not necessarily a scalar. When the expression returns a structure or a collection, the row expands like any node in Variables — L / Right to open it — with the same lazy loading and the same pagination for large collections.
Watches and side effects¶
A watch expression runs in the debuggee. If it calls a function, that function executes — every time the program stops. An expression that mutates state, sends a request or writes a file will do so repeatedly, and will change the behaviour of the program you are debugging.
Keep watches to reads. For anything with a side effect, use Evaluate, where you control when it runs.
When a watch shows an error¶
The usual causes, in order of likelihood:
- The expression is not valid in the selected frame — the variable is out of scope there.
- The name is spelled differently than in the source, or is a macro or a compile-time construct the adapter cannot resolve.
- The frame has no debug information, so nothing can be resolved in it.
An error in one watch does not affect the others.