Debugging Scripts
If a script is not behaving as you expect, you
may find it helpful to test the script using one or both of these techniques:
-
Add a :T command and a terse
true command at the beginning of the script file. :T
causes the script file commands and their responses to be displayed as
they execute, and the terse option turns off the full, formatted
command screen, resulting in a display
that is easier to follow as a script executes.
-
Use single-stepping to step through the script file commands one at a time.
This gives you time to analyze what is happening as each command executes
and allows you to add your own diagnostic commands. For example, if an
if or until command is not finding a prompt that you
expect, after the problematic command executes, you could enter the show
buffer command to see what the remote computer did send
before proceeding to the next command in the script file.
Single-Stepping through a Script
To allow single-stepping, first use the debug script command.
Before starting the script you want to test, enter the command:
debug script true
While debug script is true, single-stepping can be activated.
After turning on debug script, enter the go
command to start the script you want to test. The script will execute normally
until you press the pause key or until a haltpoint
command is encountered within the script. Single-stepping will then begin.
The debug script command
allows single-stepping, but single-stepping does not actually
begin until you press the pause key or until a haltpoint command
is encountered in a script.
When single-stepping is activated, only one command
from the script will execute, then the execution of the script will stop
until you enter the command:
sstep
or press the pause key again. Each sstep command or press of
the pause key will cause the next single command from the script to execute.
While the script is paused, you can enter your own Autolog commands. The
show and debug
commands can be useful for displaying diagnostic information to determine
why a particular command is not behaving as you expect.
Single-stepping will continue until a resume
command is encountered in a script or until you enter the command:
debug script false
The haltpoint and resume Commands
You can put haltpoint and resume commands into your scripts
for diagnostic purposes. The haltpoint command marks the place
where you want single-stepping to begin, and
the resume command marks the place where you want single-stepping
to end. Because single-stepping is not activated until you turn on debug
script, the haltpoint and resume commands will
not affect normal script execution until you also turn on debug script.
When designing complex scripts, you may find it helpful to add haltpoint
and resume commands at the beginning and end of sections of the
script that you may need to single-step through later. These commands will
not affect normal execution when debug script is turned off, but
they can make debugging easier when you turn debug script on.