Engee documentation

Using Valgrind in Julia

https://valgrind.org /[Valgrind] is a tool for memory debugging, memory leak detection and profiling. This section describes the features to keep in mind when using Valgrind to debug memory issues in Julia.

General provisions

By default, Valgrind assumes that there is no self-modifying code in the programs it executes. This assumption is valid in most cases, but does not work for a JIT compiler such as 'julia'. For this reason, it is very important to pass --smc-check=all-non-file to the valgrind tool, otherwise the code may crash or behave unexpectedly (often quite subtly).

In some cases, for more efficient detection of memory errors using Valgrind, compiling julia with disabled memory pools can help. The compile-time flag MEMDEBUG disables memory pools in Julia, and MEMDEBUG2 disables memory pools in FemtoLisp. To build julia with both flags, add the following line to the Make.user file:

CFLAGS = -DMEMDEBUG -DMEMDEBUG2

One more point: If your program uses multiple workflows, most likely you will want all of these workflows (not just the parent process) to start with Valgrind. To do this, pass --trace-children=yes to the valgrind tool.

It is also worth noting that if errors occur with Unable to find compatible target in system image when using valgrind, try rebuilding the system image using the generic or julia target using `JULIA_CPU_TARGET=generic'.

Suppression

During operation, Valgrind usually issues false warnings. To reduce the number of such warnings, it is recommended to provide Valgrind https://valgrind.org/docs/manual/manual-core.html#manual-core.suppress [suppression file]. A sample suppression file is included in the Julia source code distribution in the file `contrib/valgrind-julia.supp'.

The suppression file can be used from the source code directory julia/ as follows:

$ valgrind --smc-check=all-non-file --suppressions=contrib/valgrind-julia.supp ./julia progname.jl

Any memory errors that are displayed should either be reported as errors or fixed as additional suppressions. Note that some versions of Valgrind https://github.com/JuliaLang/julia/issues/8314#issuecomment-55766210 [shipped with insufficient By default suppressions], so this point should be taken into account before sending any errors.

Running the Julia Test suite in Valgrind

It is possible to run the entire Julia test suite in Valgrind, but this will take quite a long time (usually several hours). To do this, run the following command from the julia/test/ directory:

valgrind --smc-check=all-non-file --trace-children=yes --suppressions=$PWD/../contrib/valgrind-julia.supp ../julia runtests.jl all

If you want to see a report on "certain" memory leaks, pass the --leak-check=full --show-leak-kinds=definite flags to the `valgrind' tool.

Additional bogus warnings

This section discusses Valgrind warnings that cannot yet be added to the suppression file, but which, however, can be safely ignored.

Raw rr system calls

Valgrind issues a warning when any https://github.com/rr-debugger/rr/blob/master/src/preload/rrcalls .h[system call related to rr], https://rr-project.org /[recording and playback framework]. In particular, a warning about an unprocessed system call 1008 is displayed if the Julia environment is trying to determine whether it is running rr:

--xxxxxx-- WARNING: unhandled amd64-linux syscall: 1008
--xxxxxx-- You may be able to write your own handler.
--xxxxxx-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--xxxxxx-- Nevertheless we consider this a bug.  Please report
--xxxxxx-- it at http://valgrind.org/support/bug_reports.html.

About this problem https://bugs.kde.org/show_bug.cgi?id=446401 [it was reported] to the Valgrind developers at their request.

Warnings

Currently Valgrind https://bugs.kde.org/show_bug.cgi?id=136779 [does not support multiple rounding modes], so the code that configures the rounding mode will work differently when running in Valgrind.

In general, if after installing --smc-check=all-non-file you find that the program behaves differently than when running in Valgrind, it is recommended to pass `--tool=none' to the `valgrind' tool upon further investigation. This will allow you to use the minimum Valgrind mechanism, but at the same time it will work much faster than the full memory check tool.