Artifacts Associated With Ticket bc1a96407a
Ticket change [f72c917598] (rid 139722) by anonymous on 2014-09-08 15:01:55:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
This piece of code running in 64Bit ends in Segmentation fault (core dumped) in Oracle Linux 6.4. proc dispatcher {chan} { if {[eof $chan]} { } else { set line [gets $chan] array set ::guggus [list a 1 b 2] } } fileevent stdin readable [list ::dispatcher stdin] vwait ::guggus parray ::guggus exit -------------------- Tcl 8.6.2 64Bit Segmentation fault (core dumped) Tcl 8.6.2 32Bit it works - foundin initialized to: "8.6.2-64bit"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "85671f894663f9e5da5ba6dfcadd8d477fe77a60"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "04. Async Events"
- title initialized to: "segfault using filevent/vwait and array"
- type initialized to: "Bug"
Ticket change [62852abecc] (rid 139724) by msofer on 2014-09-08 15:13:05:
- icomment:
Segfault confirmed, valgrind sees the crash as ==17360== Invalid read of size 8 ==17360== at 0x56D1D8: TclObjCallVarTraces (tclTrace.c:2514) ==17360== by 0x576DB1: TclPtrSetVar (tclVar.c:1985) This is positively weird: no variables are traced in this script.
- login: "msofer"
- mimetype: "text/plain"
- priority changed to: "9 Immediate"
- icomment:
Ticket change [fce7986f5d] (rid 139725) by dgp on 2014-09-08 15:21:17:
- assignee changed to: "dgp"
- icomment:
Confirmed: Program received signal SIGSEGV, Segmentation fault. 0x000000000057a965 in TclObjCallVarTraces (iPtr=0x824648, arrayPtr=0x905d08, varPtr=0x8ffdc8, part1Ptr=0x0, part2Ptr=0x9066d8, flags=32, leaveErrMsg=512, index=2) at /home/dgp/fossil/tcl-only/generic/tclTrace.c:2514 2514 part1 = TclGetString(part1Ptr); (gdb) bt #0 0x000000000057a965 in TclObjCallVarTraces (iPtr=0x824648, arrayPtr=0x905d08, varPtr=0x8ffdc8, part1Ptr=0x0, part2Ptr=0x9066d8, flags=32, leaveErrMsg=512, index=2) at /home/dgp/fossil/tcl-only/generic/tclTrace.c:2514 #1 0x000000000058451f in TclPtrSetVar (interp=0x824648, varPtr=0x8ffdc8, arrayPtr=0x905d08, part1Ptr=0x0, part2Ptr=0x9066d8, newValuePtr=0x902588, flags=512, index=2) at /home/dgp/fossil/tcl-only/generic/tclVar.c:1985 #2 0x00000000004e8507 in TEBCresume (data=0x9067d0, interp=0x824648, result=0) at /home/dgp/fossil/tcl-only/generic/tclExecute.c:3576 #3 0x000000000041497f in TclNRRunCallbacks (interp=0x824648, result=0, rootPtr=0x907cb8) at /home/dgp/fossil/tcl-only/generic/tclBasic.c:4390 #4 0x0000000000417129 in TclEvalObjEx (interp=0x824648, objPtr=0x905d08, flags=131072, invoker=0x0, word=0) at /home/dgp/fossil/tcl-only/generic/tclBasic.c:5956 #5 0x00000000004170cd in Tcl_EvalObjEx (interp=0x824648, objPtr=0x905d08, flags=131072) at /home/dgp/fossil/tcl-only/generic/tclBasic.c:5937 #6 0x000000000052b569 in TclChannelEventScriptInvoker (clientData=0x8ef378, mask=2) at /home/dgp/fossil/tcl-only/generic/tclIO.c:8608 #7 0x000000000052ae08 in Tcl_NotifyChannel (channel=0x8f0578, mask=2) at /home/dgp/fossil/tcl-only/generic/tclIO.c:8107 #8 0x000000000059dd36 in FileHandlerEventProc (evPtr=0x902018, flags=-3) at /home/dgp/fossil/tcl-only/unix/tclUnixNotfy.c:765 #9 0x000000000054c63e in Tcl_ServiceEvent (flags=-3) at /home/dgp/fossil/tcl-only/generic/tclNotify.c:670 #10 0x000000000054ca6d in Tcl_DoOneEvent (flags=-3) at /home/dgp/fossil/tcl-only/generic/tclNotify.c:967 #11 0x00000000004de29d in Tcl_VwaitObjCmd (clientData=0x0, interp=0x824648, objc=2, objv=0x827b70) at /home/dgp/fossil/tcl-only/generic/tclEvent.c:1408 - login: "dgp"
- mimetype: "text/plain"
Ticket change [26f57d4574] (rid 139726) by dgp on 2014-09-08 15:30:10:
- icomment: "[vwait] is powered by a variable trace."
- login: "dgp"
- mimetype: "text/plain"
Ticket change [9852238d0a] (rid 139727) by dgp on 2014-09-08 15:43:31:
- assignee changed to: "msofer"
- icomment:
Broken by http://core.tcl.tk/tcl/info/93a75ad1c4
- login: "dgp"
- mimetype: "text/plain"
Ticket change [00380512bb] (rid 139728) by dgp on 2014-09-08 15:58:13:
- icomment:
Bug originates in http://core.tcl.tk/tcl/info/88629f23ac
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [c18c4eb26e] (rid 139729) by dgp on 2014-09-08 16:09:56:
- icomment:
Simpler demo: after 0 [list apply {{} {array set ::foo [list a 1 b 2]}}] vwait foo Changes to bytecode execution of [array set] have broken array traces. - login: "dgp"
- mimetype: "text/plain"
- subsystem changed to: "47. Bytecode Compiler"
- icomment:
Ticket change [6253c5ccce] (rid 139730) by dgp on 2014-09-08 16:14:22:
- icomment:
Simpler still: trace add variable foo array {#} apply {{} {array set ::foo {a 1}}} - login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [92934630e5] (rid 139731) by dgp on 2014-09-08 16:18:25:
- login: "dgp"
- mimetype: "text/plain"
- title changed to:
segfault in compiled [array set] of array-traced variable
Ticket change [7569dda356] (rid 139732) by dgp on 2014-09-08 17:17:28:
- icomment:
This looks to be hard. The revised [array set] bytecode is creating a nameless local variable that's an upvar link to a named variable in the same local frame. When traces are in place, a NULL value is passed to the tracing machinery for the name of the traced variable, and trace cannot accept that. The trace mechanism fundamentally requires that the traced variable has a name. (it's going to pass that name on to the trace handler procs). In this situation, it *might* be good enough to pass the name of the link target, since its in the same frame. I don't quickly see how to achieve that, though.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [56542a4f24] (rid 139747) by msofer on 2014-09-09 01:15:21:
- icomment:
Something is wrong: when tracing a variable that is upvared, normally it is the link TARGET that gets the trace. Witness: % proc foo {} { upvar 1 a b trace add variable b write {puts hit;#} set ::a 1 set b 1 } % foo hit hit 1 % set a 2 hit 2 So this may be a problem with the way vwait creates the trace? - login: "msofer"
- mimetype: "text/plain"
- icomment:
Ticket change [a2934d40bb] (rid 139749) by msofer on 2014-09-09 03:54:47:
- icomment:
Another hint tht the core dislikes traces on upvar SOURCEs, and that [vwait] should better respect that: % proc foo {} { trace add variable b write {puts hit;#} upvar 1 a b set b 1 } % foo variable "b" has traces: can't use for upvar - login: "msofer"
- mimetype: "text/plain"
- icomment:
Ticket change [4bf0aa4a28] (rid 139754) by dgp on 2014-09-09 10:18:02:
- icomment:
The problem is that a traced variable has no name. upvar 0 ::a <noname> Using the actual upvar command that doesn't happen and all is ok: % proc report {a e o} { set msg "$o on $a" if {$e ne {}} {append msg ($e)} puts $msg } % proc foo {} { upvar 0 ::tcl_platform x trace add variable x array report array set ::tcl_platform {mmmm donuts} array set x {where coffee} } % foo array on ::tcl_platform array on x - login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [d1612c4556] (rid 139755) by dgp on 2014-09-09 12:53:37:
- icomment:
There's partial handling of this already in place. When TclObjCallVarTraces() notices it got NULL for part1Ptr, it "calls" localName (really a macro) to pull a name out of local variable data kept by a frame (an LVT?). Trouble in this case is that also fails, since the local temp variable truly does not have a name, on purpose. Traces have never been implemented to tolerate that. Gotta have a name. That's the problem.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [dcacc92591] (rid 139797) by dkf on 2014-09-09 20:10:08:
- icomment:
The code generated in this case is (removing wholly irrelevant bits): <pre> Command 5: "array set ::guggus [list a 1 b 2]"... (30) startCommand +86 1 # next cmd at pc 116 (39) push1 3 # "::guggus" (41) push1 4 # "0" (43) reverse 2 <span style="background:#eaeaff"> (48) upvar %v2 # temp var 2</span> (53) pop Command 6: "list a 1 b 2"... (54) startCommand +14 1 # next cmd at pc 68 (63) push1 5 # "a 1 b 2" (65) dup (66) listLength (67) pop (68) dup (69) listLength (70) push1 6 # "1" (72) bitand (73) jumpFalse1 +15 # pc 88 (75) push1 7 # "list must have an even number of element"... (77) push1 8 # "-errorcode {TCL ARGUMENT FORMAT}" (79) returnImm +1 0 (88) arrayExistsImm 2 (93) jumpTrue1 +7 # pc 100 (95) arrayMakeImm 2 (100) foreach_start 0 [data=[%v1633771873], loop=%v18446744073709551609 it%v1633771873 [%v3, %v4]] (105) loadScalar1 %v3 # temp var 3 (107) loadScalar1 %v4 # temp var 4 <span style="background:#eaeaff"> (109) storeArray1 %v2 # temp var 2</span> (111) pop (112) foreach_step (113) foreach_end (114) push1 1 # "" </pre> I do not remember using <tt>upvar</tt> when writing the <tt>array set</tt> compiler. But be that as it may, <b>if</b> we fix this by generating the loop with <tt>storeArrayStk</tt>, we need to be careful when changing this (particularly the code that generates the highlighted lines) to ensure that we only run the code to generate the array name once; that'll have to be the value stored in the temporary variable. <p> Can we make the solution with nameless aliases work instead? Please? It's so much easier to code correctly. - login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [1271f5de85] (rid 140149) by dgp on 2014-10-02 17:10:41:
- icomment:
Though the details are not fully clear (really big app), Rolf Ade reports enough clues on the chat to make pretty clear he's suffering segfaults due to the same cause. If an elegant fix is not in the works, then we ought to at least do the NULL check and avoid the crash.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [bf09f2be53] (rid 140150) by dgp on 2014-10-02 17:44:20:
- icomment:
see bug-bc1a96407a branch for a partial fix for review.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [c494ade6f5] (rid 140155) by dgp on 2014-10-02 18:48:19:
- icomment:
I think this problem is related. If not, move to another ticket: % apply {{} {set name foo(bar); array set $name {baz bash}}} Segmentation fault: 11 - login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [047df43938] (rid 140156) by dgp on 2014-10-02 21:40:16:
- icomment:
New commit to that branch appears to be an effective fix. Not sure how much abuse I'm committing. msofer please review.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [3a339208ce] (rid 140161) by dgp on 2014-10-03 20:22:15:
- assignee changed to: "dgp"
- closedate changed to: "2456934.34879068"
- closer changed to: "dgp"
- icomment:
Fix merged to trunk. Only concern is whether any trouble can come from replacing an anonymous temporary variable with a temporary variable that lies about its name, claiming a namespace-qualified name instead (which I believe cannot conflict with any other local varname).
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"