Copyright © 2019 MariaDB. All rights reserved.
Training & Tutorials
Advanced MariaDB Articles
Compiling MariaDB for Debugging
Compiling MariaDB for Debugging - Source
<<toc>> ==Building MariaDB Starting From 5.5 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%). On Unixes 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: <<code>> ./BUILD/compile-pentium64-debug-max <</code>> There are separate build scripts for different configurations in the BUILD directory. You can find a list of the needed packages/libraries for building on Linux [[Build_Environment_Setup_for_Linux|here]]. == Example of Building MariaDB With Build Scripts * Scripts containing "debug" in the name are for developers that want to build, develop and test MariaDB. * Scripts containing "valgrind" in the name are for running mysqld under [[|http://valgrind.org|valgrind]]. Compiling for valgrind means that we are using another implementation of MEM_ROOT to allow valgrind to better detect memory overruns. In addition, some memory areas are marked as used/not used to remove some false positives. * Scripts containing "max" in the name include all normal plugins. Here is an example of how to compile MariaDB for debugging in your home directory with MariaDB 5.2.9 as an example: <<code>> 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 <</code>> The last command will produce a debug version of <<fixed>>sql/mysqld<</fixed>>. If you have a system other than 64 bit Intel/AMD on Linux you can use a different <<fixed>>BUILD/...-debug-max<</fixed>> file. If this fails, you can try with: <<code>> cmake --build . --config Debug make -j4 <</code>> == Building Optimized Build With Debug Symbols To build MariaDB with symbols, to get better stack traces and to be able to debug the binary with ##gdb##, you need to supply the ##-g3## option to the ##gcc## compiler. Just compiling with ##-g3## will make the binary much bigger but the slowdown of the server should be negligible. One way to do this is to edit the script <<code>> BUILD/compile-pentium64-max <</code>> and add the -g3 last on the line with ##extra_flags##, like this: <<code>> extra_flags="$pentium64_cflags $fast_cflags -g3" <</code>> After that you can compile MariaDB with debugging symbols by just execution the above script. == Doing a Debug Build on Debian/Ubuntu To build a "mysqld" 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): <<code>> apt-get build-dep mariadb-10.2 apt-get install cmake libaio1 libaio-dev apt-get source mariadb-10.2 cd mariadb-10.2* ./debian/rules configure ./BUILD/compile-pentuim64-debug-all <</code>> Then you will have your "debugging enabled" mysqld binary in the sql/ directory. This binary can directly replace the one provided by the binary package that is placed on "/usr/bin/mysqld". == See Also * [[Build_Environment_Setup_for_Linux|Build environment setup for Linux]] * [[debugging-mariadb-with-a-debugger|Debugging MariaDB with a debugger]] *[[creating-a-trace-file|Creating a trace file]] *[[how-to-compile-and-use-mariadb-with-addresssanitizer-asan|Using ASAN with MariaDB]]