UbuntuWiki:Valgrind

来自Ubuntu中文
跳到导航跳到搜索

{{#ifexist: :UbuntuWiki:Valgrind/zh | | {{#ifexist: UbuntuWiki:Valgrind/zh | | {{#ifeq: {{#titleparts:UbuntuWiki:Valgrind|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:UbuntuWiki:Valgrind|1|-1|}} | zh | | }}

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

  1. Remove any old Valgrind logs:

rm valgrind.log.*

  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 <program> <arguments>

  1. The program will start. Perform any actions necessary to reproduce the crash
  2. Package up the log files:

tar -zcf valgrind-logs-<program>.tar.gz valgrind.log.*

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