/ Check-in [e9023a4e]
Login

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

Overview
Comment:Enhancements to the "showdb" debugging tool. Add the ability to display the content of a cell.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9023a4e1edd552a81dcb2dcd5a996edfa167709
User & Date: drh 2011-01-05 21:20:52
Context
2011-01-05
21:46
Fix a bug in the showdb utility: the serial types for BLOB and TEXT where reversed. check-in: 65a13faf user: drh tags: trunk
21:20
Enhancements to the "showdb" debugging tool. Add the ability to display the content of a cell. check-in: e9023a4e user: drh tags: trunk
13:43
Increment the version number to 3.7.5. check-in: 9ec3896e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/showdb.c.

   176    176     print_decode_line(aData, 80, 4, "meta[10]");
   177    177     print_decode_line(aData, 84, 4, "meta[11]");
   178    178     print_decode_line(aData, 88, 4, "meta[12]");
   179    179     print_decode_line(aData, 92, 4, "Change counter for version number");
   180    180     print_decode_line(aData, 96, 4, "SQLite version number");
   181    181   }
   182    182   
          183  +/*
          184  +** Describe cell content.
          185  +*/
          186  +static int describeContent(
          187  +  unsigned char *a,
          188  +  char *zDesc
          189  +){
          190  +  int nDesc = 0;
          191  +  int n, i, j;
          192  +  i64 x, v;
          193  +  const unsigned char *pData;
          194  +  char sep = ' ';
          195  +
          196  +  n = decodeVarint(a, &x);
          197  +  pData = &a[x];
          198  +  a += n;
          199  +  i = x - n;
          200  +  while( i>0 ){
          201  +    n = decodeVarint(a, &x);
          202  +    a += n;
          203  +    i -= n;
          204  +    zDesc[0] = sep;
          205  +    sep = ',';
          206  +    nDesc++;
          207  +    zDesc++;
          208  +    if( x==0 ){
          209  +      sprintf(zDesc, "null");
          210  +    }else if( x>=1 && x<=6 ){
          211  +      v = (signed char)pData[0];
          212  +      pData++;
          213  +      switch( x ){
          214  +        case 6:  v = (v<<16) + (pData[0]<<8) + pData[1];  pData += 2;
          215  +        case 5:  v = (v<<16) + (pData[0]<<8) + pData[1];  pData += 2;
          216  +        case 4:  v = (v<<8) + pData[0];  pData++;
          217  +        case 3:  v = (v<<8) + pData[0];  pData++;
          218  +        case 2:  v = (v<<8) + pData[0];  pData++;
          219  +      }
          220  +      sprintf(zDesc, "%lld", v);
          221  +    }else if( x==7 ){
          222  +      sprintf(zDesc, "real");
          223  +      pData += 8;
          224  +    }else if( x==8 ){
          225  +      sprintf(zDesc, "0");
          226  +    }else if( x==9 ){
          227  +      sprintf(zDesc, "1");
          228  +    }else if( x>=12 ){
          229  +      int size = (x-12)/2;
          230  +      if( x&1 ){
          231  +        sprintf(zDesc, "blob(%d)", size);
          232  +      }else{
          233  +        sprintf(zDesc, "text(%d)", size);
          234  +      }
          235  +      pData += size;
          236  +    }
          237  +    j = strlen(zDesc);
          238  +    zDesc += j;
          239  +    nDesc += j;
          240  +  }
          241  +  return nDesc;
          242  +}
          243  +  
          244  +
   183    245   /*
   184    246   ** Create a description for a single cell.
   185    247   */
   186         -static int describeCell(unsigned char cType, unsigned char *a, char **pzDesc){
          248  +static int describeCell(
          249  +  unsigned char cType,    /* Page type */
          250  +  unsigned char *a,       /* Cell content */
          251  +  int showCellContent,    /* Show cell content if true */
          252  +  char **pzDesc           /* Store description here */
          253  +){
   187    254     int i;
   188    255     int nDesc = 0;
   189    256     int n = 0;
   190    257     int leftChild;
   191    258     i64 nPayload;
   192    259     i64 rowid;
   193         -  static char zDesc[100];
          260  +  int nLocal;
          261  +  static char zDesc[1000];
   194    262     i = 0;
   195    263     if( cType<=5 ){
   196    264       leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
   197    265       a += 4;
   198    266       n += 4;
   199         -    sprintf(zDesc, "left-child: %d ", leftChild);
          267  +    sprintf(zDesc, "lx: %d ", leftChild);
   200    268       nDesc = strlen(zDesc);
   201    269     }
   202    270     if( cType!=5 ){
   203    271       i = decodeVarint(a, &nPayload);
   204    272       a += i;
   205    273       n += i;
   206         -    sprintf(&zDesc[nDesc], "sz: %lld ", nPayload);
          274  +    sprintf(&zDesc[nDesc], "n: %lld ", nPayload);
   207    275       nDesc += strlen(&zDesc[nDesc]);
   208    276     }
   209    277     if( cType==5 || cType==13 ){
   210    278       i = decodeVarint(a, &rowid);
   211    279       a += i;
   212    280       n += i;
   213         -    sprintf(&zDesc[nDesc], "rowid: %lld ", rowid);
          281  +    sprintf(&zDesc[nDesc], "r: %lld ", rowid);
   214    282       nDesc += strlen(&zDesc[nDesc]);
   215    283     }
          284  +  if( showCellContent && cType!=5 ){
          285  +    nDesc += describeContent(a, &zDesc[nDesc]);
          286  +  }
   216    287     *pzDesc = zDesc;
   217    288     return n;
   218    289   }
   219    290   
   220    291   /*
   221    292   ** Decode a btree page
   222    293   */
   223         -static void decode_btree_page(unsigned char *a, int pgno, int hdrSize){
          294  +static void decode_btree_page(
          295  +  unsigned char *a,   /* Page content */
          296  +  int pgno,           /* Page number */
          297  +  int hdrSize,        /* Size of the page header.  0 or 100 */
          298  +  char *zArgs         /* Flags to control formatting */
          299  +){
   224    300     const char *zType = "unknown";
   225    301     int nCell;
   226    302     int i;
   227    303     int iCellPtr;
          304  +  int showCellContent = 0;
   228    305     switch( a[0] ){
   229    306       case 2:  zType = "index interior node";  break;
   230    307       case 5:  zType = "table interior node";  break;
   231    308       case 10: zType = "index leaf";           break;
   232    309       case 13: zType = "table leaf";           break;
          310  +  }
          311  +  while( zArgs[0] ){
          312  +    switch( zArgs[0] ){
          313  +      case 'c': showCellContent = 1;  break;
          314  +    }
          315  +    zArgs++;
   233    316     }
   234    317     printf("Decode of btree page %d:\n", pgno);
   235    318     print_decode_line(a, 0, 1, zType);
   236    319     print_decode_line(a, 1, 2, "Offset to first freeblock");
   237    320     print_decode_line(a, 3, 2, "Number of cells on this page");
   238    321     nCell = a[3]*256 + a[4];
   239    322     print_decode_line(a, 5, 2, "Offset to cell content area");
   240    323     print_decode_line(a, 7, 1, "Fragmented byte count");
          324  +  if( nCell>0 ){
          325  +    printf(" key: lx=left-child n=payload-size r=rowid\n");
          326  +  }
   241    327     if( a[0]==2 || a[0]==5 ){
   242    328       print_decode_line(a, 8, 4, "Right child");
   243    329       iCellPtr = 12;
   244    330     }else{
   245    331       iCellPtr = 8;
   246    332     }
   247    333     for(i=0; i<nCell; i++){
   248    334       int cofst = iCellPtr + i*2;
   249    335       char *zDesc;
   250    336       cofst = a[cofst]*256 + a[cofst+1];
   251         -    describeCell(a[0], &a[cofst-hdrSize], &zDesc);
          337  +    describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc);
   252    338       printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);
   253    339     }
   254    340   }
   255    341   
   256    342   /*
   257    343   ** Decode a freelist trunk page.
   258    344   */
................................................................................
   357    443             nByte = pagesize-100;
   358    444           }else{
   359    445             hdrSize = 0;
   360    446             ofst = (iStart-1)*pagesize;
   361    447             nByte = pagesize;
   362    448           }
   363    449           a = getContent(ofst, nByte);
   364         -        decode_btree_page(a, iStart, hdrSize);
          450  +        decode_btree_page(a, iStart, hdrSize, &zLeft[1]);
   365    451           free(a);
   366    452           continue;
   367    453         }else if( zLeft && zLeft[0]=='t' ){
   368    454           unsigned char *a;
   369    455           int detail = 0;
   370    456           int recursive = 0;
   371    457           int i;