Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6ec8c597bd4d5c2b54e4ec5f4e1896d0909c2020530a924e135f1da2f152865b
Ticket: 3f90d66af9c432479bcdbae5fd57c075dd0a468e
Inconsistent behaviour of trace add execute leave on a command already on the stack
User & Date: cyan on 2023-05-04 12:29:21
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
    If a proc that is currently executing adds an execution leave trace on itself,
    the trace only fires when that call returns if the proc already had an (unrelated)
    execution trace registered for it when it started executing.  Otherwise the trace fires
    only on the next call to the command:
    
    proc _finish {target cmd code result op} {
        trace remove execution $target leave [list ::_finish $target]
        # fire finish breakpoint
        puts "would fire fini break"
    }
    
    proc foo {} {
        puts "in foo"
        set target [namespace which -command [lindex [info level 0] 0]]
        trace add execution $target leave [list ::_finish $target]
    }
    
    # Works if this line is uncommented
    #trace add execution foo enter {apply {args {}}}
    
    puts "first foo: [foo]"
    puts "second foo: [foo]"
    
    
    @aspect on the Tcl chat found this: "the block in EvalObjvCore that sets up
    TEOV_RunLeaveTraces is under an if whose condition includes (cmdPtr->flags & CMD_HAS_EXEC_TRACES)"
    I understand that the performance overhead may be prohibitive for rechecking each time a
    proc finishes, but I'm raising this ticket in case it can be made feasible, or at least
    be documented that registering a leave trace on a proc on the call stack is undefined
    (depends on other trace state)
    
  5. foundin changed to: "8.7a6"
  6. is_private changed to: "0"
  7. login: "cyan"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "54152f94cb1628c0c148b4b5708ace53216227b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "cyan"
  14. subsystem changed to: "46. Traces"
  15. title changed to:
    Inconsistent behaviour of trace add execute leave on a command already on the stack
    
  16. type changed to: "Bug"