| Index: third_party/sqlite/src/src/test_vfstrace.c
|
| diff --git a/third_party/sqlite/src/src/test_vfstrace.c b/third_party/sqlite/src/src/test_vfstrace.c
|
| index 073eab631b9c0a7acfd8798856c796f153d459cd..d0bc29f0c3ceb6dd60c7b4307480f5e77c3c344f 100644
|
| --- a/third_party/sqlite/src/src/test_vfstrace.c
|
| +++ b/third_party/sqlite/src/src/test_vfstrace.c
|
| @@ -12,6 +12,100 @@
|
| **
|
| ** This file contains code implements a VFS shim that writes diagnostic
|
| ** output for each VFS call, similar to "strace".
|
| +**
|
| +** USAGE:
|
| +**
|
| +** This source file exports a single symbol which is the name of a
|
| +** function:
|
| +**
|
| +** int vfstrace_register(
|
| +** const char *zTraceName, // Name of the newly constructed VFS
|
| +** const char *zOldVfsName, // Name of the underlying VFS
|
| +** int (*xOut)(const char*,void*), // Output routine. ex: fputs
|
| +** void *pOutArg, // 2nd argument to xOut. ex: stderr
|
| +** int makeDefault // Make the new VFS the default
|
| +** );
|
| +**
|
| +** Applications that want to trace their VFS usage must provide a callback
|
| +** function with this prototype:
|
| +**
|
| +** int traceOutput(const char *zMessage, void *pAppData);
|
| +**
|
| +** This function will "output" the trace messages, where "output" can
|
| +** mean different things to different applications. The traceOutput function
|
| +** for the command-line shell (see shell.c) is "fputs" from the standard
|
| +** library, which means that all trace output is written on the stream
|
| +** specified by the second argument. In the case of the command-line shell
|
| +** the second argument is stderr. Other applications might choose to output
|
| +** trace information to a file, over a socket, or write it into a buffer.
|
| +**
|
| +** The vfstrace_register() function creates a new "shim" VFS named by
|
| +** the zTraceName parameter. A "shim" VFS is an SQLite backend that does
|
| +** not really perform the duties of a true backend, but simply filters or
|
| +** interprets VFS calls before passing them off to another VFS which does
|
| +** the actual work. In this case the other VFS - the one that does the
|
| +** real work - is identified by the second parameter, zOldVfsName. If
|
| +** the 2nd parameter is NULL then the default VFS is used. The common
|
| +** case is for the 2nd parameter to be NULL.
|
| +**
|
| +** The third and fourth parameters are the pointer to the output function
|
| +** and the second argument to the output function. For the SQLite
|
| +** command-line shell, when the -vfstrace option is used, these parameters
|
| +** are fputs and stderr, respectively.
|
| +**
|
| +** The fifth argument is true (non-zero) to cause the newly created VFS
|
| +** to become the default VFS. The common case is for the fifth parameter
|
| +** to be true.
|
| +**
|
| +** The call to vfstrace_register() simply creates the shim VFS that does
|
| +** tracing. The application must also arrange to use the new VFS for
|
| +** all database connections that are created and for which tracing is
|
| +** desired. This can be done by specifying the trace VFS using URI filename
|
| +** notation, or by specifying the trace VFS as the 4th parameter to
|
| +** sqlite3_open_v2() or by making the trace VFS be the default (by setting
|
| +** the 5th parameter of vfstrace_register() to 1).
|
| +**
|
| +**
|
| +** ENABLING VFSTRACE IN A COMMAND-LINE SHELL
|
| +**
|
| +** The SQLite command line shell implemented by the shell.c source file
|
| +** can be used with this module. To compile in -vfstrace support, first
|
| +** gather this file (test_vfstrace.c), the shell source file (shell.c),
|
| +** and the SQLite amalgamation source files (sqlite3.c, sqlite3.h) into
|
| +** the working directory. Then compile using a command like the following:
|
| +**
|
| +** gcc -o sqlite3 -Os -I. -DSQLITE_ENABLE_VFSTRACE \
|
| +** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE \
|
| +** -DHAVE_READLINE -DHAVE_USLEEP=1 \
|
| +** shell.c test_vfstrace.c sqlite3.c -ldl -lreadline -lncurses
|
| +**
|
| +** The gcc command above works on Linux and provides (in addition to the
|
| +** -vfstrace option) support for FTS3 and FTS4, RTREE, and command-line
|
| +** editing using the readline library. The command-line shell does not
|
| +** use threads so we added -DSQLITE_THREADSAFE=0 just to make the code
|
| +** run a little faster. For compiling on a Mac, you'll probably need
|
| +** to omit the -DHAVE_READLINE, the -lreadline, and the -lncurses options.
|
| +** The compilation could be simplified to just this:
|
| +**
|
| +** gcc -DSQLITE_ENABLE_VFSTRACE \
|
| +** shell.c test_vfstrace.c sqlite3.c -ldl -lpthread
|
| +**
|
| +** In this second example, all unnecessary options have been removed
|
| +** Note that since the code is now threadsafe, we had to add the -lpthread
|
| +** option to pull in the pthreads library.
|
| +**
|
| +** To cross-compile for windows using MinGW, a command like this might
|
| +** work:
|
| +**
|
| +** /opt/mingw/bin/i386-mingw32msvc-gcc -o sqlite3.exe -Os -I \
|
| +** -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_VFSTRACE \
|
| +** shell.c test_vfstrace.c sqlite3.c
|
| +**
|
| +** Similar compiler commands will work on different systems. The key
|
| +** invariants are (1) you must have -DSQLITE_ENABLE_VFSTRACE so that
|
| +** the shell.c source file will know to include the -vfstrace command-line
|
| +** option and (2) you must compile and link the three source files
|
| +** shell,c, test_vfstrace.c, and sqlite3.c.
|
| */
|
| #include <stdlib.h>
|
| #include <string.h>
|
| @@ -164,6 +258,11 @@ static void vfstrace_print_errcode(
|
| case SQLITE_IOERR_SHMOPEN: zVal = "SQLITE_IOERR_SHMOPEN"; break;
|
| case SQLITE_IOERR_SHMSIZE: zVal = "SQLITE_IOERR_SHMSIZE"; break;
|
| case SQLITE_IOERR_SHMLOCK: zVal = "SQLITE_IOERR_SHMLOCK"; break;
|
| + case SQLITE_IOERR_SHMMAP: zVal = "SQLITE_IOERR_SHMMAP"; break;
|
| + case SQLITE_IOERR_SEEK: zVal = "SQLITE_IOERR_SEEK"; break;
|
| + case SQLITE_IOERR_GETTEMPPATH: zVal = "SQLITE_IOERR_GETTEMPPATH"; break;
|
| + case SQLITE_IOERR_CONVPATH: zVal = "SQLITE_IOERR_CONVPATH"; break;
|
| + case SQLITE_READONLY_DBMOVED: zVal = "SQLITE_READONLY_DBMOVED"; break;
|
| case SQLITE_LOCKED_SHAREDCACHE: zVal = "SQLITE_LOCKED_SHAREDCACHE"; break;
|
| case SQLITE_BUSY_RECOVERY: zVal = "SQLITE_BUSY_RECOVERY"; break;
|
| case SQLITE_CANTOPEN_NOTEMPDIR: zVal = "SQLITE_CANTOPEN_NOTEMPDIR"; break;
|
| @@ -377,7 +476,18 @@ static int vfstraceFileControl(sqlite3_file *pFile, int op, void *pArg){
|
| }
|
| case SQLITE_FCNTL_FILE_POINTER: zOp = "FILE_POINTER"; break;
|
| case SQLITE_FCNTL_SYNC_OMITTED: zOp = "SYNC_OMITTED"; break;
|
| + case SQLITE_FCNTL_WIN32_AV_RETRY: zOp = "WIN32_AV_RETRY"; break;
|
| + case SQLITE_FCNTL_PERSIST_WAL: zOp = "PERSIST_WAL"; break;
|
| + case SQLITE_FCNTL_OVERWRITE: zOp = "OVERWRITE"; break;
|
| + case SQLITE_FCNTL_VFSNAME: zOp = "VFSNAME"; break;
|
| + case SQLITE_FCNTL_TEMPFILENAME: zOp = "TEMPFILENAME"; break;
|
| case 0xca093fa0: zOp = "DB_UNCHANGED"; break;
|
| + case SQLITE_FCNTL_PRAGMA: {
|
| + const char *const* a = (const char*const*)pArg;
|
| + sqlite3_snprintf(sizeof(zBuf), zBuf, "PRAGMA,[%s,%s]",a[1],a[2]);
|
| + zOp = zBuf;
|
| + break;
|
| + }
|
| default: {
|
| sqlite3_snprintf(sizeof zBuf, zBuf, "%d", op);
|
| zOp = zBuf;
|
| @@ -388,6 +498,15 @@ static int vfstraceFileControl(sqlite3_file *pFile, int op, void *pArg){
|
| pInfo->zVfsName, p->zFName, zOp);
|
| rc = p->pReal->pMethods->xFileControl(p->pReal, op, pArg);
|
| vfstrace_print_errcode(pInfo, " -> %s\n", rc);
|
| + if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){
|
| + *(char**)pArg = sqlite3_mprintf("vfstrace.%s/%z",
|
| + pInfo->zVfsName, *(char**)pArg);
|
| + }
|
| + if( (op==SQLITE_FCNTL_PRAGMA || op==SQLITE_FCNTL_TEMPFILENAME)
|
| + && rc==SQLITE_OK && *(char**)pArg ){
|
| + vfstrace_printf(pInfo, "%s.xFileControl(%s,%s) returns %s",
|
| + pInfo->zVfsName, p->zFName, zOp, *(char**)pArg);
|
| + }
|
| return rc;
|
| }
|
|
|
| @@ -559,7 +678,7 @@ static int vfstraceAccess(
|
| vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
|
| sqlite3_vfs *pRoot = pInfo->pRootVfs;
|
| int rc;
|
| - vfstrace_printf(pInfo, "%s.xDelete(\"%s\",%d)",
|
| + vfstrace_printf(pInfo, "%s.xAccess(\"%s\",%d)",
|
| pInfo->zVfsName, zPath, flags);
|
| rc = pRoot->xAccess(pRoot, zPath, flags, pResOut);
|
| vfstrace_print_errcode(pInfo, " -> %s", rc);
|
|
|