No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] full trace support for XOTcl methods/procs
From: Eckhard Lehmann <eckhardnospam_at_gmx.de>
Date: Wed, 02 Jan 2008 22:46:26 +0100
Kristoffer Lawson schrieb:
> You could just wrap it in a package that sets a Tcl [trace] for normal
> commands combined with filters for the XOTcl stuff, just checking to
> see if the command names match, if necessary. Or maybe I've missed
> something here and I'm thinking to simple :-)
The problem is that I need something that is like enterstep/leavestep
for [trace], but for XOTcl. Filters do only intercept calls to XOTcl
objects but not to Tcl proc's.
Consider the example from Gustaf above. I have extended it a little bit:
B instproc doit {args} {
my set x 1
my foo
set l {a b c d} ;# <------
for {set i 0} {$i < 10} {incr i} { ;# <------
puts $i ;# <------
} ;# <------
next
my set y 4
}
The whole script is below, you can paste it into a file and run it. If
you do so, the output is:
-----
Call: ::b1 set x 1
Exit: ::b1 set x 1 => 1
Call: ::b1 foo
Exit: ::b1 foo => 2
0
1
2
3
4
5
6
7
8
9
Call: ::b1 set a 3
Exit: ::b1 set a 3 => 3
Call: ::b1 set y 4
Exit: ::b1 set y 4 => 4
-----
As you can see, the calls to [my set x 1] and [my foo] are intercepted
("Call"/"Exit"), but the calls to [set l {a b c d}] and to the [for]
loop are not. Therefore it is only partially useful, if yo want to
intercept *every* statement in a method (which is what I want).
Eckhard
#----------------- Script --------------
Class A
A instproc foo {} {
my set f 2
}
A instproc doit {args} {
my set a 3
}
Class B -superclass A
B instproc doit {args} {
my set x 1
my foo
set l {a b c d}
for {set i 0} {$i < 10} {incr i} {
puts $i
}
next
my set y 4
}
B b1
Class F
F instproc traceFilter args {
if {[self callingproc] eq "doit"} {
puts "Call: [self] [self calledproc] $args"
set r [next]
puts "Exit: [self] [self calledproc] $args => $r"
return $r
} else {
next
}
}
B instmixin F
B instfilter {{traceFilter}}
b1 doit
Date: Wed, 02 Jan 2008 22:46:26 +0100
Kristoffer Lawson schrieb:
> You could just wrap it in a package that sets a Tcl [trace] for normal
> commands combined with filters for the XOTcl stuff, just checking to
> see if the command names match, if necessary. Or maybe I've missed
> something here and I'm thinking to simple :-)
The problem is that I need something that is like enterstep/leavestep
for [trace], but for XOTcl. Filters do only intercept calls to XOTcl
objects but not to Tcl proc's.
Consider the example from Gustaf above. I have extended it a little bit:
B instproc doit {args} {
my set x 1
my foo
set l {a b c d} ;# <------
for {set i 0} {$i < 10} {incr i} { ;# <------
puts $i ;# <------
} ;# <------
next
my set y 4
}
The whole script is below, you can paste it into a file and run it. If
you do so, the output is:
-----
Call: ::b1 set x 1
Exit: ::b1 set x 1 => 1
Call: ::b1 foo
Exit: ::b1 foo => 2
0
1
2
3
4
5
6
7
8
9
Call: ::b1 set a 3
Exit: ::b1 set a 3 => 3
Call: ::b1 set y 4
Exit: ::b1 set y 4 => 4
-----
As you can see, the calls to [my set x 1] and [my foo] are intercepted
("Call"/"Exit"), but the calls to [set l {a b c d}] and to the [for]
loop are not. Therefore it is only partially useful, if yo want to
intercept *every* statement in a method (which is what I want).
Eckhard
#----------------- Script --------------
Class A
A instproc foo {} {
my set f 2
}
A instproc doit {args} {
my set a 3
}
Class B -superclass A
B instproc doit {args} {
my set x 1
my foo
set l {a b c d}
for {set i 0} {$i < 10} {incr i} {
puts $i
}
next
my set y 4
}
B b1
Class F
F instproc traceFilter args {
if {[self callingproc] eq "doit"} {
puts "Call: [self] [self calledproc] $args"
set r [next]
puts "Exit: [self] [self calledproc] $args => $r"
return $r
} else {
next
}
}
B instmixin F
B instfilter {{traceFilter}}
b1 doit