trace
Traces variable access and command execution.
Syntax
tcl
trace subcommand ?arg ...?Subcommands
trace add
Add a trace to a variable, command, or execution.
tcl
trace add variable varName ops commandPrefix
trace add command cmdName ops commandPrefix
trace add execution cmdName ops commandPrefixVariable operations: read, write, unset
Note: The array operation is not supported in Feather (no array support).
Command operations: rename, delete
Execution operations: enter, leave, enterstep, leavestep
trace remove
Remove a previously added trace.
tcl
trace remove variable varName ops commandPrefix
trace remove command cmdName ops commandPrefix
trace remove execution cmdName ops commandPrefixtrace info
List traces on a variable, command, or execution.
tcl
trace info variable varName
trace info command cmdName
trace info execution cmdNameCallback Arguments
When a trace fires, Feather appends specific arguments to the command prefix:
Variable Traces
commandPrefix name1 name2 opname1: Variable name being accessedname2: Array index (empty string for scalars)op: Operation (read,write,unset)
Command Traces
commandPrefix oldName newName opoldName: Current command name (fully qualified)newName: New name (empty string for delete)op: Operation (rename,delete)
Execution Traces (enter/enterstep)
commandPrefix command-string opcommand-string: Complete command with expanded argumentsop: Operation (enter,enterstep)
Execution Traces (leave/leavestep)
commandPrefix command-string code result opcommand-string: Complete command with expanded argumentscode: Result coderesult: Result stringop: Operation (leave,leavestep)
Behavior Notes
- Multiple traces: Multiple traces can be registered on the same target
- Trace ordering: Variable traces fire in LIFO order (most recently added first)
- Trace disabling: Traces on a target are temporarily disabled while a callback runs
- Error propagation: Variable trace errors propagate as
can't read "varname": <error>orcan't set "varname": <error>; unset trace errors are silently ignored - Command existence:
trace add command/executionthrows an error if the command does not exist - Namespace resolution: Unqualified command/execution trace names are automatically prefixed with
:: - Trace removal on unset: When a variable is unset, all traces on it are automatically removed
- Step trace propagation:
enterstepandleavesteptraces propagate through nested procedure calls
Examples
Output
Output
Output
Output
Output
