Command Tracing

The strace command is yet another command that is useful only for debugging. The command enables the printing of commands before they are executed. Here is what it looks like when commands are traced.

expect1.2> set foo [split "a b [expr 10+5]"]
 3      expr 10+5
 2    split "a b [expr 10+5]"
 1  set foo [split "a b [expr 10+5]"]
a b 15

Each command is prefixed by an integer describing the depth of the evaluation stack. Each bracketed command increases the evaluation stack. In this example, you can see the expr command being evaluated at the third stack level, the split command being evaluated at the second stack level, and the set command being evaluated at the first level.

Each command is indented by two spaces for each additional level in the stack. The precise level numbers are not that important except as a guide to bounding the amount of information that is produced.

The strace command takes an integer argument that bounds the depth to which commands are traced. For example, the following command traces only commands executed at the first three levels.

strace 3

This could be useful when there are a lot of subroutines being executed and you want to ignore, for example, many iterations of a loop at some deep level. Unfortunately, this control is not very fine. In practice, I often just use a very high value no matter what kind of script I am using. It is simply not worth the effort of figuring out a precise cut-off. This command is likely to be revised in the future.[60]

Given ...

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.