SQLite Forum

Help needed! Database corruption on embedded system
Can you set watchpoints in the debugger?

If so, and you can manage to set a watchpoint to trigger when those bytes are written into the buffer, then that stack trace might tell us something.

It's complex. :)

First, set a breakpoint here:


The case you want to catch is when (*pPgno == 68). The buffer that is eventually being passed via sqlite3OsWrite() to your rawWrite() function is there at:


You then want to set a watchpoint at offset 8 of that buffer. Either on a 4 byte or 1 byte variable, probably doesn't matter which.

Math check: Page size is 512 bytes. Page 68 begins at offset (512*67)==34304. Plus 8 makes 34312, or 0x8608 in hex. Which is the offset of the corrupted bytes.

A hunch: Have you set sqlite3PendingByte? It's not your locking function (whatever sqlite3OsLock() calls) writing to those offsets by any chance?