]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Further enhancements to the showdb utility: A page number followed by "b"
authordrh <drh@noemail.net>
Mon, 26 Apr 2010 16:47:12 +0000 (16:47 +0000)
committerdrh <drh@noemail.net>
Mon, 26 Apr 2010 16:47:12 +0000 (16:47 +0000)
causes a btree decoding to occur on the page.

FossilOrigin-Name: 2ff824e58ce8b8f605c809ac960dcbfc51c30e30

manifest
manifest.uuid
tool/showdb.c

index 43c5db3d5b83f7be8d203debdc6a4af758ca78c5..5120eee05646c8e076372626e8ea21b4b753d224 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Enhancements\sto\sthe\sshowdb.c\sutility\sprogram.\s\sAutomatically\sdetect\sthe\npage\ssize\sand\sadjust\sthe\sdisplay\saccordingly.\s\sAdd\sthe\s"dbheader"\sdisplay\noption.
-D 2010-04-26T15:44:07
+C Further\senhancements\sto\sthe\sshowdb\sutility:\s\sA\spage\snumber\sfollowed\sby\s"b"\ncauses\sa\sbtree\sdecoding\sto\soccur\son\sthe\spage.
+D 2010-04-26T16:47:13
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -790,7 +790,7 @@ F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a
 F tool/shell1.test ef08a3e738b9fee4fc228920956950bc35db0575
 F tool/shell2.test 8f51f61c13b88618e71c17439fe0847c2421c5d1
 F tool/shell3.test ff663e83100670a295d473515c12beb8103a78b6
-F tool/showdb.c f36a0d6250cd66da80c70c5f68db504b6004ffae
+F tool/showdb.c 4ab96e7f501e5423d5b7ac34504afd3834dbf3ce
 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
 F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
@@ -801,14 +801,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 064d3ddd6199b7b049b1706974e4295f78fb5ab9
-R 8b381715211fe751bde39cc29f2ff9cd
+P 23eb408b5d08b89b41aaf245a7be8e235f30af8a
+R 933a436d34fb2f67d252b6f2eef7208a
 U drh
-Z 764a1f25e347ea0d4e5e531b573f483f
+Z f61ced08bbb9a853a64647c8b442a2d5
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFL1bTKoxKgR168RlERAo5cAJ9Eb+lGq+Qu8+YZ7K+hoPtgssOPdwCfc3aA
-gSmF+BvN/QcbZjim662ior8=
-=k+Sx
+iD8DBQFL1cOUoxKgR168RlERAvg3AJsFJVG93QKIMPjRrMQew07/kDOloACgjMdv
+7XmPQv5MjnYy+cdiQdmjRsk=
+=SfZz
 -----END PGP SIGNATURE-----
index 5f6a0740c2566dbc9c2d2f6eb123d89ca3e449d3..cf2caab397e69ed15dc55156cf61785f5bb17a8d 100644 (file)
@@ -1 +1 @@
-23eb408b5d08b89b41aaf245a7be8e235f30af8a
\ No newline at end of file
+2ff824e58ce8b8f605c809ac960dcbfc51c30e30
\ No newline at end of file
index d8f9d79d815c4a15bd501189c77cc265f7e1fd60..ac537682efe74acc21a30130f1ff210029fe00f5 100644 (file)
@@ -23,10 +23,10 @@ typedef long long int i64;      /* Datatype for 64-bit integers */
 ** Convert the var-int format into i64.  Return the number of bytes
 ** in the var-int.  Write the var-int value into *pVal.
 */
-static int decodeVarint(const char *z, i64 *pVal){
+static int decodeVarint(const unsigned char *z, i64 *pVal){
   i64 v = 0;
-  int i = 0;
-  while( i<8 ){
+  int i;
+  for(i=0; i<8; i++){
     v = (v<<7) + (z[i]&0x7f);
     if( (z[i]&0x80)==0 ){ *pVal = v; return i+1; }
   }
@@ -138,13 +138,13 @@ static print_decode_line(
     i += strlen(&zBuf[i]);
   }
   sprintf(&zBuf[i], "   %9d", val);
-  printf(" %s  %s\n", zBuf, zMsg);
+  printf("%s  %s\n", zBuf, zMsg);
 }
 
 /*
 ** Decode the database header.
 */
-static print_db_header(void){
+static void print_db_header(void){
   unsigned char *aData;
   aData = print_byte_range(0, 100, 0);
   printf("Decoded:\n");
@@ -173,6 +173,79 @@ static print_db_header(void){
   print_decode_line(aData, 96, 4, "meta[14]");
 }
 
+/*
+** Create a description for a single cell.
+*/
+static int describeCell(unsigned char cType, unsigned char *a, char **pzDesc){
+  int i;
+  int nDesc = 0;
+  int n = 0;
+  int leftChild;
+  i64 nPayload;
+  i64 rowid;
+  static char zDesc[100];
+  i = 0;
+  if( cType<=5 ){
+    leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
+    a += 4;
+    n += 4;
+    sprintf(zDesc, "left-child: %d ", leftChild);
+    nDesc = strlen(zDesc);
+  }
+  if( cType!=5 ){
+    i = decodeVarint(a, &nPayload);
+    a += i;
+    n += i;
+    sprintf(&zDesc[nDesc], "sz: %lld ", nPayload);
+    nDesc += strlen(&zDesc[nDesc]);
+  }
+  if( cType==5 || cType==13 ){
+    i = decodeVarint(a, &rowid);
+    a += i;
+    n += i;
+    sprintf(&zDesc[nDesc], "rowid: %lld ", rowid);
+    nDesc += strlen(&zDesc[nDesc]);
+  }
+  *pzDesc = zDesc;
+  return n;
+}
+
+/*
+** Decode a btree page
+*/
+static void decode_btree_page(unsigned char *a, int pgno, int hdrSize){
+  const char *zType = "unknown";
+  int nCell;
+  int i;
+  int iCellPtr;
+  switch( a[0] ){
+    case 2:  zType = "index interior node";  break;
+    case 5:  zType = "table interior node";  break;
+    case 10: zType = "index leaf";           break;
+    case 13: zType = "table leaf";           break;
+  }
+  printf("Decode of btree page %d:\n", pgno);
+  print_decode_line(a, 0, 1, zType);
+  print_decode_line(a, 1, 2, "Offset to first freeblock");
+  print_decode_line(a, 3, 2, "Number of cells on this page");
+  nCell = a[3]*256 + a[4];
+  print_decode_line(a, 5, 2, "Offset to cell content area");
+  print_decode_line(a, 7, 1, "Fragmented byte count");
+  if( a[0]==2 || a[0]==5 ){
+    print_decode_line(a, 8, 4, "Right child");
+    iCellPtr = 12;
+  }else{
+    iCellPtr = 8;
+  }
+  for(i=0; i<nCell; i++){
+    int cofst = iCellPtr + i*2;
+    char *zDesc;
+    cofst = a[cofst]*256 + a[cofst+1];
+    describeCell(a[0], &a[cofst-hdrSize], &zDesc);
+    printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);
+  }
+}
+
 int main(int argc, char **argv){
   struct stat sbuf;
   unsigned char zPgSz[2];
@@ -216,6 +289,21 @@ int main(int argc, char **argv){
         iEnd = mxPage;
       }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){
         iEnd = strtol(&zLeft[2], 0, 0);
+      }else if( zLeft && zLeft[0]=='b' ){
+        int ofst, nByte, hdrSize;
+        unsigned char *a;
+        if( iStart==1 ){
+          ofst = hdrSize = 100;
+          nByte = pagesize-100;
+        }else{
+          hdrSize = 0;
+          ofst = (iStart-1)*pagesize;
+          nByte = pagesize;
+        }
+        a = getContent(ofst, nByte);
+        decode_btree_page(a, iStart, hdrSize);
+        free(a);
+        continue;
       }else{
         iEnd = iStart;
       }