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

Interesting experience with execution traces

197 views
Skip to first unread message

Helmut Giese

unread,
Nov 21, 2003, 12:54:26 PM11/21/03
to
Hello out there,
I just played around a bit with execution traces and was really
surprised about the behaviour of the enterstep / leavestep commands.
As I understood the docs

enterstep
Invoke command for every tcl command which is executed inside the
procedure name, just before the actual execution takes place ...

"inside the procedure" it says, but what it does is to _recurse_ into
any command which is not built-in.

Take this script (please correct the line breaks):
---
set lineCnt 1

# this proc will be called during the trace
proc showTrace {args} {
puts "[format %2d $::lineCnt]) showTrace: $args"
incr ::lineCnt
}

proc show {str} {
puts "$str"
}

# this proc is to be traced
proc sum {args} {
set sum [expr [join $args +]]
show "sum of $args: $sum"
}

# enable traces
trace add execution sum [list enter leave enterstep leavestep]
showTrace
sum 1 2 3
---

This is the output it produces:
1) showTrace: {sum 1 2 3} enter
2) showTrace: {join {1 2 3} +} enterstep
3) showTrace: {join {1 2 3} +} 0 1+2+3 leavestep
4) showTrace: {expr 1+2+3} enterstep
5) showTrace: {expr 1+2+3} 0 6 leavestep
6) showTrace: {set sum 6} enterstep
7) showTrace: {set sum 6} 0 6 leavestep
8) showTrace: {show {sum of 1 2 3: 6}} enterstep
9) showTrace: {puts {sum of 1 2 3: 6}} enterstep
sum of 1 2 3: 6
10) showTrace: {puts {sum of 1 2 3: 6}} 0 {} leavestep
11) showTrace: {show {sum of 1 2 3: 6}} 0 {} leavestep
12) showTrace: {sum 1 2 3} 0 {} leave

As you can see in lines 9 and 10, also the 'puts' inside 'show' gets
traced, not only the commands inside 'sum' as I expected.

IMHO, this behaviour makes this feature a lot less useful: A simple
'puts' gave me screens full of output when running in TkCon - amazing,
what TkCon has to do to write out a simple line, but not necessarily
what I was interested in seeing at this moment.

At least the docs should get updated to mention something about
recursive descent, but I wonder if a step wise trace which _does not
recurse_ would be of use. Any comments ?

On a side note: This can be a very useful feature explaining the inner
workings of Tcl to a beginner (which incidentally made me look at it):
Look at the 'leavestep' lines in the sample above to see all the
transformations which take place - just don't throw in a 'puts' when
running under TkCon :)

Best regards
Helmut Giese

Kevin Kenny

unread,
Nov 23, 2003, 2:11:07 PM11/23/03
to
Helmut Giese wrote:
> At least the docs should get updated to mention something about
> recursive descent, but I wonder if a step wise trace which _does not
> recurse_ would be of use. Any comments ?

It's easy to constrain the depth of recursion by having the trace
procedure look at [info level]. Having the full recursive tree is
useful for applications like profilers.

--
73 de ke9tv/2, Kevin

Helmut Giese

unread,
Nov 24, 2003, 8:26:08 AM11/24/03
to
On Sun, 23 Nov 2003 14:11:07 -0500, Kevin Kenny <ken...@acm.org>
wrote:

Ok, that's true.
I was thinking along the lines of having an _additional_ non-recursive
step trace for performance reasons: If the core could already decide
that 'stepping into' procs wasn't desired I suppose a lot of overhead
could be avoided.
But then, this should mostly matter for people building debuggers.
Best regards
Helmut Giese

0 new messages