/ Check-in [eea231f8]
Login

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

Overview
Comment:Have sqlite3.c automatically turn on osinst logging for all connections.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | osinst
Files: files | file ages | folders
SHA3-256: eea231f81b3ca6196949a84e8e0eb73a1ed03cb1ddd21f3b24787999caef8b1a
User & Date: dan 2019-10-05 17:29:52
Context
2019-10-05
19:17
Add a timestamp to each osinst log entry, to facilitate merging multiple log files. check-in: c9519c0c user: dan tags: osinst
17:29
Have sqlite3.c automatically turn on osinst logging for all connections. check-in: eea231f8 user: dan tags: osinst
2019-10-04
15:03
Version 3.30.0 check-in: c20a3533 user: drh tags: trunk, release, version-3.30.0
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   373    373     opcodes.c \
   374    374     opcodes.h \
   375    375     parse.c \
   376    376     parse.h \
   377    377     config.h \
   378    378     shell.c \
   379    379     sqlite3.h
          380  +
          381  +SRC += $(TOP)/src/test_osinst.c
   380    382   
   381    383   # Source code to the test files.
   382    384   #
   383    385   TESTSRC = \
   384    386     $(TOP)/src/test1.c \
   385    387     $(TOP)/src/test2.c \
   386    388     $(TOP)/src/test3.c \
................................................................................
   677    679                $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS)
   678    680   
   679    681   sessionfuzz$(TEXE):	$(TOP)/test/sessionfuzz.c sqlite3.c sqlite3.h
   680    682   	$(LTLINK) -o $@ $(TOP)/test/sessionfuzz.c $(TLIBS)
   681    683   
   682    684   dbfuzz$(TEXE):	$(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
   683    685   	$(LTLINK) -o $@ $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c $(TLIBS)
          686  +
          687  +osinst2sql$(TEXE):	$(TOP)/tool/osinst2sql.c sqlite3.c sqlite3.h
          688  +	$(LTLINK) -o $@ $(TOP)/tool/osinst2sql.c sqlite3.c $(TLIBS)
   684    689   
   685    690   DBFUZZ2_OPTS = \
   686    691     -DSQLITE_THREADSAFE=0 \
   687    692     -DSQLITE_OMIT_LOAD_EXTENSION \
   688    693     -DSQLITE_ENABLE_DESERIALIZE \
   689    694     -DSQLITE_DEBUG \
   690    695     -DSQLITE_ENABLE_DBSTAT_VTAB \

Changes to Makefile.msc.

  1466   1466     $(SQLITETCLDECLSH)
  1467   1467   !ELSE
  1468   1468   SRC12 =
  1469   1469   !ENDIF
  1470   1470   
  1471   1471   # All source code files.
  1472   1472   #
  1473         -SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11)
         1473  +SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11) $(TOP)\src\test_osinst.c
  1474   1474   
  1475   1475   # Source code to the test files.
  1476   1476   #
  1477   1477   TESTSRC = \
  1478   1478     $(TOP)\src\test1.c \
  1479   1479     $(TOP)\src\test2.c \
  1480   1480     $(TOP)\src\test3.c \
................................................................................
  1768   1768   
  1769   1769   fuzzershell.exe:	$(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
  1770   1770   	$(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1771   1771   
  1772   1772   dbfuzz.exe:	$(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
  1773   1773   	$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1774   1774   
         1775  +osinst2sql.exe:	$(TOP)\tool\osinst2sql.c $(SQLITE3C) $(SQLITE3H)
         1776  +	$(LTLINK) $(NO_WARN) $(TOP)\tool\osinst2sql.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1777  +
  1775   1778   fuzzcheck.exe:	$(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
  1776   1779   	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1777   1780   
  1778   1781   ossshell.exe:	$(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
  1779   1782   	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1780   1783   
  1781   1784   sessionfuzz.exe:	zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H)

Changes to main.mk.

   293    293     opcodes.c \
   294    294     opcodes.h \
   295    295     parse.c \
   296    296     parse.h \
   297    297     shell.c \
   298    298     sqlite3.h
   299    299   
          300  +SRC += $(TOP)/src/test_osinst.c
          301  +
   300    302   
   301    303   # Source code to the test files.
   302    304   #
   303    305   TESTSRC = \
   304    306     $(TOP)/ext/expert/sqlite3expert.c \
   305    307     $(TOP)/ext/expert/test_expert.c \
   306    308     $(TOP)/ext/fts3/fts3_term.c \
................................................................................
   575    577   	  $(FUZZERSHELL_OPT) $(TOP)/tool/fuzzershell.c sqlite3.c \
   576    578   	  $(TLIBS) $(THREADLIB)
   577    579   
   578    580   dbfuzz$(EXE):	$(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
   579    581   	$(TCCX) -o dbfuzz$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
   580    582   	  $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c \
   581    583   	  $(TLIBS) $(THREADLIB)
          584  +
          585  +osinst2sql$(EXE): $(TOP)/tool/osinst2sql.c sqlite3.c sqlite3.h
          586  +	$(TCCX) -o osinst2sql$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
          587  +	  $(DBFUZZ_OPT) $(TOP)/tool/osinst2sql.c sqlite3.c \
          588  +	  $(TLIBS) $(THREADLIB)
   582    589   
   583    590   DBFUZZ2_OPTS = \
   584    591     -DSQLITE_THREADSAFE=0 \
   585    592     -DSQLITE_OMIT_LOAD_EXTENSION \
   586    593     -DSQLITE_ENABLE_DESERIALIZE \
   587    594     -DSQLITE_DEBUG \
   588    595     -DSQLITE_ENABLE_DBSTAT_VTAB \

Changes to src/main.c.

  1143   1143   ** version forces the connection to become a zombie if there are
  1144   1144   ** unclosed resources, and arranges for deallocation when the last
  1145   1145   ** prepare statement or sqlite3_backup closes.
  1146   1146   */
  1147   1147   int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
  1148   1148   int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
  1149   1149   
         1150  +#ifdef SQLITE_ENABLE_OSINST
         1151  +int sqlite3_vfslog_new(const char*,const char*,const char*,sqlite3_vfs**);
         1152  +int sqlite3_vfslog_finalize(const char*);
         1153  +#endif
         1154  +
  1150   1155   
  1151   1156   /*
  1152   1157   ** Close the mutex on database connection db.
  1153   1158   **
  1154   1159   ** Furthermore, if database connection db is a zombie (meaning that there
  1155   1160   ** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
  1156   1161   ** every sqlite3_stmt has now been finalized and every sqlite3_backup has
................................................................................
  1247   1252     sqlite3CloseExtensions(db);
  1248   1253   #if SQLITE_USER_AUTHENTICATION
  1249   1254     sqlite3_free(db->auth.zAuthUser);
  1250   1255     sqlite3_free(db->auth.zAuthPW);
  1251   1256   #endif
  1252   1257   
  1253   1258     db->magic = SQLITE_MAGIC_ERROR;
         1259  +
         1260  +#ifdef SQLITE_ENABLE_OSINST
         1261  +  if( db->pOsinstVfs ){
         1262  +    sqlite3_vfslog_finalize(db->pOsinstVfs->zName);
         1263  +    db->pOsinstVfs = 0;
         1264  +  }
         1265  +#endif
  1254   1266   
  1255   1267     /* The temp-database schema is allocated differently from the other schema
  1256   1268     ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
  1257   1269     ** So it needs to be freed here. Todo: Why not roll the temp schema into
  1258   1270     ** the same sqliteMalloc() as the one that allocates the database 
  1259   1271     ** structure?
  1260   1272     */
................................................................................
  3183   3195     testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
  3184   3196     testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
  3185   3197     if( ((1<<(flags&7)) & 0x46)==0 ){
  3186   3198       rc = SQLITE_MISUSE_BKPT;  /* IMP: R-65497-44594 */
  3187   3199     }else{
  3188   3200       rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
  3189   3201     }
         3202  +#ifdef SQLITE_ENABLE_OSINST
         3203  +  /* If this is not a temporary or ":memory:" database, create an osinst
         3204  +  ** VFS to use. */
         3205  +  assert( db->pVfs );
         3206  +  if( rc==SQLITE_OK && zOpen && zOpen[0] && strcmp(":memory:", zOpen) ){
         3207  +    u32 iVal = 0;
         3208  +    char *zLog = 0;
         3209  +    sqlite3_randomness(sizeof(iVal), (void*)&iVal);
         3210  +    zLog = sqlite3_mprintf("%s-osinst-%08x", zOpen, iVal);
         3211  +    if( zLog==0 ){
         3212  +      rc = SQLITE_NOMEM_BKPT;
         3213  +    }else{
         3214  +      sqlite3_vfs *pVfs = 0;
         3215  +      rc = sqlite3_vfslog_new(zLog, db->pVfs->zName, zLog, &pVfs);
         3216  +      sqlite3_free(zLog);
         3217  +      db->pOsinstVfs = db->pVfs = pVfs;
         3218  +    }
         3219  +  }
         3220  +#endif
  3190   3221     if( rc!=SQLITE_OK ){
  3191   3222       if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
  3192   3223       sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
  3193   3224       sqlite3_free(zErrMsg);
  3194   3225       goto opendb_out;
  3195   3226     }
         3227  +
  3196   3228   
  3197   3229     /* Open the backend database driver */
  3198   3230     rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
  3199   3231                           flags | SQLITE_OPEN_MAIN_DB);
  3200   3232     if( rc!=SQLITE_OK ){
  3201   3233       if( rc==SQLITE_IOERR_NOMEM ){
  3202   3234         rc = SQLITE_NOMEM_BKPT;

Changes to src/sqliteInt.h.

    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14     14   */
    15     15   #ifndef SQLITEINT_H
    16     16   #define SQLITEINT_H
    17     17   
           18  +#define SQLITE_ENABLE_OSINST 1
           19  +
    18     20   /* Special Comments:
    19     21   **
    20     22   ** Some comments have special meaning to the tools that measure test
    21     23   ** coverage:
    22     24   **
    23     25   **    NO_TEST                     - The branches on this line are not
    24     26   **                                  measured by branch coverage.  This is
................................................................................
  1483   1485     void *pUnlockArg;                     /* Argument to xUnlockNotify */
  1484   1486     void (*xUnlockNotify)(void **, int);  /* Unlock notify callback */
  1485   1487     sqlite3 *pNextBlocked;        /* Next in list of all blocked connections */
  1486   1488   #endif
  1487   1489   #ifdef SQLITE_USER_AUTHENTICATION
  1488   1490     sqlite3_userauth auth;        /* User authentication information */
  1489   1491   #endif
         1492  +#ifdef SQLITE_ENABLE_OSINST
         1493  +  sqlite3_vfs *pOsinstVfs;      /* osinst VFS to finalize, if any */
         1494  +#endif
  1490   1495   };
  1491   1496   
  1492   1497   /*
  1493   1498   ** A macro to discover the encoding of a database.
  1494   1499   */
  1495   1500   #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
  1496   1501   #define ENC(db)        ((db)->enc)

Changes to src/test_osinst.c.

   638    638   #ifdef SQLITE_TEST
   639    639     sqlite3_io_error_pending = pending;
   640    640     sqlite3_io_error_persist = persist;
   641    641     sqlite3_diskfull_pending = diskfull;
   642    642   #endif
   643    643   }
   644    644   
   645         -static void put32bits(unsigned char *p, unsigned int v){
          645  +static void vfslogPut32bits(unsigned char *p, unsigned int v){
   646    646     p[0] = v>>24;
   647    647     p[1] = (unsigned char)(v>>16);
   648    648     p[2] = (unsigned char)(v>>8);
   649    649     p[3] = (unsigned char)v;
   650    650   }
   651    651   
   652    652   static void vfslog_call(
................................................................................
   660    660   ){
   661    661     VfslogVfs *p = (VfslogVfs *)pVfs;
   662    662     unsigned char *zRec;
   663    663     if( (24+p->nBuf)>sizeof(p->aBuf) ){
   664    664       vfslog_flush(p);
   665    665     }
   666    666     zRec = (unsigned char *)&p->aBuf[p->nBuf];
   667         -  put32bits(&zRec[0], eEvent);
   668         -  put32bits(&zRec[4], iFileid);
   669         -  put32bits(&zRec[8], (unsigned int)(nClick&0xffff));
   670         -  put32bits(&zRec[12], return_code);
   671         -  put32bits(&zRec[16], size);
   672         -  put32bits(&zRec[20], offset);
          667  +  vfslogPut32bits(&zRec[0], eEvent);
          668  +  vfslogPut32bits(&zRec[4], iFileid);
          669  +  vfslogPut32bits(&zRec[8], (unsigned int)(nClick&0xffffffff));
          670  +  vfslogPut32bits(&zRec[12], return_code);
          671  +  vfslogPut32bits(&zRec[16], size);
          672  +  vfslogPut32bits(&zRec[20], offset);
   673    673     p->nBuf += 24;
   674    674   }
   675    675   
   676    676   static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){
   677    677     VfslogVfs *p = (VfslogVfs *)pVfs;
   678    678     unsigned char *zRec;
   679    679     int nStr = zStr ? (int)strlen(zStr) : 0;
   680    680     if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){
   681    681       vfslog_flush(p);
   682    682     }
   683    683     zRec = (unsigned char *)&p->aBuf[p->nBuf];
   684         -  put32bits(&zRec[0], nStr);
          684  +  vfslogPut32bits(&zRec[0], nStr);
   685    685     if( zStr ){
   686    686       memcpy(&zRec[4], zStr, nStr);
   687    687     }
   688    688     p->nBuf += (4 + nStr);
   689    689   }
   690    690   
   691    691   static void vfslog_finalize(VfslogVfs *p){
................................................................................
   706    706     vfslog_finalize((VfslogVfs *)pVfs);
   707    707     return SQLITE_OK;
   708    708   }
   709    709   
   710    710   int sqlite3_vfslog_new(
   711    711     const char *zVfs,               /* New VFS name */
   712    712     const char *zParentVfs,         /* Parent VFS name (or NULL) */
   713         -  const char *zLog                /* Log file name */
          713  +  const char *zLog,               /* Log file name */
          714  +  sqlite3_vfs **ppVfs             /* OUT: New VFS object */
   714    715   ){
   715    716     VfslogVfs *p;
   716    717     sqlite3_vfs *pParent;
   717    718     int nByte;
   718    719     int flags;
   719    720     int rc;
   720    721     char *zFile;
................................................................................
   743    744     flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MASTER_JOURNAL;
   744    745     pParent->xDelete(pParent, zFile, 0);
   745    746     rc = pParent->xOpen(pParent, zFile, p->pLog, flags, &flags);
   746    747     if( rc==SQLITE_OK ){
   747    748       memcpy(p->aBuf, "sqlite_ostrace1.....", 20);
   748    749       p->iOffset = 0;
   749    750       p->nBuf = 20;
   750         -    rc = sqlite3_vfs_register((sqlite3_vfs *)p, 1);
          751  +    rc = sqlite3_vfs_register((sqlite3_vfs *)p, 0);
          752  +    if( ppVfs ) *ppVfs = (sqlite3_vfs*)p;
   751    753     }
   752    754     if( rc ){
   753    755       vfslog_finalize(p);
   754    756     }
   755    757     return rc;
   756    758   }
   757    759   
................................................................................
  1176   1178           Tcl_WrongNumArgs(interp, 2, objv, "VFS PARENT LOGFILE");
  1177   1179           return TCL_ERROR;
  1178   1180         }
  1179   1181         zVfs = Tcl_GetString(objv[2]);
  1180   1182         zParent = Tcl_GetString(objv[3]);
  1181   1183         zLog = Tcl_GetString(objv[4]);
  1182   1184         if( *zParent=='\0' ) zParent = 0;
  1183         -      rc = sqlite3_vfslog_new(zVfs, zParent, zLog);
         1185  +      rc = sqlite3_vfslog_new(zVfs, zParent, zLog, 0);
  1184   1186         if( rc!=SQLITE_OK ){
  1185   1187           Tcl_AppendResult(interp, "failed", 0);
  1186   1188           return TCL_ERROR;
  1187   1189         }
         1190  +      sqlite3_vfs_register(sqlite3_vfs_find(zVfs), 1);
  1188   1191         break;
  1189   1192       };
  1190   1193   
  1191   1194       case VL_REGISTER: {
  1192   1195         char *zDb;
  1193   1196         if( objc!=3 ){
  1194   1197           Tcl_WrongNumArgs(interp, 2, objv, "DB");

Changes to tool/mksqlite3c.tcl.

   399    399      fts3_icu.c
   400    400      sqlite3rbu.c
   401    401      dbstat.c
   402    402      dbpage.c
   403    403      sqlite3session.c
   404    404      fts5.c
   405    405      stmt.c
          406  +
          407  +   test_osinst.c
   406    408   } {
   407    409     copy_file tsrc/$file
   408    410   }
   409    411   
   410    412   # Synthesize an alternative sqlite3_sourceid() implementation that
   411    413   # that tries to detects changes in the amalgamation source text
   412    414   # and modify returns a modified source-id if changes are detected.