From Newsgroup: comp.lang.tcl
saito <
saitology9@gmail.com> posted:
Is there any debugging tool for tcl? I am not sure what features it
would have but basic step execution or proc tracing or something similar would be sufficient for what I am looking for. It is fine if it has more features for professionals or advanced users but something basic would
go a long way.
##################################################################
# my personal dbg solution
# covers 99% of my needs.
# about the names.
# deliberately
# short
# easy to type
# non-descriptive in the consensus coding style
# low chance for collision ##################################################################
# these notions started w/ my scheme experience.
# scheme: so much flexibility and so little support.
# a scheme function like this one served all my debugging needs.
# When I moved to tcl I took the idea w/ me. ##################################################################
# out : takes a variable name
# sends a string to stdout displaying the name and its local value. ##################################################################
proc out {n} { upvar $n x ; puts "$n : $x" } ##################################################################
# taking the notion further and making use of tcls string handling convenience ##################################################################
# tap : takes a list of variable names
# sends them to stdout in a format that lines up
# "variable name(s)" : "local value(s)"
# for easy reading ##################################################################
proc tap {args} {
set ln 0
foreach n $args { set ln [expr {max($ln,[string length $n])}] }
foreach n $args { upvar $n x ; puts [format " %${ln}s : %s" $n $x] }
}
##################################################################
# Realizing, tcl actually has the introspection that
# scheme says it has and doesn't. (at the time, mb its all supported now) ##################################################################
# pips applies tap to all local variables ##################################################################
proc pips {} { uplevel { tap {*}[info locals] } } ##################################################################
# the crown jewel, tat,
# short for 'tattle' as in to inform about
# or 'tat' as in a simple quick stitch.
# slip tat in as the first line of any proc ##################################################################
# tat
# sends the name of the proc and
# all the values used to invoke
# to stdout
##################################################################
proc tat {} {
set rv [list]
set info [info frame -1]
if { [dict exists $info proc] } {
lappend rv [dict get $info proc]
} elseif { [dict exists $info method] } {
if { [dict exists $info class] } {
lappend rv [dict get $info class]
}
lappend rv [dict get $info method]
} elseif { [dict get $info type] eq "source" } {
lappend rv [file tail [dict get $info file]]
lappend rv [dict get $info line]
} else {
lappend rv [dict get $info type]
lappend rv [dict get $info line]
}
puts [join $rv ::]
uplevel 1 { pips }
}
##################################################################
# When sketching code,
# I put in tat as the body of procs that are 'yet to be'
# verify that A calls B calls C etc... then
# as I fill in the code
# tat confirms that they are called AND what they are called w/
# that's all I ever really need to get things sorted out.
#
# I have more stuff like this for larger efforts, but I don't know whether this is useful.
# I'm not a professional. ##################################################################
--- Synchronet 3.21f-Linux NewsLink 1.2