Example
package require Pstack proc A { } { B -x E } proc B { x } { C -x -y } proc C { x y {z -z} } { $Pstack::print D -x -y } proc D { x y} { E } proc E { } { $Pstack::print } puts "# trace calls" Pstack::printON A puts "# don't trace calls" Pstack::printOFF AExample OutputNotice that only passed arguments are printed, not arguments that are defaulted.
# trace calls --- pstack A {} B {-x} C {-x -y} --- pstack A {} B {-x} C {-x -y} D {-x -y} E {} --- pstack A {} E {} # don't trace calls
package provide Pstack 1.0 # -------------------------------------------------- # This package prints the sequence of calls that # preceeded the execution of a selected procedure. # Arguments are included in the printed output. # # Place $Pstack::print some where in the # procedure you are interested in tracing. # # Tracr printing is turned on and off with the # Pstack::printON and Pstack::printOFF commands. # -------------------------------------------------- namespace eval Pstack { variable print set print Pstack::OFF } # ------------------------------ # turn traccing on/off proc Pstack::printON { } { variable print set print Pstack::ON } proc Pstack::printOFF { } { variable print set print Pstack::OFF } # ------------------------------ # no output proc Pstack::OFF { } { } # ------------------------------ # print proc name and arguments proc Pstack::ON { } { puts stderr "--- pstack" set indent "" set up_level [expr [info level]-1] for {set i 1} {$i<=[expr [info level]-1]} {incr i} { set argList [info level ${i}] puts stderr "${indent}[lindex $argList 0] {[lrange $argList 1 end]}" append indent " " } }
escargo 29 Nov 2005 - I changed the first puts in Pstack::ON to output to stderr like to puts in the following loop does. It seems like output should be going to only one place, not a label to stdout and data to stderr.
Category Debugging | Category Example | Category Package