Tcl Source Code

View Ticket
Login
Ticket UUID: 3059758
Title: tclTraceExec==3 : wrong pc+INST on uncaught error return
Type: Bug Version: None
Submitter: ferrieux Created on: 2010-09-05 10:14:14
Subsystem: 47. Bytecode Compiler Assigned To: ferrieux
Priority: 5 Medium Severity:
Status: Open Last Modified: 2011-04-12 09:39:24
Resolution: None Closed By:
    Closed on:
Description:
When tracing instructions (tclTraceExec==3), returns from procedure calls typically look like:

       ... no enclosing catch, returning TCL_OK
    LEVEL:  DEPTH (PC) INST args => ... after "PROCNAME": TCL_OK, result="1"

where PC and INST/args are the position and instruction to be executed just after the return.
However, when the return code is not TCL_OK, the PC is off by one, and is the last byte of the previous instruction (typically invokeXXX), and consequently the INST is random (possibly an immediate operand interpreted as an opcode):

   ... no enclosing catch, returning TCL_ERROR
 LEVEL:  DEPTH (WRONG PC) WRONG INST => TCL_ERROR, result= "..."

Of course this is a very tiny issue, but tracing instructions accurately is key to understanding the delicate operation of TEBC, and this microbug has been annoying in the course of the investigation of Patch 2995655. The fix/insight could help both.
User Comments: ferrieux added on 2010-09-20 04:03:25:

File Added - 387183: traceinst.patch

ferrieux added on 2010-09-20 04:02:28:
Attaching a patch that at least brings back a valid pc and inst, though it is the instruction _following_ the one which is erroring. Though it is not entirely acceptable for the current purpose, this patch uses a new local in TEBC, pcBeg, that is also needed for 2995655.

Miguel, please review :}

ferrieux added on 2010-09-20 03:55:15:

File Added - 387182: out.txt

ferrieux added on 2010-09-20 03:54:39:

File Added - 387181: traceexec.tcl

ferrieux added on 2010-09-20 03:53:55:
Attaching example: traccexec.tcl, and generated output, out.txt.
The following line from the output has an invalid pc and instruction:

      1:  3 (7) pop => TCL_ERROR, result= "Yo"

since offset 7 is not the beginning of an instruction:

  Command 1: "B x x"
    (0) push1 0 # "B"
    (2) push1 1 # "x"
    (4) push1 1 # "x"
    (6) invokeStk1 3 
    (8) done

ferrieux added on 2010-09-06 06:10:48:
The 'pc--' after the nonRecursiveCallReturn: label is the reason. I know it is necessary, so that the pc goes back into the range of the offending instruction, so that TIP 280 info can be recomputed from it, but subsequently a stronger contract is expected: namely that *pc be the inst itself:

    processExceptionReturn:
#if TCL_COMPILE_DEBUG
switch (*pc) {
            ...

So, the conflict must be resolved, either by giving up the pretty printing of the offending inst, or by using the pc-indexing data in TIP 280 to crawl back to the beginning of the inst (conditionally on TCL_COMPILE_DEBUG).

Attachments: