
A Debugger for Tcl Applications Don Libes
4 Tcl/Tk Workshop - June 10-11, 1993 - Berkeley, CA
Expect that sequentially execute Tcl commands,
although it can also be used with any Tcl appli-
cation.
This paper has three parts. The first part de-
scribes the debugger in terms of how it is used in
a typical application. The second part of the pa-
per describes how the debugger can be
integrated into Tcl applications. The third part
describes the design and implementation of the
debugger.
View by the Application User
This section of the paper is a debugger tutorial
which shows the application user’s view of the
debugger. For the sake of concreteness, Expect
[1] will be used as the application. However,
any other application using the debugger will
work similarly.
Starting the Debugger
The debugger is initially invoked in an applica-
tion-dependent way. In Expect, the debugger is
started by using the flag “-D 1”. For example:
% expect -D 1 script
If the system supports the #! mechanism, the
script may also be started as:
% script -D 1
In either case, additional arguments may be sup-
plied as usual.
The user is prompted for a command. At this
point either Expect commands, Tcl commands,
or debugger commands may be entered. This is
true at all other times that the user is prompted as
well. The debugger is modeless.
The following Tcl commands illustrate that the
debugger evaluates Tcl commands as usual.
expect2.1> set m {a b c}
a b c
expect2.2> llength $m
3
expect2.3>
The command prompt is changeable by the ap-
plication or user. Here, the second number is the
Tcl history identifier. The first number is the
depth of the evaluation stack.
In the context of a script, the initial depth of the
evaluation stack is 1 but the debugger always in-
troduces a new level to the stack. Hence, we see
a “2” in the prompt.
Expect also allows the application to take initial
control. By using the flag “-D 0”, the applica-
tion runs until the user presses ^C at which time
the debugger begins running. The remainder of
this tutorial will assume that the debugger has
started up immediately from the flag “-D 1”.
Command Overview and Philosophy
The debugger commands are:
Name Description
s step into procedure
n step over procedure
r return from procedure
b set, clear, or show breakpoint
c continue
w show stack
u move scope up
d move scope down
h help
The debugger commands are all one letter. Short
procedure names are desirable in an interactive-
only application such as the debugger. In con-
trast, scripted applications rarely use one-letter
commands. The chances of name conflict be-
tween the debugger and scripted applications are
very low.
The command names are very similar and, in
some cases, identical to other popular debuggers
(gdb, dbx, etc.). Existing Tcl procedures are di-
rectly usable so there are no new commands, for
example, to print variables since Tcl already pro-
vides such commands (e.g., set, puts, parray).
The intent of the debugger is that it should be
easy to learn and use, and otherwise stay out of
the way.
The debugger uses the application’s top-level in-
teractor. In the case of Expect, for example, the
debugger uses Expect’s interact command which
prompts for commands and evaluates them.
For the purposes of describing the debugger
commands, the following script is assumed to be
named debug-test.exp.
1
The script doesn’t do