Skip to content
Tcl Source Code History Of Ticket 571385ffffffffff
Login

History Of Ticket 571385ffffffffff

Artifacts Associated With Ticket 571385ffffffffff

  1. Ticket change [a845e050a5] (rid 98954) by dgp on 2002-06-19 23:52:28:

    1. assignee initialized to: "vincentdarley"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      
      assigning to co-author of TIP 62, which introduced this
      bug.
      
      I see a segfault in line 4036 of tclCmdMZ.c, apparently due
      to an attempt to access tracePtr->nextPtr in a situation
      where tracePtr is NULL.
      
      But that's just the beginning...
      
      My code that triggers the segfault is not making use
      of execution traces, so it has no business being in
      TclCheckExecutionTraces() to begin with.
      
      It's getting there from line 3023 of tclBasic.c by mistake.
      Line 3022 checks the value of
      
          (cmdPtr->flags & CMD_HAS_EXEC_TRACES)
      
      but in my situation cmdPtr is no longer valid because
      execution of the command had caused redefinition
      of the command, something like:
      
          proc foo {} {
              proc foo {} {puts NEW}
              uplevel 1 foo
          }
      
      still looking at this to see if I can sort it out.  The
      logic of
      the trace routines is not transparent.  More comments
      would be helpful.
      
    4. foundin initialized to: "obsolete: 8.4a5"
    5. priority initialized to: "8"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "dgp"
    9. subsystem initialized to: "18. Commands M-Z"
    10. title initialized to: "segfaults in execution tracing."
    11. type initialized to: "Bug"
  2. Ticket change [4dddd855e9] (rid 127130) by vincentdarley on 2002-06-20 17:58:25:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Looks as if something like the logic which is applied 20 
      lines up needs to be applied, but we still need 
      the 'cmdPtr' to be around.  I think we need to 
      Tcl_Preserve the cmdPtr, if traces are going to be called, 
      and then Tcl_Release afterwards.
      
      Not sure if the correct afterwards test is to check 
      if 'cmdPtr->cmdEpoch' has changed or if cmdPtr has 
      been deleted.  I think the latter is the right one (cmdPtr-
      >flags & CMD_IS_DELETED).  Partly this decision 
      depends on the desired semantics of execution traces 
      when the command is modified.  According to tclInt.h, 
      cmdPtr->cmdEpoch is incremented when the command 
      is renamed, deleted, hidden, or exposed.  What do we 
      want execution traces to do in these cases?
      
      Vince.
      
      
      
      I think Hemang ought to take a look at this, since he's 
      been examining the trace code recently, while I haven't 
      looked at it in a very long time (1 year +).
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  3. Ticket change [284b0a4b95] (rid 88675) by hemanglavana on 2002-06-20 20:02:14:

    1. icomment:
      Logged In: YES 
      user_id=81875
      
      Since there are no execution traces involved, 
      
      (cmdPtr->flags & CMD_HAS_EXEC_TRACES) 
      
      should never be true unless cmdPtr is pointing
      to arbitrary memory location. cmdPtr may be
      NULL or even if cmdPtr is invalidated, the above
      condition should not be true. So, we need to
      first figure out, why this bit was set.
      
      I could not replicate this problem on solaris2.6:
      godel:76> /tmp/hlavana/tcltk/bin/tclsh8.4
      % info patch
      8.4a5
      % proc foo {} {
      proc foo {} {puts NEW}
      uplevel foo
      }
      % foo
      NEW
      % exit
      godel:77>
      
      Don, can you provide the script that gives seg. fault.
      
      Next question is: what should be its behavior
      when execution traces are set and the command
      has been modified in some way. The execution
      traces should be disabled.
      
      Although I am not very familiar with 'cmdPtr->cmdEpoch',
      a cursory look at the code tells me that it is sufficient to
      check whether 'cmdPtr->cmdEpoch' has been modified
      or not (it covers CMD_IS_DELTED case as well). I am
      providing the following patch to prevent 'leave' traces
      from being invoked when the command itself has been
      modified.
      
      godel:80> cvs diff tclBasic.c 
      Index: tclBasic.c
      ===================================================================
      RCS file: /cvsroot/tcl/tcl/generic/tclBasic.c,v
      retrieving revision 1.61
      diff -r1.61 tclBasic.c
      2927a2928
      >     int cmdEpoch;
      2974a2976,2985
      >          * According to tclInt.h, cmdPtr->cmdEpoch is incremented 
      >          * to invalidate any references that point to this command 
      >          * when the it is renamed, deleted, hidden, or exposed. 
      >          * Save the current value of cmdPtr->cmdEpoch, so that we
      >          * can use it later on to find out if the command has been
      >          * modified in any way or not.
      >          */
      >         cmdEpoch = cmdPtr->cmdEpoch;
      > 
      >         /*
      2978d2988
      <             int cmdEpoch = cmdPtr->cmdEpoch;
      3021c3031,3032
      <      * Call 'leave' command traces
      ---
      >      * If the command has been modified in any while executing the code, 
      >      * then do not call any traces.
      3023,3025c3034,3035
      <     if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) && (traceCode == TCL_OK)) {
      <       traceCode = TclCheckExecutionTraces(interp, command, length,
      <                      cmdPtr, code, TCL_TRACE_LEAVE_EXEC, objc, objv);
      ---
      >     if (cmdEpoch != cmdPtr->cmdEpoch) {
      >         checkTraces = 0;
      3027,3028c3037,3043
      <     if (iPtr->tracePtr != NULL && traceCode == TCL_OK) {
      <       traceCode = TclCheckInterpTraces(interp, command, length,
      ---
      > 
      >     /*
      >      * Call 'leave' command traces, if needed.
      >      */
      >     if ((checkTraces) && (command != NULL)) {
      >         if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) && (traceCode == TCL_OK)) {
      >           traceCode = TclCheckExecutionTraces(interp, command, length,
      3029a3045,3049
      >         }
      >         if (iPtr->tracePtr != NULL && traceCode == TCL_OK) {
      >           traceCode = TclCheckInterpTraces(interp, command, length,
      >                      cmdPtr, code, TCL_TRACE_LEAVE_EXEC, objc, objv);
      >         }
      godel:81> 
      
      
    2. login: "hemanglavana"
    3. mimetype: "text/plain"
    4. username: "hemanglavana"
  4. Ticket change [f1131517ed] (rid 109300) by dgp on 2002-06-20 21:42:31:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      several responses:
      
      1) The Command structure has its own refCount field, so
      Tcl_Preserve
          should not be used on pointers to it.
      
      2) We should put Hemang on the list of maintainers who can
      be assigned
           Tcl Bugs.
      
      3) I agree that (cmdPtr->flags & CMD_HAS_EXEC_TRACES) should
          not be true if the code was correct.  By the time that
      expression is
          computed, though, it seems that the Command structure
      pointed to
          has been freed and the memory re-allocated to another
      purpose.
          I see a (faulty) value of cmdPtr->flags == 1852793951 @
      line 3022
          of tclBasic.c just before a segfault in
      TclCheckExecutionTraces().
      
      4) if cmdPtr is NULL, I expect cmdPtr->flags access to segfault.
      
      5) Sadly I have not been able to create a short demo script,
      though
          I can reliably reproduce the problem with OOMMF.  The proc
          example was just meant to illustrate the kind of thing
      that's going
          on.  It is not a demo script.
      
      6) As far as correct behavior goes, whatever was specified
      in the TIP.
      
      7) SF won't let you attach the patch, will it? Grrrr.....
      can you mail it?
          [email protected]  I'm happy to try it, but the form
      mangled by
          comment processing is nearly unusable.
      
      8) This is a total showstopper for OOMMF.  It will be very
      bad if this
          bug gets into the Tcl 8.4b1 release.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  5. Ticket change [9823d580b5] (rid 110552) by dgp on 2002-06-20 21:53:00:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      A copy of the report came in e-mail with a usable form
      of the patch.  Trying now...
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  6. Ticket change [2345f4cf58] (rid 130896) by dgp on 2002-06-20 22:10:13:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      no joy.  we need something witht the refCount to stop
      the re-allocation I think.
      
      Perhaps we can keep around a Tcl_Obj that holds
      a reference to the Command structure?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  7. Ticket change [9ff584354c] (rid 96728) by hemanglavana on 2002-06-20 22:14:10:

    1. icomment:
      Logged In: YES 
      user_id=81875
      
      1. yes please add me to the list of maintainers
      
      2. I have sent the patch to Don (direct e-mail) to see if it resolves 
          the problem
      
      3. cmdPtr should either have NULL value or a valid value. It
          should never point to an invalid address. If the memory
          for cmdPtr has been re-allocated, then cmdPtr should be
          set to null (l will look into this).
      
      4. sf does not allow me to attach files today.
      
      
    2. login: "hemanglavana"
    3. mimetype: "text/plain"
    4. username: "hemanglavana"
  8. Ticket change [f55298d2ac] (rid 130086) by vincentdarley on 2002-06-20 22:22:37:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      I don't see from the code how 'cmdPtr' could ever be set 
      to null; it's a local variable.
      
      Replacing the main block of code around 3022 with this 
      ought to fix a segfault, but may not be an ideal solution:
      
          /*
           * Finally, invoke the command's Tcl_ObjCmdProc.
           */
          
          cmdPtr->refCount++;
          iPtr->cmdCount++;
          if ( code == TCL_OK && traceCode == TCL_OK) {
      savedVarFramePtr = iPtr->varFramePtr;
      if (flags & TCL_EVAL_GLOBAL) {
          iPtr->varFramePtr = NULL;
      }
      code = (*cmdPtr->objProc)(cmdPtr-
      >objClientData, interp, objc, objv);
      iPtr->varFramePtr = savedVarFramePtr;
          }
          if (Tcl_AsyncReady()) {
      code = Tcl_AsyncInvoke(interp, code);
          }
      
          /*
           * Call 'leave' command traces
           */
          if (!cmdPtr->flags & CMD_IS_DELETED) {
      if ((cmdPtr->flags & CMD_HAS_EXEC_TRACES) 
      && (traceCode == TCL_OK)) {
          traceCode = TclCheckExecutionTraces
      (interp, command, length,
      cmdPtr, code, 
      TCL_TRACE_LEAVE_EXEC, objc, objv);
      }
      if (iPtr->tracePtr != NULL && traceCode == 
      TCL_OK) {
          traceCode = TclCheckInterpTraces(interp, 
      command, length,
      cmdPtr, code, 
      TCL_TRACE_LEAVE_EXEC, objc, objv);
      }
          }
          TclCleanupCommand(cmdPtr);
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  9. Ticket change [51a8bd0b94] (rid 126168) by dgp on 2002-06-20 22:38:03:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      The attached patch stops the segfaulting
      that I see.  I do not know, however, if
      
      1) this depends too much on internal
          details of the tclCmdNameType
          that may change.
      
      2) the patch introduces a memory leak.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  10. Ticket change [0de7032111] (rid 114445) by dgp on 2002-06-20 22:51:31:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Oops!  Failed to attach patch.
      Trying again...
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  11. Add attachment "extr.patch" [0e07d2e32d] (rid 94538) by dgp on 2002-06-20 22:51:32.

  12. Ticket change [66ba3d9bf6] (rid 102768) by dgp on 2002-06-20 22:51:32:

    1. icomment:
      
      
      File Added - 25494: extr.patch
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  13. Ticket change [301af19ca2] (rid 93188) by dgp on 2002-06-20 22:53:57:

    1. icomment:
      
      
      File Added - 25495: darley.patch
      
      Logged In: YES 
      user_id=80530
      
      
      Here's Darley's patch as diff against HEAD.
      
      It also stops the segfaults.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  14. Ticket change [0fa44e105d] (rid 94823) by dgp on 2002-06-20 23:01:57:

    1. icomment:
      
      
      File Deleted - 25495: 
      
      
      
      File Added - 25497: darley.patch
      
      Logged In: YES 
      user_id=80530
      
      sorry, that patch got mangled.
      Here's a replacement.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  15. Ticket change [acc9a8e7e1] (rid 101354) by dgp on 2002-06-20 23:11:08:

    1. assignee changed to: "msofer"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      Hemang and I agree that darley's patch seems to
      be the best immediate fix.  Assigning to
      maintainer for evaluation and commit.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  16. Ticket change [e8a5db5925] (rid 104685) by msofer on 2002-06-20 23:23:49:

    1. assignee changed to: "vincentdarley"
    2. icomment:
      Logged In: YES 
      user_id=148712
      
      Patch looks fine to me, *but* it causes failures in
      trace.test 21.(3-8), 23.(1-3), 24.(2-5), 25.2 , 25.(5-7)
      
      
      
      
    3. login: "msofer"
    4. mimetype: "text/plain"
    5. username: "msofer"
  17. Ticket change [dcaafce653] (rid 114520) by hemanglavana on 2002-06-20 23:33:43:

    1. icomment:
      Logged In: YES 
      user_id=81875
      
      Please add paratheses around the check for CMD_IS_DELETED flag:
      
      if (!(cmdPtr->flags & CMD_IS_DELETED)) {
      
      After this change it passes all the trace tests
      
      
    2. login: "hemanglavana"
    3. mimetype: "text/plain"
    4. username: "hemanglavana"
  18. Add attachment "darley.patch" [ae577e170c] (rid 101625) by msofer on 2002-06-20 23:44:13.

  19. Ticket change [e934b997c0] (rid 104776) by msofer on 2002-06-20 23:44:13:

    1. icomment:
      
      
      File Deleted - 25497: 
      
      
      
      File Added - 25501: darley.patch
      
      Logged In: YES 
      user_id=148712
      
      Indeed; patch corrected here and committed to HEAD. I'm
      leaving this open at lowered priority: did anybody find a
      test for this bug?
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. priority changed to: "3 Low"
    5. subsystem changed to: "45. Parsing and Eval"
    6. username: "msofer"
  20. Ticket change [399771196a] (rid 112420) by dgp on 2002-06-21 01:49:19:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      I agree we should keep this open as a reminder to
      add tests for the bug.
      
      Also, note that the coding of
      TclCheckExecutionTraces() appears to allow
      for a potential segfault in line 4036, as noted
      in the original report.  Someone ought to look
      that over.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  21. Ticket change [87ba437144] (rid 131751) by vincentdarley on 2002-06-21 19:56:34:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Definitely keep this open, and I would _really_ like a 
      test which illustrates the previous bug, since, although 
      the 'darley patch' works, that 20-30 lines of code really 
      should be made clearer and more streamlined, and I'd 
      like to do that (when I have time) without a chance of re-
      introducing the bug.
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  22. Ticket change [2950db4c9a] (rid 88849) by vincentdarley on 2003-01-17 18:27:47:

    1. closedate changed to: "2003-01-17T11:27:47"
    2. closer changed to: "vincentdarley"
    3. icomment:
      Logged In: YES 
      user_id=32170
      
      Fixed and made trace routines somewhat more transparent.
      
      
      
    4. login: "vincentdarley"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "vincentdarley"