| Ticket UUID: | 2438181 | ||
| Title: | Incorrect error reporting in traces | ||
| Type: | Bug | Created on: | 2008-12-17 06:53:16 |
| Submitter: | nobody | Assigned to: | dgp |
| Subsystem: | 46. Traces | Severity: | |
| Priority: | 9 Immediate | Last modified: | 2013-03-21 20:19:34 |
| Status: | Closed | Closed by: | dgp |
| Resolution: | Fixed | Closed on: | 2013-03-21 13:19:34 |
| Version: | obsolete: 8.5.13 | ||
| Description: | ||||
This script:
#-----------
set pbody "set comms \[list [info commands]\]"
append pbody {
set pname [lindex $pstr 1]
if {[lsearch -exact $comms $pname]!=-1} {
puts "$pname already exists"
return
}
puts "Setting trace on: $pname"
trace add execution $pname enter my_report2
puts "Trace set"
}
#This is an error I made:
proc my_report {pstr op} $pbody
#This was intended, btw...:
#proc my_report {pstr args} $pbody
proc my_report2 {commstr args} {
set pname [lindex $commstr 0]
puts "<DEBUG> $pname"
}
trace add execution proc leave my_report
#Testing:
rename gets _gets
proc gets {a b} {
puts "A new gets"
}
proc exp {a b} {
puts $a
puts $b
}
exp 1 2
gets 5 6
#-----------
Correctly reports in tclkit8.4.19:
-----
wrong # args: should be "my_report pstr op"
while executing
"proc gets {a b} {
puts "A new gets"
}"
(file "bug.tcl" line 29)
-----
But both tcl 8.5.2 and 8.6a3 report:
-----
while executing
"proc gets {a b} {
puts "A new gets"
}"
(file "bug.tcl" line 29)
-----
As you see, error description is missing.
| ||||
| User Comments: | ||||
pooryorick added on 2013-02-12 12:12:57:
Here's a more concise snippet that illustrates the problem, and takes it further by illustrating that the interpreter result for the set command remains in effect and is reported as the error:
trace add execution set leave { puts one two three ;#}
puts "hmm..."
set a hello
pooryorick added on 2013-02-13 07:24:05:
Here's a proposed fix and a test:
Index: generic/tclTrace.c
==================================================================
--- generic/tclTrace.c
+++ generic/tclTrace.c
@@ -1483,11 +1483,15 @@
lastTracePtr = active.nextTracePtr->nextPtr;
}
}
iPtr->activeCmdTracePtr = active.nextPtr;
if (state) {
- Tcl_RestoreInterpState(interp, state);
+ if (traceCode) {
+ Tcl_DiscardInterpState(state);
+ } else {
+ Tcl_RestoreInterpState(interp, state);
+ }
}
return traceCode;
}
@@ -2671,11 +2679,13 @@
if (code == TCL_ERROR) {
goto done;
}
}
/*
- * an array trace may have caused the variable to exist
+ * an array trace may have caused the variable to exist. This section
+ * and the one similar to it after the variable traces below are
+ * executed addresses bugs like #3603163 and #3599017
*/
varPtr2 = TclObjLookupVarEx((Tcl_Interp *) iPtr
, Tcl_NewStringObj(part1 ,-1)
, Tcl_NewStringObj(part2 ,-1)
, flags ,"read" ,/*createPart1*/ 0 ,/*createPart2*/ 0 ,&newArrayPtr
Index: tests/trace.test
==================================================================
--- tests/trace.test
+++ tests/trace.test
@@ -2328,10 +2328,22 @@
} -cleanup {
namespace delete a
rename ::x {}
} -result {:: ::}
+proc set2 args {
+ set {*}$args
+}
+
+test trace-22.11.$mode {} {
+ body {} {
+ trace add execution set2 leave {puts one two three #;}
+ } {
+ set2 a hello
+ }
+} {1 {wrong # args: should be "puts ?-nonewline? ?channelId? string"} {}}
+
proc factorial {n} {
if {$n != 1} { return [expr {$n * [factorial [expr {$n -1 }]]}] }
return 1
}
pooryorick added on 2013-02-13 07:28:40:
oops, the following code chunk isn't part of the fix: @@ -2671,11 +2679,13 @@ pooryorick added on 2013-02-14 13:05:22:
the fix below is also at: https://ynform.org/fossil/tcl/info/45968549a8 nijtmans added on 2013-02-19 17:59:36:
Proposed fix committed to all branches. Given that the functions TclCheckExecutionTraces and TclCheckInterpTraces and were different in the saving/restoring of the interpreter state, there is little doubt to me that this is the right approach. Don, feel free to evaluate. dgp added on 2013-03-21 20:19:34:
allow_comments - 1 | ||||
