Recent Changes - Search:

Mod /



Debugging Programs

In Tcl, debugging has traditionally been limited to using puts or tclLog statements in the code. Herein we discuss some other alternatives.

Validating Programs

Wize provides static code checking with:

  wize -Wall prog.tcl

This statically checks Tcl procs for validation

Even if a program passes validation, there can still be errors. Here are a few debugging utilities.


You can inspect variables within a running proc vy inserting a .Break XXX statement. When this gets executed, the TclInspect console is invoked allowing the user to view/modify variables, procs or edit the file. The XXX label is optional and is only used in locating code with multiple .Breaks.

For example:

  # File "foo.tcl"
  package require Mod

  proc Foo {n} {
     incr n
     .Break 1
     set n [expr {$n*2.3}]
     .Break 2
     return $n

  puts [Foo 1]
  exit 0

Run this with:

  wize -Wall foo.tcl

This will invoke TclInspect where you can examine and change variables.

Error Trap

Sometimes it's desirable to debug a proc that is causing a traceback. Tracebacks are useful for showing that an error occurred, but unfortunately the current state information is lost by the time the stack unwinds.

With Mod an application can trap errors using ::env(TCL_TRAP). This invokes TclInspect right at the error, much like .Break, eg.

  wize  -Wlevel=all,trap=1 bad.tcl

See Trap for more details.

Tracing Proc Calls

You can trace all commands by calling bltdebug.

Wize supports tracing of all proc calls using:

  wize -Wproccalls=3 prog.tcl

See Analysis for details.

Edit - History - Print - Recent Changes - Search
Page last modified on September 14, 2010, at 08:47 PM