/ Check-in [66396d2f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Registerify binary operators. Add register tracing to debugging output. (CVS 4686)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:66396d2f0289e36b5fc0af5078c08d1b17f342ae
User & Date: drh 2008-01-05 16:29:28
Context
2008-01-05
17:39
First pass at optimizing max()/min() as described in #2853. Some refinements to come. (CVS 4687) check-in: c449e04f user: danielk1977 tags: trunk
16:29
Registerify binary operators. Add register tracing to debugging output. (CVS 4686) check-in: 66396d2f user: drh tags: trunk
06:51
Expression code generator takes advantage of recent opcode changes. (CVS 4685) check-in: 6c78d2a4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to mkopcodeh.awk.

   126    126     #  bit 1:     pushes a result onto stack
   127    127     #  bit 2:     output to p1.  release p1 before opcode runs
   128    128     #
   129    129     for(i=0; i<=max; i++) bv[i] = 0;
   130    130     for(name in op){
   131    131       x = op[name]
   132    132       a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = 0
          133  +    a8 = a9 = a10 = a11 = a12 = a13 = a14 = a15 = 0
   133    134       if( jump[name] ) a0 = 1;
   134    135       if( nopush[name]==0 ) a1 = 2;
   135    136       if( out2_prerelease[name] ) a2 = 4;
   136    137       if( in1[name] ) a3 = 8;
   137    138       if( in2[name] ) a4 = 16;
   138    139       if( in3[name] ) a5 = 32;
   139    140       if( out2[name] ) a6 = 64;
   140    141       if( out3[name] ) a7 = 128;
   141         -    bv[x] = a0+a1+a2+a3+a4+a5+a6+a7;
          142  +    bv[x] = a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15;
   142    143     }
   143    144     print "\n"
   144    145     print "/* Properties such as \"out2\" or \"jump\" that are specified in"
   145    146     print "** comments following the "case" for each opcode in the vdbe.c"
   146    147     print "** are encoded into bitvectors as follows:"
   147    148     print "*/"
   148         -  print "#define OPFLG_JUMP            0x01    /* jump:  P2 holds jmp target */"
   149         -  print "#define OPFLG_PUSH            0x02    /* ~no-push:  Does not push */"
   150         -  print "#define OPFLG_OUT2_PRERELEASE 0x04    /* out2-prerelease: */"
   151         -  print "#define OPFLG_IN1             0x08    /* in1:   P1 is an input */"
   152         -  print "#define OPFLG_IN2             0x10    /* in2:   P2 is an input */"
   153         -  print "#define OPFLG_IN3             0x20    /* in3:   P3 is an input */"
   154         -  print "#define OPFLG_OUT2            0x40    /* out2:  P2 is an output */"
   155         -  print "#define OPFLG_OUT3            0x80    /* out3:  P3 is an output */"
          149  +  print "#define OPFLG_JUMP            0x0001  /* jump:  P2 holds jmp target */"
          150  +  print "#define OPFLG_PUSH            0x0002  /* ~no-push:  Does not push */"
          151  +  print "#define OPFLG_OUT2_PRERELEASE 0x0004  /* out2-prerelease: */"
          152  +  print "#define OPFLG_IN1             0x0008  /* in1:   P1 is an input */"
          153  +  print "#define OPFLG_IN2             0x0010  /* in2:   P2 is an input */"
          154  +  print "#define OPFLG_IN3             0x0020  /* in3:   P3 is an input */"
          155  +  print "#define OPFLG_OUT2            0x0040  /* out2:  P2 is an output */"
          156  +  print "#define OPFLG_OUT3            0x0080  /* out3:  P3 is an output */"
   156    157     print "#define OPFLG_INITIALIZER {\\"
   157    158     for(i=0; i<=max; i++){
   158         -    printf " 0x%02x,", bv[i]
          159  +    if( i%8==0 ) printf("/* %3d */",i)
          160  +    printf " 0x%04x,", bv[i]
   159    161       if( i%8==7 ) printf("\\\n");
   160    162     }
   161    163     print "}"
   162    164   }

Changes to src/analyze.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code associated with the ANALYZE command.
    13     13   **
    14         -** @(#) $Id: analyze.c,v 1.33 2008/01/05 05:20:10 drh Exp $
           14  +** @(#) $Id: analyze.c,v 1.34 2008/01/05 16:29:28 drh Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_ANALYZE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine generates code that opens the sqlite_stat1 table on cursor
    21     21   ** iStatCur.
................................................................................
   155    155       endOfLoop = sqlite3VdbeMakeLabel(v);
   156    156       sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
   157    157       topOfLoop = sqlite3VdbeCurrentAddr(v);
   158    158       sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
   159    159       for(i=0; i<nCol; i++){
   160    160         sqlite3VdbeAddOp2(v, OP_Column, iIdxCur, i);
   161    161         sqlite3VdbeAddOp1(v, OP_SCopy, iMem+nCol+i+1);
   162         -      sqlite3VdbeAddOp1(v, OP_Ne, 0x100);
          162  +      sqlite3VdbeAddOp1(v, OP_Ne, 0x100);  /* FIX ME: use collating sequence */
   163    163       }
   164    164       sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
   165    165       for(i=0; i<nCol; i++){
   166    166         addr = sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
   167    167         sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
   168    168         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
   169    169       }
................................................................................
   191    191       */
   192    192       sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
   193    193       addr = sqlite3VdbeAddOp0(v, OP_IfNot);
   194    194       sqlite3VdbeAddOp1(v, OP_NewRowid, iStatCur);
   195    195       sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pTab->zName, 0);
   196    196       sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pIdx->zName, 0);
   197    197       sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
   198         -    sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, " ", 0);
   199    198       for(i=0; i<nCol; i++){
   200         -      sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
   201         -      sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
   202         -      sqlite3VdbeAddOp0(v, OP_Add);
          199  +      sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, " ", 0);
          200  +      sqlite3VdbeAddOp0(v, OP_Concat);
          201  +      sqlite3VdbeAddOp2(v, OP_Add, iMem, iMem+i+1);
   203    202         sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);
   204         -      sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
   205         -      sqlite3VdbeAddOp0(v, OP_Divide);
          203  +      sqlite3VdbeAddOp2(v, OP_Divide, iMem+i+1, 0);
   206    204         sqlite3VdbeAddOp0(v, OP_ToInt);
   207         -      if( i==nCol-1 ){
   208         -        sqlite3VdbeAddOp1(v, OP_Concat, nCol*2-1);
   209         -      }else{
   210         -        sqlite3VdbeAddOp1(v, OP_Copy, -1);
   211         -      }
          205  +      sqlite3VdbeAddOp0(v, OP_Concat);
   212    206       }
   213    207       sqlite3VdbeAddOp4(v, OP_MakeRecord, 3, 0, 0, "aaa", 0);
   214    208       sqlite3CodeInsert(pParse, iStatCur, OPFLAG_APPEND);
   215    209       sqlite3VdbeJumpHere(v, addr);
   216    210     }
   217    211   }
   218    212   

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.333 2008/01/05 06:51:30 drh Exp $
           15  +** $Id: expr.c,v 1.334 2008/01/05 16:29:28 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
  2082   2082       case TK_REM:
  2083   2083       case TK_BITAND:
  2084   2084       case TK_BITOR:
  2085   2085       case TK_SLASH:
  2086   2086       case TK_LSHIFT:
  2087   2087       case TK_RSHIFT: 
  2088   2088       case TK_CONCAT: {
         2089  +      int r1, r2;
  2089   2090         assert( TK_AND==OP_And );
  2090   2091         assert( TK_OR==OP_Or );
  2091   2092         assert( TK_PLUS==OP_Add );
  2092   2093         assert( TK_MINUS==OP_Subtract );
  2093   2094         assert( TK_REM==OP_Remainder );
  2094   2095         assert( TK_BITAND==OP_BitAnd );
  2095   2096         assert( TK_BITOR==OP_BitOr );
  2096   2097         assert( TK_SLASH==OP_Divide );
  2097   2098         assert( TK_LSHIFT==OP_ShiftLeft );
  2098   2099         assert( TK_RSHIFT==OP_ShiftRight );
  2099   2100         assert( TK_CONCAT==OP_Concat );
  2100         -      sqlite3ExprCode(pParse, pExpr->pLeft, 0);
  2101         -      sqlite3ExprCode(pParse, pExpr->pRight, 0);
  2102         -      sqlite3VdbeAddOp0(v, op);
  2103         -      stackChng = -1;
         2101  +      r1 = sqlite3ExprCode(pParse, pExpr->pLeft, 0);
         2102  +      r2 = sqlite3ExprCode(pParse, pExpr->pRight, 0);
         2103  +      sqlite3VdbeAddOp3(v, op, r2, r1, target);
         2104  +      if( r1==0 ) stackChng--;
         2105  +      if( r2==0 ) stackChng--;
         2106  +      if( target==0 ) stackChng++;
         2107  +      inReg = target;
  2104   2108         break;
  2105   2109       }
  2106   2110       case TK_UMINUS: {
  2107   2111         Expr *pLeft = pExpr->pLeft;
  2108   2112         assert( pLeft );
  2109   2113         if( pLeft->op==TK_FLOAT || pLeft->op==TK_INTEGER ){
  2110   2114           Token *p = &pLeft->token;
................................................................................
  2345   2349            VdbeComment((v, "raise(IGNORE)"));
  2346   2350         }
  2347   2351         stackChng = 0;
  2348   2352         break;
  2349   2353       }
  2350   2354   #endif
  2351   2355     }
  2352         -  if( inReg!=target && origTarget!=-1 ){
  2353         -    sqlite3VdbeAddOp2(v, (inReg>0 ? OP_SCopy : OP_Move), inReg, target);
         2356  +  if( inReg!=target ){
         2357  +    if( origTarget!=-1 ){
         2358  +      sqlite3VdbeAddOp2(v, (inReg>0 ? OP_SCopy : OP_Move), inReg, target);
         2359  +    }else{
         2360  +      target = inReg;
         2361  +    }
  2354   2362       stackChng = 0;
  2355   2363     }
  2356   2364     if( pParse->ckOffset ){
  2357   2365       pParse->ckOffset += stackChng;
  2358   2366       assert( pParse->ckOffset );
  2359   2367     }
  2360   2368     return target;

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.160 2008/01/05 05:20:10 drh Exp $
           14  +** $Id: pragma.c,v 1.161 2008/01/05 16:29:28 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <ctype.h>
    18     18   
    19     19   /* Ignore this whole file if pragmas are disabled
    20     20   */
    21     21   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
................................................................................
   883    883         if( cnt==0 ) continue;
   884    884         sqlite3VdbeAddOp2(v, OP_IntegrityCk, 1, i);
   885    885         addr = sqlite3VdbeAddOp2(v, OP_IsNull, -1, 0);
   886    886         sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0,
   887    887            sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
   888    888            P4_DYNAMIC);
   889    889         sqlite3VdbeAddOp2(v, OP_Pull, 1, 0);
   890         -      sqlite3VdbeAddOp2(v, OP_Concat, 0, 0);
          890  +      sqlite3VdbeAddOp0(v, OP_Concat);
   891    891         sqlite3VdbeAddOp2(v, OP_Callback, 1, 0);
   892    892         sqlite3VdbeJumpHere(v, addr);
   893    893   
   894    894         /* Make sure all the indices are constructed correctly.
   895    895         */
   896    896         for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
   897    897           Table *pTab = sqliteHashData(x);
................................................................................
   910    910             int jmp2;
   911    911             static const VdbeOpList idxErr[] = {
   912    912               { OP_AddImm,      1, -1,  0},
   913    913               { OP_String8,     0,  0,  0},    /* 1 */
   914    914               { OP_Rowid,       1,  0,  0},
   915    915               { OP_String8,     0,  0,  0},    /* 3 */
   916    916               { OP_String8,     0,  0,  0},    /* 4 */
   917         -            { OP_Concat,      2,  0,  0},
          917  +            { OP_Concat,      0,  0,  0},
          918  +            { OP_Concat,      0,  0,  0},
          919  +            { OP_Concat,      0,  0,  0},
   918    920               { OP_Callback,    1,  0,  0},
   919    921             };
   920    922             sqlite3GenerateIndexKey(v, pIdx, 1);
   921    923             jmp2 = sqlite3VdbeAddOp2(v, OP_Found, j+2, 0);
   922    924             addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
   923    925             sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
   924    926             sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.683 2008/01/05 06:51:32 drh Exp $
           46  +** $Id: vdbe.c,v 1.684 2008/01/05 16:29:28 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
   174    174   
   175    175   /*
   176    176   ** Properties of opcodes.  The OPFLG_INITIALIZER macro is
   177    177   ** created by mkopcodeh.awk during compilation.  Data is obtained
   178    178   ** from the comments following the "case OP_xxxx:" statements in
   179    179   ** this file.  
   180    180   */
   181         -static unsigned char opcodeProperty[] = OPFLG_INITIALIZER;
          181  +static unsigned short opcodeProperty[] = OPFLG_INITIALIZER;
   182    182   
   183    183   /*
   184    184   ** Return true if an opcode has any of the OPFLG_xxx properties
   185    185   ** specified by mask.
   186    186   */
   187    187   int sqlite3VdbeOpcodeHasProperty(int opcode, int mask){
   188    188     assert( opcode>0 && opcode<sizeof(opcodeProperty) );
................................................................................
   392    392       sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]);
   393    393       k += strlen(&zBuf[k]);
   394    394       zBuf[k++] = 0;
   395    395     }
   396    396   }
   397    397   #endif
   398    398   
          399  +#ifdef SQLITE_DEBUG
          400  +/*
          401  +** Print the value of a register for tracing purposes:
          402  +*/
          403  +static void memTracePrint(FILE *out, Mem *p){
          404  +  if( p->flags & MEM_Null ){
          405  +    fprintf(out, " NULL");
          406  +  }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
          407  +    fprintf(out, " si:%lld", p->u.i);
          408  +  }else if( p->flags & MEM_Int ){
          409  +    fprintf(out, " i:%lld", p->u.i);
          410  +  }else if( p->flags & MEM_Real ){
          411  +    fprintf(out, " r:%g", p->r);
          412  +  }else{
          413  +    char zBuf[200];
          414  +    sqlite3VdbeMemPrettyPrint(p, zBuf);
          415  +    fprintf(out, " ");
          416  +    fprintf(out, "%s", zBuf);
          417  +  }
          418  +}
          419  +static void registerTrace(FILE *out, int iReg, Mem *p){
          420  +  fprintf(out, "REG[%d] = ", iReg);
          421  +  memTracePrint(out, p);
          422  +  fprintf(out, "\n");
          423  +}
          424  +#endif
          425  +
          426  +#ifdef SQLITE_DEBUG
          427  +#  define REGISTER_TRACE(R,M) if(p->trace&&R>0)registerTrace(p->trace,R,M)
          428  +#else
          429  +#  define REGISTER_TRACE(R,M)
          430  +#endif
          431  +
   399    432   
   400    433   #ifdef VDBE_PROFILE
   401    434   /*
   402    435   ** The following routine only works on pentium-class processors.
   403    436   ** It uses the RDTSC opcode to read the cycle count value out of the
   404    437   ** processor and returns that value.  This can be used for high-res
   405    438   ** profiling.
................................................................................
   463    496   ){
   464    497     int pc;                    /* The program counter */
   465    498     Op *pOp;                   /* Current operation */
   466    499     int rc = SQLITE_OK;        /* Value to return */
   467    500     sqlite3 *db = p->db;       /* The database */
   468    501     u8 encoding = ENC(db);     /* The database encoding */
   469    502     Mem *pTos;                 /* Top entry in the operand stack */
   470         -  Mem *pIn1, *pIn2;          /* Input operands */
          503  +  Mem *pIn1, *pIn2, *pIn3;   /* Input operands */
   471    504     Mem *pOut;                 /* Output operand */
   472    505     int nPop = 0;              /* Number of times to pop the stack */
   473    506     u8 opProperty;
   474    507   #ifdef VDBE_PROFILE
   475    508     unsigned long long start;  /* CPU clock count at start of opcode */
   476    509     int origPc;                /* Program counter at start of opcode */
   477    510   #endif
................................................................................
   628    661         assert( pOp->p1>=0 );
   629    662         if( pOp->p1==0 ){
   630    663           pIn1 = pTos;
   631    664           nPop = 1;
   632    665         }else{
   633    666           assert( pOp->p1<=p->nMem );
   634    667           pIn1 = &p->aMem[pOp->p1];
          668  +        REGISTER_TRACE(pOp->p1, pIn1);
   635    669         }
   636    670         if( (opProperty & OPFLG_IN2)!=0 ){
   637    671           assert( pOp->p2>=0 );
   638    672           if( pOp->p2==0 ){
   639    673             pIn2 = &pTos[-nPop];
   640    674             nPop++;
   641    675           }else{
   642    676             assert( pOp->p2<=p->nMem );
   643    677             pIn2 = &p->aMem[pOp->p2];
          678  +          REGISTER_TRACE(pOp->p2, pIn2);
   644    679           }
   645    680           if( (opProperty & OPFLG_OUT3)!=0 ){
   646    681             assert( pOp->p3>=0 );
   647    682             if( pOp->p3==0 ){
   648         -            pTos++;
          683  +            nPop--;
          684  +            if( nPop<0 ){
          685  +              assert( nPop==(-1) );
          686  +              pTos++;
          687  +              nPop = 0;
          688  +            }
   649    689               pOut = &pTos[-nPop];
   650         -            pOut->flags = MEM_Null;
   651    690             }else{
   652    691               assert( pOp->p3<=p->nMem );
   653    692               pOut = &p->aMem[pOp->p3];
   654    693             }
   655    694           }
   656    695         }else if( (opProperty & OPFLG_IN3)!=0 ){
   657    696           assert( pOp->p3>=0 );
   658    697           if( pOp->p3==0 ){
   659         -          pIn2 = &pTos[-nPop];
          698  +          pIn3 = &pTos[-nPop];
   660    699             nPop++;
   661    700           }else{
   662    701             assert( pOp->p3<=p->nMem );
   663         -          pIn2 = &p->aMem[pOp->p3];
          702  +          pIn3 = &p->aMem[pOp->p3];
          703  +          REGISTER_TRACE(pOp->p3, pIn3);
   664    704           }
   665    705         }else if( (opProperty & OPFLG_OUT2)!=0 ){
   666    706           assert( pOp->p2>=0 );
   667    707           if( pOp->p2==0 ){
   668         -          pTos++;
          708  +          nPop--;
          709  +          if( nPop<0 ){
          710  +            assert( nPop==(-1) );
          711  +            pTos++;
          712  +            nPop = 0;
          713  +          }
   669    714             pOut = &pTos[-nPop];
   670         -          pOut->flags = MEM_Null;
   671    715           }else{
   672    716             assert( pOp->p2<=p->nMem );
   673    717             pOut = &p->aMem[pOp->p2];
   674    718           }
   675    719         }
   676    720       }
   677    721   
................................................................................
  1043   1087   case OP_SCopy: {
  1044   1088     if( pOp->p1<=0 ){
  1045   1089       pIn1 = &pTos[pOp->p1];
  1046   1090       assert( pIn1>=p->aStack );
  1047   1091     }else{
  1048   1092       assert( pOp->p1<=p->nMem );
  1049   1093       pIn1 = &p->aMem[pOp->p1];
         1094  +    REGISTER_TRACE(pOp->p1, pIn1);
  1050   1095     }
  1051   1096     assert( pOp->p2>=0 );
  1052   1097     if( pOp->p2==0 ){
  1053   1098       pOut = ++pTos;
  1054   1099       pOut->flags = MEM_Null;
  1055   1100     }else{
  1056   1101       assert( pOp->p2<=p->nMem );
................................................................................
  1061   1106       if( pOp->p1==0 ) pTos--;
  1062   1107     }else{
  1063   1108       sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
  1064   1109       if( pOp->opcode==OP_Copy ){
  1065   1110         Deephemeralize(pOut);
  1066   1111       }
  1067   1112     }
         1113  +  REGISTER_TRACE(pOp->p2, pOut);
  1068   1114     break;
  1069   1115   }
  1070   1116   
  1071   1117   /* Opcode: Pull P1 * *
  1072   1118   **
  1073   1119   ** The P1-th element is removed from its current location on 
  1074   1120   ** the stack and pushed back on top of the stack.  The
................................................................................
  1213   1259     p->popStack = 0;
  1214   1260     p->pc = pc + 1;
  1215   1261     p->pTos = pTos;
  1216   1262     rc = SQLITE_ROW;
  1217   1263     goto vdbe_return;
  1218   1264   }
  1219   1265   
  1220         -/* Opcode: Concat P1 P2 *
         1266  +/* Opcode: Concat P1 P2 P3 * *
  1221   1267   **
  1222         -** Look at the first P1+2 elements of the stack.  Append them all 
  1223         -** together with the lowest element first.  The original P1+2 elements
  1224         -** are popped from the stack if P2==0 and retained if P2==1.  If
  1225         -** any element of the stack is NULL, then the result is NULL.
  1226         -**
  1227         -** When P1==1, this routine makes a copy of the top stack element
  1228         -** into memory obtained from sqlite3_malloc().
         1268  +** Add the text in register P1 onto the end of the text in
         1269  +** register P2 and store the result in register P3.
         1270  +** If either the P1 or P2 text are NULL then store NULL in P3.
  1229   1271   */
  1230         -case OP_Concat: {           /* same as TK_CONCAT */
         1272  +case OP_Concat: {           /* same as TK_CONCAT, in1, in2, out3 */
  1231   1273     char *zNew;
  1232   1274     i64 nByte;
  1233         -  int nField;
  1234         -  int i, j;
  1235         -  Mem *pTerm;
  1236         -
  1237         -  /* Loop through the stack elements to see how long the result will be. */
  1238         -  nField = pOp->p1 + 2;
  1239         -  pTerm = &pTos[1-nField];
  1240         -  nByte = 0;
  1241         -  for(i=0; i<nField; i++, pTerm++){
  1242         -    assert( pOp->p2==0 || (pTerm->flags&MEM_Str) );
  1243         -    if( pTerm->flags&MEM_Null ){
  1244         -      nByte = -1;
  1245         -      break;
  1246         -    }
  1247         -    ExpandBlob(pTerm);
  1248         -    Stringify(pTerm, encoding);
  1249         -    nByte += pTerm->n;
  1250         -  }
  1251         -
  1252         -  if( nByte<0 ){
  1253         -    /* If nByte is less than zero, then there is a NULL value on the stack.
  1254         -    ** In this case just pop the values off the stack (if required) and
  1255         -    ** push on a NULL.
  1256         -    */
  1257         -    if( pOp->p2==0 ){
  1258         -      popStack(&pTos, nField);
  1259         -    }
  1260         -    pTos++;
  1261         -    pTos->flags = MEM_Null;
  1262         -  }else{
  1263         -    /* Otherwise malloc() space for the result and concatenate all the
  1264         -    ** stack values.
  1265         -    */
  1266         -    if( nByte+2>SQLITE_MAX_LENGTH ){
  1267         -      goto too_big;
  1268         -    }
  1269         -    zNew = sqlite3DbMallocRaw(db, nByte+2 );
  1270         -    if( zNew==0 ) goto no_mem;
  1271         -    j = 0;
  1272         -    pTerm = &pTos[1-nField];
  1273         -    for(i=j=0; i<nField; i++, pTerm++){
  1274         -      int n = pTerm->n;
  1275         -      assert( pTerm->flags & (MEM_Str|MEM_Blob) );
  1276         -      memcpy(&zNew[j], pTerm->z, n);
  1277         -      j += n;
  1278         -    }
  1279         -    zNew[j] = 0;
  1280         -    zNew[j+1] = 0;
  1281         -    assert( j==nByte );
  1282         -
  1283         -    if( pOp->p2==0 ){
  1284         -      popStack(&pTos, nField);
  1285         -    }
  1286         -    pTos++;
  1287         -    pTos->n = j;
  1288         -    pTos->flags = MEM_Str|MEM_Dyn|MEM_Term;
  1289         -    pTos->xDel = 0;
  1290         -    pTos->enc = encoding;
  1291         -    pTos->z = zNew;
  1292         -  }
         1275  +
         1276  +  if( (pIn1->flags | pIn2->flags) & MEM_Null ){
         1277  +    Release(pOut);
         1278  +    pOut->flags = MEM_Null;
         1279  +    break;
         1280  +  }
         1281  +  ExpandBlob(pIn1);
         1282  +  Stringify(pIn1, encoding);
         1283  +  ExpandBlob(pIn2);
         1284  +  Stringify(pIn2, encoding);
         1285  +  nByte = pIn1->n + pIn2->n;
         1286  +  if( nByte>SQLITE_MAX_LENGTH ){
         1287  +    goto too_big;
         1288  +  }
         1289  +  zNew = sqlite3DbMallocRaw(db, nByte+2);
         1290  +  if( zNew==0 ){
         1291  +    goto no_mem;
         1292  +  }
         1293  +  memcpy(zNew, pIn2->z, pIn2->n);
         1294  +  memcpy(&zNew[pIn2->n], pIn1->z, pIn1->n);
         1295  +  zNew[nByte] = 0;
         1296  +  zNew[nByte+1] = 0;
         1297  +  Release(pOut);
         1298  +  pOut->n = nByte;
         1299  +  pOut->flags = MEM_Str|MEM_Dyn|MEM_Term;
         1300  +  pOut->xDel = 0;
         1301  +  pOut->enc = encoding;
         1302  +  pOut->z = zNew;
  1293   1303     break;
  1294   1304   }
  1295   1305   
  1296   1306   /* Opcode: Add * * *
  1297   1307   **
  1298   1308   ** Pop the top two elements from the stack, add them together,
  1299   1309   ** and push the result back onto the stack.  If either element
................................................................................
  1335   1345   ** first (what was on top of the stack) from the second (the
  1336   1346   ** next on stack)
  1337   1347   ** and push the remainder after division onto the stack.  If either element
  1338   1348   ** is a string then it is converted to a double using the atof()
  1339   1349   ** function before the division.  Division by zero returns NULL.
  1340   1350   ** If either operand is NULL, the result is NULL.
  1341   1351   */
  1342         -case OP_Add:                   /* same as TK_PLUS, no-push */
  1343         -case OP_Subtract:              /* same as TK_MINUS, no-push */
  1344         -case OP_Multiply:              /* same as TK_STAR, no-push */
  1345         -case OP_Divide:                /* same as TK_SLASH, no-push */
  1346         -case OP_Remainder: {           /* same as TK_REM, no-push */
  1347         -  Mem *pNos = &pTos[-1];
         1352  +case OP_Add:                   /* same as TK_PLUS, in1, in2, out3 */
         1353  +case OP_Subtract:              /* same as TK_MINUS, in1, in2, out3 */
         1354  +case OP_Multiply:              /* same as TK_STAR, in1, in2, out3 */
         1355  +case OP_Divide:                /* same as TK_SLASH, in1, in2, out3 */
         1356  +case OP_Remainder: {           /* same as TK_REM, in1, in2, out3 */
  1348   1357     int flags;
  1349         -  assert( pNos>=p->aStack );
  1350         -  flags = pTos->flags | pNos->flags;
         1358  +  flags = pIn1->flags | pIn2->flags;
  1351   1359     if( (flags & MEM_Null)!=0 ){
  1352         -    Release(pTos);
  1353         -    pTos--;
  1354         -    Release(pTos);
  1355         -    pTos->flags = MEM_Null;
  1356         -  }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){
         1360  +    Release(pOut);
         1361  +    pOut->flags = MEM_Null;
         1362  +  }else if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
  1357   1363       i64 a, b;
  1358         -    a = pTos->u.i;
  1359         -    b = pNos->u.i;
         1364  +    a = pIn1->u.i;
         1365  +    b = pIn2->u.i;
  1360   1366       switch( pOp->opcode ){
  1361   1367         case OP_Add:         b += a;       break;
  1362   1368         case OP_Subtract:    b -= a;       break;
  1363   1369         case OP_Multiply:    b *= a;       break;
  1364   1370         case OP_Divide: {
  1365   1371           if( a==0 ) goto divide_by_zero;
  1366   1372           /* Dividing the largest possible negative 64-bit integer (1<<63) by 
................................................................................
  1377   1383         default: {
  1378   1384           if( a==0 ) goto divide_by_zero;
  1379   1385           if( a==-1 ) a = 1;
  1380   1386           b %= a;
  1381   1387           break;
  1382   1388         }
  1383   1389       }
  1384         -    Release(pTos);
  1385         -    pTos--;
  1386         -    Release(pTos);
  1387         -    pTos->u.i = b;
  1388         -    pTos->flags = MEM_Int;
         1390  +    Release(pOut);
         1391  +    pOut->u.i = b;
         1392  +    pOut->flags = MEM_Int;
  1389   1393     }else{
  1390   1394       double a, b;
  1391         -    a = sqlite3VdbeRealValue(pTos);
  1392         -    b = sqlite3VdbeRealValue(pNos);
         1395  +    a = sqlite3VdbeRealValue(pIn1);
         1396  +    b = sqlite3VdbeRealValue(pIn2);
  1393   1397       switch( pOp->opcode ){
  1394   1398         case OP_Add:         b += a;       break;
  1395   1399         case OP_Subtract:    b -= a;       break;
  1396   1400         case OP_Multiply:    b *= a;       break;
  1397   1401         case OP_Divide: {
  1398   1402           if( a==0.0 ) goto divide_by_zero;
  1399   1403           b /= a;
................................................................................
  1407   1411           b = ib % ia;
  1408   1412           break;
  1409   1413         }
  1410   1414       }
  1411   1415       if( sqlite3_isnan(b) ){
  1412   1416         goto divide_by_zero;
  1413   1417       }
  1414         -    Release(pTos);
  1415         -    pTos--;
  1416         -    Release(pTos);
  1417         -    pTos->r = b;
  1418         -    pTos->flags = MEM_Real;
         1418  +    Release(pOut);
         1419  +    pOut->r = b;
         1420  +    pOut->flags = MEM_Real;
  1419   1421       if( (flags & MEM_Real)==0 ){
  1420         -      sqlite3VdbeIntegerAffinity(pTos);
         1422  +      sqlite3VdbeIntegerAffinity(pOut);
  1421   1423       }
  1422   1424     }
  1423   1425     break;
  1424   1426   
  1425   1427   divide_by_zero:
  1426         -  Release(pTos);
  1427         -  pTos--;
  1428         -  Release(pTos);
  1429         -  pTos->flags = MEM_Null;
         1428  +  Release(pOut);
         1429  +  pOut->flags = MEM_Null;
  1430   1430     break;
  1431   1431   }
  1432   1432   
  1433   1433   /* Opcode: CollSeq * * P4
  1434   1434   **
  1435   1435   ** P4 is a pointer to a CollSeq struct. If the next call to a user function
  1436   1436   ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
................................................................................
  1565   1565   /* Opcode: ShiftRight * * *
  1566   1566   **
  1567   1567   ** Pop the top two elements from the stack.  Convert both elements
  1568   1568   ** to integers.  Push back onto the stack the second element shifted
  1569   1569   ** right by N bits where N is the top element on the stack.
  1570   1570   ** If either operand is NULL, the result is NULL.
  1571   1571   */
  1572         -case OP_BitAnd:                 /* same as TK_BITAND, no-push */
  1573         -case OP_BitOr:                  /* same as TK_BITOR, no-push */
  1574         -case OP_ShiftLeft:              /* same as TK_LSHIFT, no-push */
  1575         -case OP_ShiftRight: {           /* same as TK_RSHIFT, no-push */
  1576         -  Mem *pNos = &pTos[-1];
         1572  +case OP_BitAnd:                 /* same as TK_BITAND, in1, in2, out3 */
         1573  +case OP_BitOr:                  /* same as TK_BITOR, in1, in2, out3 */
         1574  +case OP_ShiftLeft:              /* same as TK_LSHIFT, in1, in2, out3 */
         1575  +case OP_ShiftRight: {           /* same as TK_RSHIFT, in1, in2, out3 */
  1577   1576     i64 a, b;
  1578   1577   
  1579         -  assert( pNos>=p->aStack );
  1580         -  if( (pTos->flags | pNos->flags) & MEM_Null ){
  1581         -    popStack(&pTos, 2);
  1582         -    pTos++;
  1583         -    pTos->flags = MEM_Null;
         1578  +  if( (pIn1->flags | pIn2->flags) & MEM_Null ){
         1579  +    Release(pOut);
         1580  +    pOut->flags = MEM_Null;
  1584   1581       break;
  1585   1582     }
  1586         -  a = sqlite3VdbeIntValue(pNos);
  1587         -  b = sqlite3VdbeIntValue(pTos);
         1583  +  a = sqlite3VdbeIntValue(pIn2);
         1584  +  b = sqlite3VdbeIntValue(pIn1);
  1588   1585     switch( pOp->opcode ){
  1589   1586       case OP_BitAnd:      a &= b;     break;
  1590   1587       case OP_BitOr:       a |= b;     break;
  1591   1588       case OP_ShiftLeft:   a <<= b;    break;
  1592   1589       case OP_ShiftRight:  a >>= b;    break;
  1593   1590       default:   /* CANT HAPPEN */     break;
  1594   1591     }
  1595         -  Release(pTos);
  1596         -  pTos--;
  1597         -  Release(pTos);
  1598         -  pTos->u.i = a;
  1599         -  pTos->flags = MEM_Int;
         1592  +  Release(pOut);
         1593  +  pOut->u.i = a;
         1594  +  pOut->flags = MEM_Int;
  1600   1595     break;
  1601   1596   }
  1602   1597   
  1603   1598   /* Opcode: AddImm  P1 P2 * * *
  1604   1599   ** 
  1605   1600   ** Add P2 the value in register P1.
  1606   1601   ** The result is always an integer.
................................................................................
  1660   1655   ** If P3 is not zero, then act on the value in register P3 instead
  1661   1656   ** of using the stack.
  1662   1657   */
  1663   1658   case OP_MustBeInt: {            /* no-push, jump */
  1664   1659     Mem *pMem = ((pOp->p3==0)?pTos:&p->aMem[pOp->p3]);
  1665   1660     assert( pOp->p3 || pTos>=p->aStack );
  1666   1661     assert( pOp->p3>=0 && pOp->p3<=p->nMem );
         1662  +  REGISTER_TRACE(pOp->p3, pMem);
  1667   1663     applyAffinity(pMem, SQLITE_AFF_NUMERIC, encoding);
  1668   1664     if( (pMem->flags & MEM_Int)==0 ){
  1669   1665       if( pOp->p2==0 ){
  1670   1666         rc = SQLITE_MISMATCH;
  1671   1667         goto abort_due_to_error;
  1672   1668       }else if( pMem==pTos ){
  1673   1669         if( pOp->p1 ) popStack(&pTos, 1);
................................................................................
  1939   1935       pTos++;
  1940   1936       pTos->flags = MEM_Int;
  1941   1937       pTos->u.i = res;
  1942   1938     }
  1943   1939     break;
  1944   1940   }
  1945   1941   
  1946         -/* Opcode: And * * *
  1947         -**
  1948         -** Pop two values off the stack.  Take the logical AND of the
  1949         -** two values and push the resulting boolean value back onto the
  1950         -** stack. 
  1951         -*/
  1952         -/* Opcode: Or * * *
  1953         -**
  1954         -** Pop two values off the stack.  Take the logical OR of the
  1955         -** two values and push the resulting boolean value back onto the
  1956         -** stack. 
  1957         -*/
  1958         -case OP_And:              /* same as TK_AND, no-push */
  1959         -case OP_Or: {             /* same as TK_OR, no-push */
  1960         -  Mem *pNos = &pTos[-1];
  1961         -  int v1, v2;    /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */
  1962         -
  1963         -  assert( pNos>=p->aStack );
  1964         -  if( pTos->flags & MEM_Null ){
         1942  +/* Opcode: And P1 P2 P3 * *
         1943  +**
         1944  +** Take the logical AND of the values in registers P1 and P2 and
         1945  +** write the result into register P3.
         1946  +**
         1947  +** If either P1 or P2 is 0 (false) then the result is 0 even if
         1948  +** the other input is NULL.  A NULL and true or two NULLs give
         1949  +** a NULL output.
         1950  +*/
         1951  +/* Opcode: Or P1 P2 P3 * *
         1952  +**
         1953  +** Take the logical OR of the values in register P1 and P2 and
         1954  +** store the answer in register P3.
         1955  +**
         1956  +** If either P1 or P2 is nonzero (true) then the result is 1 (true)
         1957  +** even if the other input is NULL.  A NULL and false or two NULLs
         1958  +** give a NULL output.
         1959  +*/
         1960  +case OP_And:              /* same as TK_AND, in1, in2, out3 */
         1961  +case OP_Or: {             /* same as TK_OR, in1, in2, out3 */
         1962  +  int v1, v2;    /* 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
         1963  +
         1964  +  if( pIn1->flags & MEM_Null ){
  1965   1965       v1 = 2;
  1966   1966     }else{
  1967         -    sqlite3VdbeMemIntegerify(pTos);
  1968         -    v1 = pTos->u.i==0;
         1967  +    v1 = sqlite3VdbeIntValue(pIn1)!=0;
  1969   1968     }
  1970         -  if( pNos->flags & MEM_Null ){
         1969  +  if( pIn2->flags & MEM_Null ){
  1971   1970       v2 = 2;
  1972   1971     }else{
  1973         -    sqlite3VdbeMemIntegerify(pNos);
  1974         -    v2 = pNos->u.i==0;
         1972  +    v2 = sqlite3VdbeIntValue(pIn2)!=0;
  1975   1973     }
  1976   1974     if( pOp->opcode==OP_And ){
  1977         -    static const unsigned char and_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
         1975  +    static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
  1978   1976       v1 = and_logic[v1*3+v2];
  1979   1977     }else{
  1980         -    static const unsigned char or_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
         1978  +    static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
  1981   1979       v1 = or_logic[v1*3+v2];
  1982   1980     }
  1983         -  popStack(&pTos, 2);
  1984         -  pTos++;
         1981  +  Release(pOut);
  1985   1982     if( v1==2 ){
  1986         -    pTos->flags = MEM_Null;
         1983  +    pOut->flags = MEM_Null;
  1987   1984     }else{
  1988         -    pTos->u.i = v1==0;
  1989         -    pTos->flags = MEM_Int;
         1985  +    pOut->u.i = v1;
         1986  +    pOut->flags = MEM_Int;
  1990   1987     }
  1991   1988     break;
  1992   1989   }
  1993   1990   
  1994   1991   /* Opcode: Negative * * *
  1995   1992   **
  1996   1993   ** Treat the top of the stack as a numeric quantity.  Replace it
................................................................................
  2421   2418     }
  2422   2419   
  2423   2420     /* pDest->z might be pointing to sMem.zShort[].  Fix that so that we
  2424   2421     ** can abandon sMem */
  2425   2422     rc = sqlite3VdbeMemMakeWriteable(pDest);
  2426   2423   
  2427   2424   op_column_out:
         2425  +  REGISTER_TRACE(pOp->p3, pDest);
  2428   2426     break;
  2429   2427   }
  2430   2428   
  2431   2429   /* Opcode: MakeRecord P1 P2 P4
  2432   2430   **
  2433   2431   ** Convert the top abs(P1) entries of the stack into a single entry
  2434   2432   ** suitable for use as a data record in a database table or as a key
................................................................................
  3500   3498     int i = pOp->p1;
  3501   3499     Cursor *pC;
  3502   3500     BtCursor *pCrsr;
  3503   3501     Mem *pKey;
  3504   3502     if( pOp->p3 ){
  3505   3503       assert( pOp->p3<=p->nMem );
  3506   3504       pKey = &p->aMem[pOp->p3];
         3505  +    REGISTER_TRACE(pOp->p3, pKey);
  3507   3506     }else{
  3508   3507       pKey = pTos;
  3509   3508       assert( pTos>=p->aStack );
  3510   3509     }
  3511   3510     assert( i>=0 && i<p->nCursor );
  3512   3511     assert( p->apCsr[i]!=0 );
  3513   3512     if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
................................................................................
  3654   3653         }
  3655   3654   
  3656   3655   #ifndef SQLITE_OMIT_AUTOINCREMENT
  3657   3656         if( pOp->p3 ){
  3658   3657           Mem *pMem;
  3659   3658           assert( pOp->p3>0 && pOp->p3<=p->nMem ); /* P3 is a valid memory cell */
  3660   3659           pMem = &p->aMem[pOp->p3];
         3660  +	REGISTER_TRACE(pOp->p3, pMem);
  3661   3661           sqlite3VdbeMemIntegerify(pMem);
  3662   3662           assert( (pMem->flags & MEM_Int)!=0 );  /* mem(P3) holds an integer */
  3663   3663           if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
  3664   3664             rc = SQLITE_FULL;
  3665   3665             goto abort_due_to_error;
  3666   3666           }
  3667   3667           if( v<pMem->u.i+1 ){
................................................................................
  3735   3735     Mem *pData = &p->aMem[pOp->p2];
  3736   3736     Mem *pKey = &p->aMem[pOp->p3];
  3737   3737   
  3738   3738     int i = pOp->p1;
  3739   3739     Cursor *pC;
  3740   3740     assert( i>=0 && i<p->nCursor );
  3741   3741     assert( p->apCsr[i]!=0 );
         3742  +  REGISTER_TRACE(pOp->p2, pData);
         3743  +  REGISTER_TRACE(pOp->p3, pKey);
  3742   3744     if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){
  3743   3745       i64 iKey;   /* The integer ROWID or key for the record to be inserted */
  3744   3746   
  3745   3747       assert( pKey->flags & MEM_Int );
  3746   3748       assert( pC->isTable );
  3747   3749       iKey = intToKey(pKey->u.i);
  3748   3750   
................................................................................
  3958   3960       assert( pC->nData<=SQLITE_MAX_LENGTH );
  3959   3961       pOut->z = pC->pData;
  3960   3962       pOut->flags = MEM_Blob|MEM_Ephem;
  3961   3963     }else{
  3962   3964       pOut->flags = MEM_Null;
  3963   3965     }
  3964   3966     pOut->enc = SQLITE_UTF8;  /* In case the blob is ever cast to text */
         3967  +  REGISTER_TRACE(pOp->p3, pOut);
  3965   3968     break;
  3966   3969   }
  3967   3970   
  3968   3971   /* Opcode: Rowid P1 P2 * * *
  3969   3972   **
  3970   3973   ** Store in register P2 an integer which is the key of the table entry that
  3971   3974   ** P1 is currently point to.  If p2==0 then push the integer.
................................................................................
  4642   4645   /* Opcode: FifoWrite P1 * *
  4643   4646   **
  4644   4647   ** Write the integer from memory cell P1 into the Fifo.
  4645   4648   */
  4646   4649   case OP_FifoWrite: {        /* no-push */
  4647   4650     Mem *pReg = &p->aMem[pOp->p1];
  4648   4651     assert( pOp->p1>0 && pOp->p1<=p->nMem );
         4652  +  REGISTER_TRACE(pOp->p1, pReg);
  4649   4653     sqlite3VdbeMemIntegerify(pReg);
  4650   4654     if( sqlite3VdbeFifoPush(&p->sFifo, pReg->u.i)==SQLITE_NOMEM ){
  4651   4655       goto no_mem;
  4652   4656     }
  4653   4657     break;
  4654   4658   }
  4655   4659   
................................................................................
  4667   4671     CHECK_FOR_INTERRUPT;
  4668   4672     if( sqlite3VdbeFifoPop(&p->sFifo, &v)==SQLITE_DONE ){
  4669   4673       pc = pOp->p2 - 1;
  4670   4674     }else{
  4671   4675       Mem *pOut = &p->aMem[pOp->p1];
  4672   4676       assert( pOp->p1>0 && pOp->p1<=p->nMem );
  4673   4677       sqlite3VdbeMemSetInt64(pOut, v);
         4678  +    REGISTER_TRACE(pOp->p1, pOut);
  4674   4679     }
  4675   4680     break;
  4676   4681   }
  4677   4682   
  4678   4683   #ifndef SQLITE_OMIT_TRIGGER
  4679   4684   /* Opcode: ContextPush * * * 
  4680   4685   **
................................................................................
  5080   5085     int nArg;
  5081   5086     int iQuery;
  5082   5087     const sqlite3_module *pModule;
  5083   5088     Mem *pQuery = &p->aMem[pOp->p3];
  5084   5089     Mem *pArgc = &pQuery[1];
  5085   5090   
  5086   5091     Cursor *pCur = p->apCsr[pOp->p1];
         5092  +
         5093  +  REGISTER_TRACE(pOp->p3, pQuery);
  5087   5094     assert( pCur->pVtabCursor );
  5088   5095     pModule = pCur->pVtabCursor->pVtab->pModule;
  5089   5096   
  5090   5097     /* Grab the index number and argc parameters off the top of the stack. */
  5091   5098     assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
  5092   5099     nArg = pArgc->u.i;
  5093   5100     iQuery = pQuery->u.i;
................................................................................
  5180   5187       ** do this regardless of whether or not an error occured to ensure any
  5181   5188       ** dynamic allocation in sContext.s (a Mem struct) is  released.
  5182   5189       */
  5183   5190       sqlite3VdbeChangeEncoding(&sContext.s, encoding);
  5184   5191       if( pOp->p3>0 ){
  5185   5192         assert( pOp->p3<=p->nMem );
  5186   5193         pDest = &p->aMem[pOp->p3];
         5194  +      REGISTER_TRACE(pOp->p3, pDest);
  5187   5195       }else{
  5188   5196         pDest = ++pTos;
  5189   5197         pDest->flags = 0;
  5190   5198       }
  5191   5199       sqlite3VdbeMemMove(pDest, &sContext.s);
  5192   5200   
  5193   5201       if( sqlite3SafetyOn(db) ){
................................................................................
  5252   5260   ** This opcode invokes the corresponding xRename method. The value
  5253   5261   ** in register P1 is passed as the zName argument to the xRename method.
  5254   5262   */
  5255   5263   case OP_VRename: {   /* no-push */
  5256   5264     sqlite3_vtab *pVtab = pOp->p4.pVtab;
  5257   5265     Mem *pName = &p->aMem[pOp->p1];
  5258   5266     assert( pVtab->pModule->xRename );
         5267  +  REGISTER_TRACE(pOp->p1, pName);
  5259   5268   
  5260   5269     Stringify(pName, encoding);
  5261   5270   
  5262   5271     if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  5263   5272     sqlite3VtabLock(pVtab);
  5264   5273     rc = pVtab->pModule->xRename(pVtab, pName->z);
  5265   5274     sqlite3VtabUnlock(db, pVtab);
................................................................................
  5387   5396         sqlite3VdbeMemSanity(pTos);
  5388   5397         assert( !sqlite3VdbeMemTooBig(pTos) );
  5389   5398       }
  5390   5399       assert( pc>=-1 && pc<p->nOp );
  5391   5400   
  5392   5401   #ifdef SQLITE_DEBUG
  5393   5402       /* Code for tracing the vdbe stack. */
  5394         -    if( p->trace && pTos>=p->aStack ){
  5395         -      int i;
  5396         -      fprintf(p->trace, "Stack:");
  5397         -      for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){
  5398         -        if( pTos[i].flags & MEM_Null ){
  5399         -          fprintf(p->trace, " NULL");
  5400         -        }else if( (pTos[i].flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
  5401         -          fprintf(p->trace, " si:%lld", pTos[i].u.i);
  5402         -        }else if( pTos[i].flags & MEM_Int ){
  5403         -          fprintf(p->trace, " i:%lld", pTos[i].u.i);
  5404         -        }else if( pTos[i].flags & MEM_Real ){
  5405         -          fprintf(p->trace, " r:%g", pTos[i].r);
  5406         -        }else{
  5407         -          char zBuf[200];
  5408         -          sqlite3VdbeMemPrettyPrint(&pTos[i], zBuf);
  5409         -          fprintf(p->trace, " ");
  5410         -          fprintf(p->trace, "%s", zBuf);
         5403  +    if( p->trace ){
         5404  +      if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
         5405  +      if( (opProperty&(OPFLG_OUT2_PRERELEASE|OPFLG_OUT2))!=0 && pOp->p2>0 ){
         5406  +        registerTrace(p->trace, pOp->p2, pOut);
         5407  +      }
         5408  +      if( (opProperty&OPFLG_OUT3)!=0 && pOp->p3>0 ){
         5409  +        registerTrace(p->trace, pOp->p3, pOut);
         5410  +      }
         5411  +      if( pTos>=p->aStack ){
         5412  +        int i;
         5413  +        fprintf(p->trace, "Stack:");
         5414  +        for(i=0; i>-5 && &pTos[i]>=p->aStack; i--){
         5415  +          memTracePrint(p->trace, &pTos[i]);
  5411   5416           }
         5417  +        fprintf(p->trace,"\n");
  5412   5418         }
  5413         -      if( rc!=0 ) fprintf(p->trace," rc=%d",rc);
  5414         -      fprintf(p->trace,"\n");
  5415   5419       }
  5416   5420   #endif  /* SQLITE_DEBUG */
  5417   5421   #endif  /* NDEBUG */
  5418   5422     }  /* The end of the for(;;) loop the loops through opcodes */
  5419   5423   
  5420   5424     /* If we reach this point, it means that execution is finished.
  5421   5425     */