Debugging MariaDB with mysql-test-run
If you have MariaDB compile for for debugging you can both use it in a debugger, like ddd or gdb, and get comprehensive trace file of the execution of MariaDB. The trace files are great to both see the flow of the code and by comparing two trace files you can see the difference in execution.
Core dumps are also much easier to investigate if they come from a debug binaries.
Note that a binary compiled for debugging and tracing is about 10-20 % slower than a normal binary. If you just compile a binary for debugging (option -g
with gcc) the speed difference compared to a normal binary is neglectable.
Checking that MariaDB is compiled for debugging
Execute:
mysqld --debug --help
If you get an error 'unknown option '--debug', then MariaDB is not compiled for debugging and tracing.
Building MariaDB for debugging starting from 5.5
On Unix you need to pass -DCMAKE_BUILD_TYPE=Debug
to cmake to compile with debug information.
The other option is to use the scripts in the BUILD directory that will compile MariaDB with most common debug options and plugins:
./BUILD/compile-pentium64-debug-max
For the most common configurations there exists a fine tuned script in the BUILD directory.
If you want to use valgrind, a very good memory instrumentation tool and memory overrun checker, you should use
./BUILD/compile-pentium64-valgrind-max
Some recommended debugging scripts for Intel/AMD are:
BUILD/compile-pentium64-debug-max BUILD/compile-pentium64-valgrind-max
Building MariaDB 5.3 and older
Here is how you compile with debug on older versions:
Here is an example of how to compile MariaDB for debugging in your home directory with MariaDB 5.2.9 as an example:
cd ~ mkdir mariadb cd mariadb tar xvf mariadb-5.2.9.tar.gz ln -s mariadb-5.2.9 current cd current ./BUILD/compile-pentium64-debug-max
The last command will produce a debug version of sql/mysqld
.
If you have a system other than 64 bit Intel/AMD on Linux you can use a
different BUILD/...-debug-max
file. If this fails, you can
try with:
./BUILD/autorun.sh ./configure --with-debug=full -with-extra-charsets=complex \ --with-plugin-aria --with-aria-tmp-tables --without-plugin-innodb_plugin \ --with-plugins=max \ --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static make
Debugging MariaDB from the source directory
Creating the test database
Creating the MariaDB databases in /data
./scripts/mysql_install_db --srcdir=. --datadir=/data
Running MariaDB in a debugger
The following example is using ddd
, an excellent graphical debugger in Linux. If you don't have ddd
installed, you can of course use gdb
instead.
cd sql ddd mysqld & run --datadir=/data --language=./share/english --gdb
You can of course set the options in your /.my.cnf file to not have to repeat them on the run
line.
If you run mysqld
with --debug
, you will get a trace file in /tmp/mysqld.trace that shows what is happening.
Note that you can have different options in the configuration file for each MariaDB version (like having a specific language directory).