From: drh Date: Mon, 26 Apr 2010 16:47:12 +0000 (+0000) Subject: Further enhancements to the showdb utility: A page number followed by "b" X-Git-Tag: version-3.7.2~461 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ecc14761ec35343cd93d41c53d406227f44e38c;p=thirdparty%2Fsqlite.git Further enhancements to the showdb utility: A page number followed by "b" causes a btree decoding to occur on the page. FossilOrigin-Name: 2ff824e58ce8b8f605c809ac960dcbfc51c30e30 --- diff --git a/manifest b/manifest index 43c5db3d5b..5120eee056 100644 --- 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----- diff --git a/manifest.uuid b/manifest.uuid index 5f6a0740c2..cf2caab397 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -23eb408b5d08b89b41aaf245a7be8e235f30af8a \ No newline at end of file +2ff824e58ce8b8f605c809ac960dcbfc51c30e30 \ No newline at end of file diff --git a/tool/showdb.c b/tool/showdb.c index d8f9d79d81..ac537682ef 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -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