Compiling MariaDB for Debugging
Compiling MariaDB for Debugging Using the CMAKE_BUILD_TYPE Option
CMAKE_BUILD_TYPE OptionThis option enables multiple debug instrumentation aspects within the MariaDB server that provided more detailed information around complex parts of the server and can be used to implement and run tests where the concurrent execution of multiple threads must be controlled to achieve a specific state. If you are not doing this, the following option is sufficient.
Compiling MariaDB with full debug information includes all code symbols and also new code to do internal testing of structures and allow one to trace MariaDB execution. A full debug binary will be notably slower than a normal binary (30%). Most of this overhead can be removed by disabling -DWITH_DBUG_TRACE=OFF
You can configure build a debug build by executing cmake and by setting the CMAKE_BUILD_TYPE option to Debug. For example:
cmake -DCMAKE_BUILD_TYPE=Debug source_directoryTo compile:
cmake --build .You can find a list of the needed packages/libraries for building on Linux here.
Building Optimized Build With Debug Symbols
To build MariaDB with debug symbols, to get better stack traces and to be able to debug the binary with gdb, you need to supply the -Og and -g3 options to the gcc compiler for an debuggable, with limited optimization tradeoffs..
Pass these are options to cmake like:
cmake -DCMAKE_CXX_COMPILE_FLAGS='-Og -g3' -DCMAKE_C_COMPILE_FLAGS='-Og -g3' source_directoryTo compile:
cmake --build .Doing a Debug Build on Debian/Ubuntu
To build a "mariadbd" binary with debugging enabled that uses the same parameters as the ones used in Debian/Ubuntu binary packages, you must do as follows (you must have a deb-src line of one of the MariaDB repositories on your /etc/apt/sources.list in order to do that):
apt install build-essential devscripts fakeroot dpkg-dev
apt-get build-dep mariadb-server
apt-get source mariadb-server
cd mariadb-*
DEB_CFLAGS_APPEND='-Og -g3' DEB_CXXFLAGS_APPEND='-Og -g3' debuild -us -ucThe packages created will have these flags set.
Temporarily Installing your Debug Build
The commands shown below replace the release mariadbd binary with the debug mariadbd binary that you compiled. Most importantly, they replace the binary in a way which makes it trivial to revert back to the
original release mariadbd binary.
First, stop MariaDB.
Then, use the mv utility to rename the release mariadbd binary:
sudo mv /usr/sbin/mariadbd /usr/sbin/mariadbd-origNote: Do not use the cp utility because that will change the file modification timestamp.
Then, install the debug mariadbd binary from your source tree:
sudo install ~/mariadb-*/sql/mariadbd /usr/sbin/mariadbdThen, start MariaDB.
Be sure to replace /usr/sbin/mariadbd with the path to your mariadbdd binary and to also replace ~/mariadb-*/sql/mariadbd with the path to your debug #mariadbdbinary.
Reinstalling your Release Build
If you want to restore your original mariadbd binary, you can do it with the following process::
First, stop MariaDB.
Then, execute the following command to delete the symbolic link:
sudo mv /usr/sbin/mariadbd /usr/sbin/mariadbd-debugThen, execute the following command to move the original mariadbd release binary back into place:
sudo mv /usr/sbin/mariadbd-orig /usr/sbin/mariadbdThen, start MariaDB.
Be sure to replace /usr/sbin/mariadbd with the path to your mariadbd binary
The debug mariadb-debug binary is still present if it is needed again in the future.
Different Compilation Options
Changing DBUG_ASSERT to Print to Error Log
A debug binary has lots of code checks and asserts, that are not checked in production. This is done to get more performance when running in production. In some cases, when one is trying to find a hard-to-repeat bug, it could be beneficial to have these checks in production builds too.
Compiling with -DDBUG_ASSERT_AS_PRINTF will change DBUG_ASSERT() to print any failed check to the error log.
cmake . -DDBUG_ASSERT_AS_PRINTFEnabling the above option should not have any notable impact on performance (probably < 1% slowdown). This is achieved by grouping asserts in MariaDB server code into two groups:
Fast checks, using
DBUG_ASSERT(): These are converted to printing to error log.Slow checks, using
DBUG_SLOW_ASSERT(). These will always be removed in production builds.
See Also
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

