Valgrind

Differences between revisions 16 and 17
Revision 16 as of 2012-11-15 17:29:26
Size: 2128
Editor: c-76-21-12-7
Comment:
Revision 17 as of 2013-01-03 17:20:38
Size: 2151
Editor: brian-murray
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
Please ensure you have packages with debug symbols installed. You can do this by following the instructions at DebuggingProgramCrash. /!\ Please ensure you have packages with debug symbols installed. You can do this by following the instructions at DebuggingProgramCrash.
Line 21: Line 21:
 1. Start the program under control of `memcheck` (valgrind can't solve paths, so you should feed it the full program path, to get it: `which <program>`): {{{
G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log <program> <arguments>
 1. Start the program under control of `memcheck`:
{{{
G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log $(which <program>) <arguments>
Line 24: Line 25:
 1. N.B. valgrind can't solve paths, so you should feed it the full program path, to get it: $(which <program>)

Debugging Central

This page is part of the debugging series — pages with debugging details for a variety of Ubuntu packages.

Valgrind is a suite of tools for debugging and profiling programs. There are three tools: a memory error detector, a time profiler, and a space profiler.

For debugging purposes, the memory error detector is a handy tool.

Memory error detection

The most important of these is the memory error detector, which tracks the usage of every single bit in a program, and warns if there's something suspicious. Valgrind can detect if memory is used before it has a value, memory is leaked, or memory is used twice.

This makes it ideal for tracking down segmentation faults, bus errors, and general memory leaks.

Warning /!\ Please ensure you have packages with debug symbols installed. You can do this by following the instructions at DebuggingProgramCrash.

  1. Make sure Valgrind is installed.

    sudo apt-get install valgrind
  2. Remove any old Valgrind logs:

    rm valgrind.log*
  3. Start the program under control of memcheck:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log $(which <program>) <arguments>
  1. N.B. valgrind can't solve paths, so you should feed it the full program path, to get it: $(which <program>)

  2. The program will start. It may take a while; this is normal, because Valgrind must perform extensive checking to detect memory errors.
  3. Perform any actions necessary to reproduce the crash.
  4. Package up the log files (no need if there is only one):

    tar -zcf valgrind-logs-<program>.tar.gz valgrind.log*
  5. Attach the complete output from Valgrind, contained in valgrind-logs-<program>.tar.gz, in your bug report.

Valgrind FAQ


CategoryBugSquad CategoryDebugging

Other languages

Valgrind (last edited 2013-01-03 17:20:38 by brian-murray)