Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Run tcl script in verbose mode

2,049 views
Skip to first unread message

James

unread,
Jun 12, 2015, 7:14:06 PM6/12/15
to
How to run tcl script in verbose mode equivalent to 'bash -x' or 'perl -d'?

TIA
James

Donal K. Fellows

unread,
Jun 13, 2015, 2:50:11 AM6/13/15
to
On 13/06/2015 00:14, James wrote:
> How to run tcl script in verbose mode equivalent to 'bash -x' or 'perl -d'?
>

You've got the tools, but you have to do just a little work. You need a
driver script, like this:

# A trivial logging procedure; customise how you want
proc verboselog {command operation} {
puts >>>$command
}

# KEY TRICK: Register the logger on the [source] command
trace add execution source enterstep verboselog

# Delegate to the code you want to trace
source yourRealScript.tcl

The caveats are that this produces quite a lot of output, that it
doesn't trace anything that happens after the [source] returns (notably
events; you might need a [vwait] in your script) and that it has a *big*
impact on performance (it inhibits most compilation).

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

Alexandre Ferrieux

unread,
Jun 13, 2015, 4:34:48 AM6/13/15
to
On Saturday, June 13, 2015 at 8:50:11 AM UTC+2, Donal K. Fellows wrote:
>
> The caveats are that this produces quite a lot of output, that it
> doesn't trace anything that happens after the [source] returns (notably
> events; you might need a [vwait] in your script) and that it has a *big*
> impact on performance (it inhibits most compilation).

For all these reasons I tend to stick to a less ambitious, yet practical, use of Tcl's self-modifying abilities: prepend all proc bodies with {puts [info level 0]}.A bit of housekeeping avoids tracing predefined procs:

proc xmode_pre {} {foreach p [info proc] {set ::xmode_pre($p) 1}}
proc xmode_post {} {
foreach p [info proc] {
if {[info exists ::xmode_pre($p)]} continue
set body {puts stderr "+ [info level 0]"}
append body \n [info body $p]
proc $p [info args $p] $body
}
}

xmode_pre
proc foo ..
proc bar ..
xmode_post

-Alex

vanden...@googlemail.com

unread,
Jun 15, 2015, 2:25:40 PM6/15/15
to
> Donal Fellows -- Tcl user, Tcl maintainer, TIP editor.

fyi: out of curiosity I've tried this (copy+paste of your code into a tclsh instance followed by `source' of my script. after (indeed ....) lots of output it memory faults ....

Donal K. Fellows

unread,
Jun 15, 2015, 5:32:49 PM6/15/15
to
On 15/06/2015 19:25, vanden...@googlemail.com wrote:
> after lots of output it memory faults ...

Yuck. It's not supposed to do that. I wonder what's not releasing its
memory correctly. :-(

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

vanden...@googlemail.com

unread,
Jun 16, 2015, 8:23:23 AM6/16/15
to
On Monday, 15 June 2015 23:32:49 UTC+2, Donal K. Fellows wrote:

> > after lots of output it memory faults ...
>
> Yuck. It's not supposed to do that. I wonder what's not releasing its
> memory correctly. :-(
>
> Donal.
> --
> Donal Fellows -- Tcl user, Tcl maintainer, TIP editor.

well it happens here:

::tcl::dict::get {tzName :Tcl/Localtime century 20 yearOfCentury 15 month 1 dayOfMonth 1 era CE year 2015 julianDay 2457024 secondOfDay 0} julianDay
Memory fault


any sense in trying to run it under gdb and to generate a backtrace? or can I provide any further information which might help you?
0 new messages