The Pstack package prints the sequence of procedure calls that lead to the execution of a user selected procedure. Argument values for all procedures are included in the printed output. To print the call stack for a particular procedure place $Pstack::print some were in the procedure. Printing of the call stack can be turned on and off from any were in your program using the Pstack::printON and Pstack::printOFF commands. ---- 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 at the beginning of the # procedure you are interested in tracing. # # Tracing printing is turned on and off with the # Pstack::printON and Pstack::printOFF commands. # -------------------------------------------------- namespace eval Pstack { variable print set print Pstack::OFF } # ------------------------------ # turn tracing 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 "--- 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 " " } } if { 0 } { ---- '''Example''' package require Pstack proc A { } { B -x } proc B { x } { C -x -y } proc C { x y {z -z} } { $Pstack::print D -x -y } proc D { x y} { E } proc E { } { } puts "#### trace calls" Pstack::printON A puts "#### don't trace calls" Pstack::printOFF A ---- '''Example Output'' #### trace calls --- pstack A {} B {-x} C {-x -y} #### don't trace calls }