Valgrind

Differences between revisions 1 and 12 (spanning 11 versions)
Revision 1 as of 2006-05-01 21:31:19
Size: 1334
Editor: ottawa-hs-64-26-167-206
Comment: Describe how to use Valgrind
Revision 12 as of 2008-08-13 03:45:57
Size: 1910
Editor: c-66-30-199-209
Comment: I thought that Valgrind was hanging the first time I ran it, so I thought a little warning was in order.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<Include(Debugging/Header)>>
||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; background-image: url('https://librarian.launchpad.net/1812570/bugsquad.png'); background-repeat: no-repeat; background-position: 98% 0.5ex; margin: 0 0 1em 1em; padding: 0.5em;"><<TableOfContents>>||
Line 3: Line 5:
For debugging purposes, the memory error detector is ideal. For debugging purposes, the memory error detector is a handy tool.
Line 14: Line 16:
apt-get install valgrind sudo apt-get install valgrind
Line 20: Line 22:
valgrind -v --tool=memcheck --leak-check=full --num-callers=12 --log-file=valgrind.log <program> <arguments> G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log <program> <arguments>
Line 22: Line 24:
 1. The program will start. Perform any actions necessary to reproduce the crash
 1. Package up the log files: {{{
tar -zcf valgrind-logs.tar.gz valgrind.log.*
 1. The program will start. It may take a while; this is normal, because Valgrind must perform extensive checking to detect memory errors.
 1.
Perform any actions necessary to reproduce the crash.
 1. Package up the log files (no need if there is only one): {{{
tar -zcf valgrind-logs-<program>.tar.gz valgrind.log.*
Line 26: Line 29:
 1. Attach the complete output from Valgrind, contained in valgrind-logs.tar.gz, in your bug report.  1. Attach the complete output from Valgrind, contained in valgrind-logs-<program>.tar.gz, in your bug report.
----
CategoryBugSquad CategoryDebugging

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.

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 <program> <arguments>
  4. The program will start. It may take a while; this is normal, because Valgrind must perform extensive checking to detect memory errors.
  5. Perform any actions necessary to reproduce the crash.
  6. Package up the log files (no need if there is only one):

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


CategoryBugSquad CategoryDebugging

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