Execution of Script Files

Tcl usually executes a script file as one large block, returning only after execution of the entire file. For the run command, however, the command-line debugger executes script files line-by-line. If a particular line is not a complete Tcl command, the debugger appends the next line. The debugger continues appending lines until it gets a complete Tcl script block.

The listing below lists code that includes a script. For the Tclsource command, the debugger executes this script as one block. But for the run debug command, the debugger executes this script as two blocks, the set statement and the while loop.

Listing: Example Tcl Script


set x 0;

while {$x < 5}



{



puts "x is $x";



set x [expr $x + 1]



}

Note: The run debug command synchronizes debug events between blocks in a script file. For example, after a go, next, or step command, run polls the debug thread state and does not execute the next line or block until the debug thread terminates. However, the Tcl source command does not consider the debug thread state. Consequently, use the run debug command to execute script files that contain these debug commands: debug, go, next, stop, and kill.