Valgrind tool in linux

The Valgrind Quick Start Guide

1. Introduction

The Valgrind tool suite provides a number of debugging and profiling tools that help you make your programs faster and more correct. The most popular of these tools is called Memcheck. It can detect many memory-related errors that are common in C and C++ programs and that can lead to crashes and unpredictable behaviour.

The rest of this guide gives the minimum information you need to start detecting memory errors in your program with Memcheck. For full documentation of Memcheck and the other tools, please read the User Manual.

2. Preparing your program

Compile your program with -g to include debugging information so that Memcheck’s error messages include exact line numbers. Using -O0 is also a good idea, if you can tolerate the slowdown. With -O1 line numbers in error messages can be inaccurate, although generally speaking running Memcheck on code compiled at -O1 works fairly well, and the speed improvement compared to running -O0 is quite significant. Use of -O2 and above is not recommended as Memcheck occasionally reports uninitialised-value errors which don’t really exist.

3. Running your program under Memcheck

If you normally run your program like this:

Use this command line:

Memcheck is the default tool. The —leak-check option turns on the detailed memory leak detector.

Your program will run much slower (eg. 20 to 30 times) than normal, and use a lot more memory. Memcheck will issue messages about memory errors and leaks that it detects.

4. Interpreting Memcheck’s output

Here’s an example C program, in a file called a.c, with a memory error and a memory leak.

Most error messages look like the following, which describes problem 1, the heap block overrun:

Things to notice:

There is a lot of information in each error message; read it carefully.

The 19182 is the process ID; it’s usually unimportant.

The first line («Invalid write. «) tells you what kind of error it is. Here, the program wrote to some memory it should not have due to a heap block overrun.

Below the first line is a stack trace telling you where the problem occurred. Stack traces can get quite large, and be confusing, especially if you are using the C++ STL. Reading them from the bottom up can help. If the stack trace is not big enough, use the —num-callers option to make it bigger.

The code addresses (eg. 0x804838F) are usually unimportant, but occasionally crucial for tracking down weirder bugs.

Some error messages have a second component which describes the memory address involved. This one shows that the written memory is just past the end of a block allocated with malloc() on line 5 of example.c.

It’s worth fixing errors in the order they are reported, as later errors can be caused by earlier errors. Failing to do this is a common cause of difficulty with Memcheck.

Memory leak messages look like this:

The stack trace tells you where the leaked memory was allocated. Memcheck cannot tell you why the memory leaked, unfortunately. (Ignore the «vg_replace_malloc.c», that’s an implementation detail.)

There are several kinds of leaks; the two most important categories are:

«definitely lost»: your program is leaking memory — fix it!

«probably lost»: your program is leaking memory, unless you’re doing funny things with pointers (such as moving them to point to the middle of a heap block).

Memcheck also reports uses of uninitialised values, most commonly with the message «Conditional jump or move depends on uninitialised value(s)». It can be difficult to determine the root cause of these errors. Try using the —track-origins=yes to get extra information. This makes Memcheck run slower, but the extra information you get often saves a lot of time figuring out where the uninitialised values are coming from.

Читайте также:  Real time monitoring windows

If you don’t understand an error message, please consult Explanation of error messages from Memcheck in the Valgrind User Manual which has examples of all the error messages Memcheck produces.

5. Caveats

Memcheck is not perfect; it occasionally produces false positives, and there are mechanisms for suppressing these (see Suppressing errors in the Valgrind User Manual). However, it is typically right 99% of the time, so you should be wary of ignoring its error messages. After all, you wouldn’t ignore warning messages produced by a compiler, right? The suppression mechanism is also useful if Memcheck is reporting errors in library code that you cannot change. The default suppression set hides a lot of these, but you may come across more.

Memcheck cannot detect every memory error your program has. For example, it can’t detect out-of-range reads or writes to arrays that are allocated statically or on the stack. But it should detect many errors that could crash your program (eg. cause a segmentation fault).

Try to make your program so clean that Memcheck reports no errors. Once you achieve this state, it is much easier to see when changes to the program cause Memcheck to report new errors. Experience from several years of Memcheck use shows that it is possible to make even huge programs run Memcheck-clean. For example, large parts of KDE, OpenOffice.org and Firefox are Memcheck-clean, or very close to it.

6. More information

Please consult the Valgrind FAQ and the Valgrind User Manual, which have much more information. Note that the other tools in the Valgrind distribution can be invoked with the —tool option.

Источник

Valgrind tool in linux

The complete source code, including documentation, is available as a tarball for the current release. For downloadable / browseable manual packages, go to the Documentation page. For older releases, see the Release Archive page.

If you would like to be notified when a new valgrind release is made, you can subscribe to the Valgrind announcements mailing list.

Valgrind 3.17.0

PGP signature is here.

3.17.0 fixes a number of bugs and adds some functional changes: support for GCC 11, Clang 11, DWARF5 debuginfo, the ‘debuginfod’ debuginfo server, and some new instructions for Arm64, S390 and POWER. There are also some tool updates. See the release notes for details.

PGP signature is here.

3.16.0 updates support for existing platforms, adds support for AArch64 v8.1, and reduces the Memcheck false positive rate on highly optimised code. There are, as ever, many smaller refinements and bug fixes. See the release notes for details.

PGP signature is here.

3.15.0 updates support for existing platforms and adds a major overhaul of the DHAT heap profiler. There are, as ever, many smaller refinements and bug fixes. See the release notes for details.

3.14.0 updates support for existing platforms. There are, as ever, many smaller refinements and bug fixes. See the release notes for details.

3.13.0 adds support for larger processes and programs, solidifies and improves support on existing platforms, and provides new heap-use reporting facilities. There are, as ever, many smaller refinements and bug fixes. See the release notes for details.

3.12.0 is a feature release with many improvements and the usual collection of bug fixes. This release adds support for POWER ISA 3.0, improves instruction set support on ARM32, ARM64 and MIPS, and provides support for the latest common components (kernel, gcc, glibc). There are many smaller refinements and new features. See the release notes for details.

Читайте также:  Windows 10 заставка без пароля

You may want to look at the 3.11.0 release notes.

3.11.0 is a feature release with many improvements and the usual collection of bug fixes. This release adds full support for X86/Solaris and AMD64/Solaris, improves support for Mac OS X 10.10 (Yosemite), and adds preliminary support for Mac OS X 10.11 (El Capitan) and TileGX/Linux. Intel AVX2 support is more complete (64 bit targets only). There are many smaller refinements and new features. See the release notes for details.

You may want to look at the 3.10.1 release notes.

3.10.1 is a bug fix release. It fixes various bugs reported in 3.10.0 and backports fixes for all reported missing AArch64 ARMv8 instructions and syscalls from the trunk. If you package or deliver 3.10.0 for others to use, you might want to consider upgrading to 3.10.1 instead. See the release notes for details.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, ARM64/Linux,PPC32/Linux, PPC64/Linux, PPC64BE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, ARM/Android (2.3 and later), X86/Android (4.0 and later), MIPS32/Android, X86/Darwin and AMD64/Darwin (Mac OS X 10.9 and, to a limited extent, 10.8).

You may want to look at the 3.10.0 release notes.

3.10.0 is a feature release with many improvements and the usual collection of bug fixes. This release adds support for ARM64/Linux, MIPS32/Android and little-endian PPC64/Linux, and improves support for Mac OS X 10.9 (Mavericks). Inlining-aware stack unwinding is now available on Linux targets. There are many smaller refinements and new features. See the release notes for details.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, ARM64/Linux,PPC32/Linux, PPC64/Linux, PPC64BE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, ARM/Android (2.3 and later), X86/Android (4.0 and later), MIPS32/Android, X86/Darwin and AMD64/Darwin (Mac OS X 10.9 and, to a limited extent, 10.8).

You may want to look at the 3.9.0 release notes.

3.9.0 is feature release with many improvements and the usual collection of bug fixes. This release adds support for MIPS64/Linux and improves support for Mac OS X 10.8 (Mountain Lion). Intel AVX2 and Power POWER8 instructions are supported. Initial support for hardware transactional memory on Intel and POWER platforms has been added. Accuracy of Memcheck on vectorized code has been improved. There are many smaller refinements and new features. See the release notes for details.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, ARM/Android (2.3 and later), X86/Android (4.0 and later), X86/Darwin and AMD64/Darwin (Mac OS X 10.7 and, to a limited extent, 10.8).

You may want to look at the 3.8.1 release notes.

3.8.1 is a bug fix release. It fixes some assertion failures in 3.8.0 that occur moderately frequently in real use cases, adds support for some missing instructions on ARM, and fixes a deadlock condition on MacOSX. If you package or deliver 3.8.0 for others to use, you might want to consider upgrading to 3.8.1 instead. See the release notes for details, including a list of bug fixes.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, S390X/Linux, MIPS32/Linux, ARM/Android (2.3 and later), X86/Android (4.0 and later), X86/Darwin and AMD64/Darwin (Mac OS X 10.6, 10.7 and to a very limited extent, 10.8).

You may want to look at the 3.8.0 release notes.

3.8.0 is a feature release with many improvements and the usual collection of bug fixes. This release adds support for MIPS32/Linux and X86/Android and has initial support for Mac OS X 10.8 (Mountain Lion). Intel AVX and AES instructions are now supported. There is modestly improved performance in some areas, and decreased memory consumption. There are many smaller refinements and new features. See the release notes for details.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, S390X/Linux, MIPS32/Linux, ARM/Android (2.3 and later), X86/Android (4.0 and later), X86/Darwin and AMD64/Darwin (Mac OS X 10.6, 10.7 and to a very limited extent, 10.8).

You may want to look at the 3.7.0 release notes.

Читайте также:  Mega iptv mac os

3.7.0 is a feature release with many significant improvements and the usual collection of bug fixes. This release adds support for ARM/Android, S390X/Linux and Mac OS X 10.7 (Lion). A GDB server has been added, so you can now control your application from inside GDB whilst it runs on Valgrind. There have been performance and functionality improvements for the following tools: Helgrind, DRD, Memcheck and exp-Sgcheck.

The tool formerly known as exp-Ptrcheck has been renamed to exp-SGCheck.

This release supports X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, S390X/Linux, ARM/Android (2.3.x), X86/Darwin and AMD64/Darwin (Mac OS X 10.6 and 10.7).

You may want to look at the 3.6.1 release notes.

3.6.1 is a bug fix release. It adds support for some SSE4 instructions that were omitted in 3.6.0 due to lack of time. Initial support for glibc-2.13 has been added. A number of bugs causing crashing or assertion failures have been fixed.

You may want to look at the 3.6.0 release notes.

3.6.0 is a feature release with many significant improvements and the usual collection of bug fixes. The main improvement is that Valgrind now works on ARM/Linux and on Mac OS X 10.6 (Snow Leopard).

This release supports X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, X86/Darwin and AMD64/Darwin (Mac OS X 10.5 and 10.6). Support for recent distros and toolchain components (glibc 2.12, gcc 4.5) has been added.

You may want to look at the 3.5.0 release notes.

3.5.0 is a feature release with many significant improvements and the usual collection of bug fixes. The main improvement is that Valgrind now works on Mac OS X.

This release supports X86/Linux, AMD64/Linux, PPC32/Linux, PPC64/Linux and X86/Darwin (Mac OS X). Support for recent distros and toolchain components (glibc 2.10, gcc 4.5) has been added.

You may want to look at the 3.4.1 release notes.

3.4.1 is a bug-fix release that fixes some regressions and assertion failures in debug info reading in 3.4.0, most notably incorrect stack traces on amd64-linux on older (glibc-2.3 based) systems. Various other debug info problems are also fixed. A number of bugs in the exp-ptrcheck tool introduced in 3.4.0 have been fixed.

In view of the fact that 3.4.0 contains user-visible regressions relative to 3.3.x, upgrading to 3.4.1 is recommended. Packagers are encouraged to ship 3.4.1 in preference to 3.4.0.

Valkyrie 2.0.0

valkyrie 2.0.0 (tar.bz2) [260Kb] — 21 October 2010.
md5: a411dfb803f548dae5f988de0160aeb5

Valkyrie is a Qt4-based GUI for the Valgrind 3.6.x and 3.7.x series, that works for the Memcheck and Helgrind tools. It also has an XML merging tool for Memcheck outputs (vk_logmerge). This tarball is known to build and work with valgrind-3.6.0 and valgrind-3.7.0.

This version of Valkyrie does not support any version of Valgrind prior to 3.6.0. If you want to use Valkyrie with an older Valgrind version, we recommend you instead upgrade your Valgrind to 3.6.0 and use this version of Valkyrie.

Valkyrie is a GUI for the Valgrind 3.4.x releases. It also has an XML merging tool for Memcheck outputs (vk_logmerge). This tarball is known to build and work with valgrind-3.4.0.

This version of Valkyrie does not support the older Valgrind 3.3.x releases. If you need a GUI for Valgrind 3.3.x, instead use valkyrie 1.3.0 (tar.bz2) instead.

This version of Valkyrie also does not support the newer Valgrind 3.5.0 release. We plan to release a 3.5.0-compatible version of Valkyrie in the near future.

RPMs / Binaries

We do not distribute binaries or RPMs. The releases available on this website contain the source code and have to be compiled in order to be installed on your system. Many Linux distributions come with valgrind these days, so if you do not want to compile your own, go to your distribution’s download site.

Источник

Оцените статью