Debugging¶
This section contains general instructions for debugging failed installs or problems encountered with Loki. First ensure you are running the latest version built from the Github repo.
Obtaining stack traces and core dumps on Unix systems¶
We generally use the tool gdb
(GNU debugger) to provide stack trace functionality, and ulimit
to provide core dumps in builds which crash or segfault.
- To use gdb in order to obtain a stack trace for a build that has stalled:
Run the build.
Once it stalls, enter the following command:
gdb /path/to/lokid `pidof lokid`
Type thread apply all bt
within gdb in order to obtain the stack trace
- If however the core dumps or segfaults:
Enter ulimit -c unlimited
on the command line to enable unlimited filesizes for core dumps
Enter echo core | sudo tee /proc/sys/kernel/core_pattern
to stop cores from being hijacked by other tools
Run the build.
When it terminates with an output along the lines of "Segmentation fault (core dumped)", there should be a core dump file in the same directory as lokid. It may be named just core
, or core.xxxx
with numbers appended.
You can now analyse this core dump with gdb
as follows:
gdb /path/to/lokid /path/to/dumpfile
Print the stack trace with bt
- To run loki within gdb:
Type gdb /path/to/lokid
Pass command-line options with --args
followed by the relevant arguments
Type run
to run lokid
Analysing memory corruption¶
We use the tool valgrind
for this.
Run with valgrind /path/to/lokid
. It will be slow.
LMDB¶
Instructions for debugging suspected blockchain corruption as per @HYC
There is an mdb_stat
command in the LMDB source that can print statistics about the database but it's not routinely built. This can be built with the following command:
cd ~/loki/external/db_drivers/liblmdb && make
The output of mdb_stat -ea <path to blockchain dir>
will indicate inconsistencies in the blocks, block_heights and block_info table.
The output of mdb_dump -s blocks <path to blockchain dir>
and mdb_dump -s block_info <path to blockchain dir>
is useful for indicating whether blocks and block_info contain the same keys.
These records are dumped as hex data, where the first line is the key and the second line is the data.