Add the showshm utility program for printing out the shm header in a

human-readable format.

FossilOrigin-Name: f6304fd142c998aba44f02c6018223af2630671b4791d750b70a59ab1adb8d6d
This commit is contained in:
drh 2017-10-30 23:25:06 +00:00
parent 07dae088b9
commit 666fb6914d
6 changed files with 177 additions and 9 deletions

View File

@ -1203,6 +1203,9 @@ showjournal$(TEXE): $(TOP)/tool/showjournal.c sqlite3.lo
showwal$(TEXE): $(TOP)/tool/showwal.c sqlite3.lo
$(LTLINK) -o $@ $(TOP)/tool/showwal.c sqlite3.lo $(TLIBS)
showshm$(TEXE): $(TOP)/tool/showshm.c
$(LTLINK) -o $@ $(TOP)/tool/showshm.c
changeset$(TEXE): $(TOP)/ext/session/changeset.c sqlite3.lo
$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)

View File

@ -2224,6 +2224,9 @@ showwal.exe: $(TOP)\tool\showwal.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
$(TOP)\tool\showwal.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
showshm.exe: $(TOP)\tool\showshm.c
$(LTLINK) $(NO_WARN) $(TOP)\tool\showshm.c /link $(LDFLAGS) $(LTLINKOPTS)
changeset.exe: $(TOP)\ext\session\changeset.c $(SQLITE3C) $(SQLITE3H)
$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
-DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 \

View File

@ -908,6 +908,9 @@ showwal$(EXE): $(TOP)/tool/showwal.c sqlite3.o
$(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o showwal$(EXE) \
$(TOP)/tool/showwal.c sqlite3.o $(THREADLIB)
showshm$(EXE): $(TOP)/tool/showshm.c
$(TCC) -o showshm$(EXE) $(TOP)/tool/showshm.c
changeset$(EXE): $(TOP)/ext/session/changeset.c sqlite3.o
$(TCC) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -o changeset$(EXE) \
$(TOP)/ext/session/changeset.c sqlite3.o $(THREADLIB)

View File

@ -1,8 +1,8 @@
C Clarify\ssome\scomments\sdescribing\sthe\sWAL\sindex\sfile.\s\sNo\schanges\sto\scode.
D 2017-10-30T20:44:36.285
F Makefile.in e016061b23e60ac9ec27c65cb577292b6bde0307ca55abd874ab3487b3b1beb2
C Add\sthe\sshowshm\sutility\sprogram\sfor\sprinting\sout\sthe\sshm\sheader\sin\sa\nhuman-readable\sformat.
D 2017-10-30T23:25:06.424
F Makefile.in 5fb6750646b432cb72d1aa91f9a7888eb488b3de145024cc48ec9815dc106fbd
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 37740aba9c4bb359c627eadccf1cfd7be4f5f847078723777ea7763969e533b1
F Makefile.msc 74ccbe1c06de753a6a0fa0fad4e7f8bea37f1ba4303448300bda3427efb64f2d
F README.md f5c87359573c4d255425e588a56554b50fdcc2afba4e017a2e02a43701456afd
F VERSION 0c10cdfed866fdd2d80434f64f042c3330f1daaed12e54287beb104f04b3faaf
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
@ -386,7 +386,7 @@ F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F main.mk a39528d993afc1f0c0aebde2e3623ab4171d3bba484eea1e5241615c706c9ce8
F main.mk a6e3fa3c4d145189a67ad89e3f0d6541e8c085f5c34a21df0b1c870eb3aeb6ce
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@ -1622,6 +1622,7 @@ F tool/run-speed-test.sh f95d19fd669b68c4c38b6b475242841d47c66076
F tool/showdb.c e6bc9dba233bf1b57ca0a525a2bba762db4e223de84990739db3f09c46151b1e
F tool/showjournal.c 5bad7ae8784a43d2b270d953060423b8bd480818
F tool/showlocks.c 9920bcc64f58378ff1118caead34147201f48c68
F tool/showshm.c a0ab6ec32dd1f11218ca2a4018f8fb875b59414801ab8ceed8b2e69b7b45a809
F tool/showstat4.c 0682ebea7abf4d3657f53c4a243f2e7eab48eab344ed36a94bb75dcd19a5c2a1
F tool/showwal.c ad9d768f96ca6199ad3a8c9562d679680bd032dd01204ea3e5ea6fb931d81847
F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
@ -1666,7 +1667,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 37284d4e8f501a37c582aa899419a3dfe0932e2a8e2ef2fdf59addd1d3cdacb4
R b73d22fe388dfec64db639a4eb4f982f
P 3be3aad9ecbe33060cfa9c6059b9206ed221d1fd72a69c355a9387f9f4e075e7
R 5511878351634578cf57017f9253148a
U drh
Z b8d196e6ebc579e3254aa8271770e0e4
Z 5f57a6784d89256cd72e7dad10ab878c

View File

@ -1 +1 @@
3be3aad9ecbe33060cfa9c6059b9206ed221d1fd72a69c355a9387f9f4e075e7
f6304fd142c998aba44f02c6018223af2630671b4791d750b70a59ab1adb8d6d

158
tool/showshm.c Normal file
View File

@ -0,0 +1,158 @@
/*
** A utility for printing content from the wal-index or "shm" file.
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#define ISDIGIT(X) isdigit((unsigned char)(X))
#define ISPRINT(X) isprint((unsigned char)(X))
#if !defined(_MSC_VER)
#include <unistd.h>
#include <sys/types.h>
#else
#include <io.h>
#endif
#include <stdlib.h>
#include <string.h>
static int fd = -1; /* The open SHM file */
/* Report an out-of-memory error and die.
*/
static void out_of_memory(void){
fprintf(stderr,"Out of memory...\n");
exit(1);
}
/*
** Read content from the file.
**
** Space to hold the content is obtained from malloc() and needs to be
** freed by the caller.
*/
static unsigned char *getContent(int ofst, int nByte){
unsigned char *aData;
aData = malloc(nByte);
if( aData==0 ) out_of_memory();
lseek(fd, ofst, SEEK_SET);
read(fd, aData, nByte);
return aData;
}
/*
** Flags values
*/
#define FG_HEX 1 /* Show as hex */
#define FG_NBO 2 /* Native byte order */
#define FG_PGSZ 4 /* Show as page-size */
/* Print a line of decode output showing a 4-byte integer.
*/
static void print_decode_line(
unsigned char *aData, /* Content being decoded */
int ofst, int nByte, /* Start and size of decode */
unsigned flg, /* Display flags */
const char *zMsg /* Message to append */
){
int i, j;
int val = aData[ofst];
char zBuf[100];
sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]);
i = (int)strlen(zBuf);
for(j=1; j<4; j++){
if( j>=nByte ){
sprintf(&zBuf[i], " ");
}else{
sprintf(&zBuf[i], " %02x", aData[ofst+j]);
val = val*256 + aData[ofst+j];
}
i += (int)strlen(&zBuf[i]);
}
if( nByte==8 ){
for(j=4; j<8; j++){
sprintf(&zBuf[i], " %02x", aData[ofst+j]);
i += (int)strlen(&zBuf[i]);
}
}
if( flg & FG_NBO ){
assert( nByte==4 );
memcpy(&val, aData+ofst, 4);
}
sprintf(&zBuf[i], " ");
i += 12;
if( flg & FG_PGSZ ){
unsigned short sz;
memcpy(&sz, aData+ofst, 2);
sprintf(&zBuf[i], " %9d", sz==1 ? 65536 : sz);
}else if( flg & FG_HEX ){
sprintf(&zBuf[i], " 0x%08x", val);
}else if( nByte<8 ){
sprintf(&zBuf[i], " %9d", val);
}
printf("%s %s\n", zBuf, zMsg);
}
/*
** Print an instance of the WalIndexHdr object. ix is either 0 or 1
** to select which header to print.
*/
static void print_index_hdr(unsigned char *aData, int ix){
int i;
assert( ix==0 || ix==1 );
i = ix ? 48 : 0;
print_decode_line(aData, 0+i, 4, FG_NBO, "Wal-index version");
print_decode_line(aData, 4+i, 4, 0, "unused padding");
print_decode_line(aData, 8+i, 4, FG_NBO, "transaction counter");
print_decode_line(aData,12+i, 1, 0, "1 when initialized");
print_decode_line(aData,13+i, 1, 0, "true if WAL cksums are bigendian");
print_decode_line(aData,14+i, 2, FG_PGSZ, "database page size");
print_decode_line(aData,16+i, 4, FG_NBO, "mxFrame");
print_decode_line(aData,20+i, 4, FG_NBO, "Size of database in pages");
print_decode_line(aData,24+i, 8, 0, "Cksum of last frame in -wal");
print_decode_line(aData,32+i, 8, 0, "Salt values from the -wal");
print_decode_line(aData,40+i, 8, 0, "Cksum over all prior fields");
}
/*
** Print the WalCkptInfo object
*/
static void print_ckpt_info(unsigned char *aData){
const int i = 96;
int j;
print_decode_line(aData, 0+i, 4, FG_NBO, "nBackfill");
for(j=0; j<5; j++){
char zLabel[100];
sprintf(zLabel, "aReadMark[%d]", j);
print_decode_line(aData, 4*j+4+i, 4, FG_NBO, zLabel);
}
print_decode_line(aData,24+i, 8, 0, "aLock");
print_decode_line(aData,32+i, 4, FG_NBO, "nBackfillAttempted");
print_decode_line(aData,36+i, 4, FG_NBO, "notUsed0");
}
int main(int argc, char **argv){
unsigned char *aData;
if( argc<2 ){
fprintf(stderr,"Usage: %s FILENAME\n", argv[0]);
exit(1);
}
fd = open(argv[1], O_RDONLY);
if( fd<0 ){
fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
exit(1);
}
aData = getContent(0, 136);
print_index_hdr(aData, 0);
print_index_hdr(aData, 1);
print_ckpt_info(aData);
free(aData);
close(fd);
return 0;
}