/ Check-in [599b4df4]
Login

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

Overview
Comment:Add the --vdbe-debug command-line option to dbfuzz2.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 599b4df43c64ce295517c804b6bb4c3ab77d77e0ba585dc0657274f55489a3b1
User & Date: drh 2019-01-11 14:38:47
Context
2019-01-11
14:46
Fix PRAGMA integrity_check so that it does not cancel the PRAGMA vdbe_debug setting. check-in: aaa3a19f user: drh tags: trunk
14:38
Add the --vdbe-debug command-line option to dbfuzz2. check-in: 599b4df4 user: drh tags: trunk
14:22
Add the "dbfuzz2" target to main.mk. Remove an unused local variable from dbfuzz2.c. check-in: 05c7609c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to test/dbfuzz2.c.

    59     59     "REINDEX;",
    60     60     "DROP TABLE t3;",
    61     61     "VACUUM;",
    62     62   };
    63     63   
    64     64   /* Output verbosity level.  0 means complete silence */
    65     65   int eVerbosity = 0;
           66  +
           67  +/* True to activate PRAGMA vdbe_debug=on */
           68  +static int bVdbeDebug = 0;
    66     69   
    67     70   /* libFuzzer invokes this routine with fuzzed database files (in aData).
    68     71   ** This routine run SQLite against the malformed database to see if it
    69     72   ** can provoke a failure or malfunction.
    70     73   */
    71     74   int LLVMFuzzerTestOneInput(const uint8_t *aData, size_t nByte){
    72     75     unsigned char *a;
................................................................................
    83     86     if( rc ) return 1;
    84     87     a = sqlite3_malloc64(nByte+1);
    85     88     if( a==0 ) return 1;
    86     89     memcpy(a, aData, nByte);
    87     90     sqlite3_deserialize(db, "main", a, nByte, nByte,
    88     91           SQLITE_DESERIALIZE_RESIZEABLE |
    89     92           SQLITE_DESERIALIZE_FREEONCLOSE);
           93  +  if( bVdbeDebug ){
           94  +    sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0);
           95  +  }
    90     96     for(i=0; i<sizeof(azSql)/sizeof(azSql[0]); i++){
    91     97       if( eVerbosity>=1 ){
    92     98         printf("%s\n", azSql[i]);
    93     99         fflush(stdout);
    94    100       }
    95    101       sqlite3_exec(db, azSql[i], 0, 0, 0);
    96    102     }
................................................................................
   104    110       sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0);
   105    111       fprintf(stderr,"Memory leak: %lld bytes in %d allocations\n",
   106    112               sqlite3_memory_used(), nAlloc);
   107    113       exit(1);
   108    114     }
   109    115     return 0;
   110    116   }
          117  +
          118  +/*
          119  +** Return the number of "v" characters in a string.  Return 0 if there
          120  +** are any characters in the string other than "v".
          121  +*/
          122  +static int numberOfVChar(const char *z){
          123  +  int N = 0;
          124  +  while( z[0] && z[0]=='v' ){
          125  +    z++;
          126  +    N++;
          127  +  }
          128  +  return z[0]==0 ? N : 0;
          129  +}
   111    130   
   112    131   /* libFuzzer invokes this routine once when the executable starts, to
   113    132   ** process the command-line arguments.
   114    133   */
   115    134   int LLVMFuzzerInitialize(int *pArgc, char ***pArgv){
   116         -  int i, j;
          135  +  int i, j, n;
   117    136     int argc = *pArgc;
   118    137     char **newArgv;
   119    138     char **argv = *pArgv;
   120    139     newArgv = malloc( sizeof(char*)*(argc+1) );
   121    140     if( newArgv==0 ) return 0;
   122    141     newArgv[0] = argv[0];
   123    142     for(i=j=1; i<argc; i++){
   124    143       char *z = argv[i];
   125    144       if( z[0]=='-' ){
   126    145         z++;
   127    146         if( z[0]=='-' ) z++;
   128         -      if( strcmp(z,"v")==0 ){
   129         -        eVerbosity++;
          147  +      if( z[0]=='v' && (n = numberOfVChar(z))>0 ){
          148  +        eVerbosity += n;
          149  +        continue;
          150  +      }
          151  +      if( strcmp(z,"vdbe-debug")==0 ){
          152  +        bVdbeDebug = 1;
   130    153           continue;
   131    154         }
   132    155       }
   133    156       newArgv[j++] = argv[i];
   134    157     }
   135    158     newArgv[j] = 0;
   136    159     *pArgv = newArgv;