Difference between revisions of "Valgrind"

From Embedded Lab Vienna for IoT & Security
Jump to navigation Jump to search
Line 5: Line 5:
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.
Valgrind executes a program 20-30 times slower and performs dynamic code analysis.


== Description ==
== Tools ==


The Valgrind distribution currently includes seven production-quality tools:
The Valgrind distribution currently includes seven production-quality tools:
Line 16: Line 16:
* DHAT
* DHAT


=== heading ===
=== Memcheck ===
Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck's supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:
 
* Accesses memory it shouldn't (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack).
* Uses uninitialised values in dangerous ways.
* Leaks memory.
* Does bad frees of heap blocks (double frees, mismatched frees).
* Passes overlapping source and destination memory blocks to memcpy() and related functions.
 
Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.
 
=== Cachegrind ===
 
=== Callgrind ===
 
=== Massif ===
 
=== Helgrind ===
 
=== DRD ===
 
=== DHAT ===
 





Revision as of 15:23, 13 January 2023

What is Valgrind?

Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

Valgrind executes a program 20-30 times slower and performs dynamic code analysis.

Tools

The Valgrind distribution currently includes seven production-quality tools:

  • Memcheck
  • Cachegrind
  • Callgrind
  • Massif
  • Helgrind
  • DRD
  • DHAT

Memcheck

Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck's supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program:

  • Accesses memory it shouldn't (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack).
  • Uses uninitialised values in dangerous ways.
  • Leaks memory.
  • Does bad frees of heap blocks (double frees, mismatched frees).
  • Passes overlapping source and destination memory blocks to memcpy() and related functions.

Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal.

Cachegrind

Callgrind

Massif

Helgrind

DRD

DHAT

References