Once you have set up a debug version of ArangoDB, it is quite helpful to also enable the Address Sanitizer and its companion tools.
These sanitizers provide runtime instrumentation for executables and check for common C++ programming errors such as buffer overflows, use-after-free bugs and memory leaks. The sanitizers supported natively by recent versions of g++ and clang++.
The general runtime overhead of the sanitizers is neglectable compared to other instrumentation tools such as Valgrind, so it can well be used in the day-to-day development process.
Configuring the build to use ASAN
To build with ASAN (Address Sanitizer) and UBSAN (Undefined Behavior Sanitizer), the following environment variables need to be set when invoking cmake:
1
|
|
The full command to configure a debug build with ASAN and UBSAN support is:
1
|
|
This will configure the build so it will pass the sanitizer options to the C++ compiler. Note that you’ll need a recent version of g++ or clang++ for this to work.
After that, build arangod normally. The binaries produced will be instrumented by the sanitizers, allowing many nasty memory errors to be detected very early.
Checking if an arangod binary is using ASAN
Whether or not an ArangoDB binary is instrumented can be found out at any
time by calling the binary with the --version
option. This will print some
version information for ArangoDB itself and the other required libraries,
and it will also print in the line starting with asan
whether the binary
was compiled with ASAN support or not:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Controlling ASAN runtime behavior
ASAN behavior can also be controlled at runtime, after the binaries have
been produced, by adjusting the environment variable ASAN_OPTIONS
.
The setting I use for this is:
1
|
|