Documentation/devtools/maemo5/valgrind

Description
Valgrind is an Open Source suite of tools for debugging and profiling Linux programs. It works only on x86 (and PPC).

Valgrind is a really powerful and easy to use tool that can save you a lot of debugging time.

Because Valgrind works by simulating the x86 processor and instrumenting the binaries on the fly, it can control the program execution completely. As a downsize it makes program execution 10-300 times slower than normally, depending on the used Valgrind tools (massif is the fastest, callgrind the slowest) and can take a huge amount of memory.

The tools available for Valgrind are:


 * Massif: run-time memory usage graph and hyperlinked allocation backtraces (allocation are sorted by time*size)


 * Memcheck: Detects memory access errors (writes to freed memory, reads from uninitialized memory) and memory leaks (process has lost a pointer to allocation). This reports less false positives than any other (Open Source) tool and can call gdb when the error happens


 * Cachegrind: Performance profiling which can be started and stopped at any moment and the results can be sorted according to instructions, cache hits etc.


 * Callgrind: Like Cachegrind, but stores also callgraph information (but can show only instruction counts). Works very well with the Kcachegrind UI.


 * Helgrind: Detects race conditions when (p)threaded programs access global data

Building Valgrind
Please note that in maemo environment we need to export G_SLICE="always-malloc" to avoid getting bogus leakage reports from Glib GSlice allocator (its TLS usage confuses Valgrind allocation tracking). If you build your own Valgrind version, you should use this setting when Valgrinding programs using Glib (e.g. all maemo UI apps).

Packages
source: valgrind

binary: valgrind

Usage Examples
See the [maemo debugging guide][] for usage examples.

Links
[valgrind man page](/development/documentation/man_pages/valgrind.html)

(http://valgrind.org/) [Valgrind tool-suite](http://valgrind.org/info/tools.html)

[Memcheck memory checker](http://valgrind.org/docs/manual/mc-manual.html)

[Massif heap-profiler](http://valgrind.org/docs/manual/ms-manual.html)

[Callgrind profiler](http://valgrind.org/docs/manual/cl-manual.html)

[Helgrind data-race tracker](http://valgrind.org/docs/manual/hg-manual.html)

[maemo debugging guide][]

[maemo debugging guide]: /development/documentation/how-tos/4-x/maemo_debugging_guide.html