This command is part of the TclX package.
See also the trace command's execution traces.
Print a trace statement for all commands executed at depth of level or below (1 is the top level). If on is specified, all commands at any level are traced. The following options are available:
The most common use of this command is to enable tracing to a file during the development. If a failure occurs, a trace is then available when needed. Command tracing will slow down the execution of code, so it should be removed when code is debugged. The following command will enable tracing to a file for the remainder of the program:
cmdtrace on [open cmd.log w]
The command option causes a user specified trace command to be called for each command executed. The command will have the following arguments appended to it before evaluation:
The command should be constructed in such a manner that it will work if additional arguments are added in the future. It is suggested that the command be a proc with the final argument being args.
Tracing will be turned off while the command is being executed. The values of the errorInfo and errorCode variables will be saved and restored on return from the command. It is the command's responsibility to preserve all other state.
If an error occurs during the execution of command, an error message is dumped to stderr and the tracing is disabled. The underlying mechanism that this functionality is built on does not support returning an error to the interpreter.
Turn off all tracing.
Returns the current maximum trace level, or zero if trace is disabled.
2021-03-11 the following snippet coredumps with tclsh8.6 on Oracle Linux 7.9
package require Tclx set chan [open x.log w] cmdtrace on $chan after 1000 {close $chan; exit} #1: after 1000 {exit} #2: after 1000 {cmdtrace off; close $chan; exit} vwait forever
Closing the channel seems to cause the problem: either #1 or #2 does not coredump.