I'm trying to have a detailed errorStack in Tcl. My intention is
double, on one hand I want to have more info when executing bytecoded
procs, and on the other hand I want to detect catched errors in a
legacy code.
Searching a bit I found a nice example, using traces with errorInfo,
in http://wiki.tcl.tk/2626, but I found it's crashing a lot. What am I
doing wrong? is still bug 1038021 or some bug related causing
problems?
Here is the code I'm using:
================================================
# From http://wiki.tcl.tk/2626
set ::errorLevel -1
set ::errorStack {}
trace add variable ::errorInfo write {
set __n [info level]
if {($__n > 0) && ($__n != $::errorLevel)} {
set ::errorLevel $__n
set __l [info level 0]
lappend ::errorStack $__l
} else {
puts "======================"
puts "ERROR Found: "
puts $::errorInfo
puts "----------------------"
puts [join $::errorStack \n]
puts "======================"
set ::errorLevel -1;
set ::errorStack [list];
}
}
================================================
Now if I execute the next code I get a low-level crash
set ::Total 0
proc A {a} {
if {catch {[expr {5 + [B $a]}]} err} {
puts "Something went wrong"
set ::Total $a
}
}
proc B {b} {
incr $b
return b
}
And yes, I known that should be "if {[catch {[expr {5 + [B $a]}]}
err]} {", but that's not the point here ;)
I'm running ActiveTcl 8.5.4 and executing in the wish console, so no
bytecode related. I'm looking deeply because I also found a nasty
"TclStackFree: incorrect freePtr" when running in my code, but so far
I cannot replicate it with an small example :(
Interesting !!!
Funnily,
proc A a {if {foo} {puts BAD}}
triggers the segfault, while
proc B b {expr {foo}}
doesn't.
Also,
::tcl::unsupported::disassemble proc A
triggers it too.
So it would seem there's something wrong at compile time.
In any case, this is nasty enough to deserve a bug report :-)
> I'm looking deeply because I also found a nasty
> "TclStackFree: incorrect freePtr" when running in my code, but so far
> I cannot replicate it with an small example :(
This may deserve yet another report, where you can start pouring
evidence...
-Alex
Thanks for the reports.
Just for the record: Don has just fixed it for 8.4.20 and 8.[56].
-Alex