Skip to content
Search

Valgrind

lastmod 2022-05-15created 2014-12-3021 edits

Valgrind is a Linux-based open-source (GPL license) DBI tool. This means it provides the opportunity to directly manipulate the executable code of a client program (the one given as input to valgrind) at run time. valgrind consists broadly of a Core and Tools, and "valgrind" generally refers to the core.

Incidentally, the word seems to be a compound of value, meaning variable, and grind, meaning to grind.

Category

Valgrind Suppression File

How to make a suppression file

Run valgrind as usual, but with the extra option --gen-suppressions=all

Instrumentation

Instrumentation collectively refers to the work of adding necessary content to code in a code segment (region) so that it produces the desired result. This instrumentation can take place at several stages:

  • Source code
  • Preprocessor (Preprocessor code)
  • Assembly code
  • Machine code
  • Binary executable

It is possible at any of these stages. It generally means static instrumentation, which means first analyzing code at one of the above stages and inserting the necessary additional code. The instrumented code is then run to obtain the desired result.

With dynamic instrumentation, however, instrumentation is performed at runtime and executed immediately. Because static instrumentation cannot know what happens during execution, dynamic instrumentation has the advantage of being able to observe and respond to memory and cache behavior during execution.

Valgrind is a representative dynamic instrumentation framework.

Quick Start Guide

Run the program as follows.

valgrind --leak-check=yes myprog arg1 arg2

Or,

valgrind --leak-check=full --show-leak-kinds=all myprog arg1 arg2

Report

Conditional jump or move depends on uninitialised value(s)
stackoverflow - pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
A conditional branch or move depends on an uninitialized value.
Use of uninitialised value of size (n)
An uninitialized variable was used.

XML Output

$ valgrind --xml=yes --demangle=yes --verbose

If you want to output as HTML, use XHTML. For the XSL and XML files, download the Spike-test-gen.sourceforge.net_valgrind.zip item.

Troubleshooting

README_MISSING_SYSCALL_OR_IOCTL

==10900== Warning: noted but unhandled ioctl 0x30000001 with no size/direction hints
==10900==    This could cause spurious value errors to appear.
==10900==    See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.

Memory still reachable _dl_init()

When using valgrind with the STL, the following error may occur.

$ valgrind --leak-check=full --show-leak-kinds=all ./a.out

Output:

==11500== Memcheck, a memory error detector
==11500== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==11500== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==11500== Command: ./a.out
==11500==
Hello, World!
==11500==
==11500== HEAP SUMMARY:
==11500==     in use at exit: 72,704 bytes in 1 blocks
==11500==   total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==11500==
==11500== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==11500==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11500==    by 0x4E9D62F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22)
==11500==    by 0x4010109: call_init.part.0 (dl-init.c:78)
==11500==    by 0x40101F2: call_init (dl-init.c:36)
==11500==    by 0x40101F2: _dl_init (dl-init.c:126)
==11500==    by 0x4001309: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==11500==
==11500== LEAK SUMMARY:
==11500==    definitely lost: 0 bytes in 0 blocks
==11500==    indirectly lost: 0 bytes in 0 blocks
==11500==      possibly lost: 0 bytes in 0 blocks
==11500==    still reachable: 72,704 bytes in 1 blocks
==11500==         suppressed: 0 bytes in 0 blocks
==11500==
==11500== For counts of detected and suppressed errors, rerun with: -v
==11500== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

This is caused by the global memory pool used by the STL and can be ignored.

See also

Favorite site

author Zer0 sitemap