DevOps

Valgrind – instrumentation framework for building dynamic analysis tools

Valgrind is a tool for memory debugging, memory leak detection, and profiling. It is essentially a virtual machine using just-in-time compilation techniques.

The Valgrind distribution currently includes five production-quality tools: a memory error detector, a thread error detector, a cache and branch-prediction profiler, a call-graph generating cache profiler, and a heap profiler. It also includes two experimental tools: a data race detector, and an instant memory leak detector.

Valgrind is designed to be as non-intrusive as possible. It works directly with existing executables. You don’t need to recompile, relink, or otherwise modify, the program to be checked.

Key Features

  • Memcheck detects memory-management problems in programs. All reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. Memcheck can therefore detect the following problems:
    • Use of uninitialised memory.
    • Reading/writing memory after it has been free’d.
    • Reading/writing off the end of malloc’d blocks.
    • Reading/writing inappropriate areas on the stack.
    • Memory leaks — where pointers to malloc’d blocks are lost forever.
    • Mismatched use of malloc/new/new [] vs free/delete/delete [].
    • Overlapping src and dst pointers in memcpy() and related functions.
  • Cachegrind is a cache profiler. It performs detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code. It will show the number of cache misses, memory references and instructions accruing to each line of source code, with per-function, per-module and whole-program summaries. If you ask really nicely it will even show counts for each individual machine instruction.
  • Callgrind is a profiler similar in concept to Cachegrind, but which also tracks caller-callee relationships. By doing so it is able to show how instruction, memory reference and cache miss costs flow between callers and callees. Callgrind collects a large amount of data which is best navigated using Josef Weidendorfer’s amazing KCachegrind visualisation tool. KCachegrind is a KDE application which presents these profiling results in a graphical and easy-to-understand form.
  • Massif is a heap profiler. It measures how much heap memory programs use. In particular, it can give you information about heap blocks, heap administration overheads, and stack sizes.
  • Helgrind detects synchronisation errors in programs that use the POSIX pthreads threading primitives. It detects the following three classes of errors:
    • Misuses of the POSIX pthreads API.
    • Potential deadlocks arising from lock ordering problems.
    • Data races — accessing memory without adequate locking.

Website: valgrind.org
Support: Manual
Developer: Cerion Armour-Brown, Jeremy Fitzhardinge, Tom Hughes, Nicholas Nethercote, Paul Mackerras, Dirk Mueller, Julian Seward, and others
License: GNU General Public License v2.0

Valgrind is written in C. Learn C with our recommended free books and free tutorials.


Related Software

Debuggers
LLDBNext generation, high-performance debugger
GhidraSoftware reverse engineering framework
DelveSource level debugger for the Go programming language
GDBThe GNU Debugger
ValgrindA memory debugger and profiler
Radare2Portable reversing framework
BugStalkerRust debugger
XdebugExtension for PHP to aid debugging and development
SeerGUI frontend to GDB
iaitoGraphical interface for radare2
React Native DebuggerStandalone app for debugging React Native apps
KDbgGraphical user interface to GDB
straceDiagnostic, debugging and instructional userspace utility
rrRecord-and-replay debugger
drgnProgrammable debugger that puts scripting at the centre
cgdbLightweight console frontend to the GNU debugger
PuDBConsole-based visual debugger for Python
nndPartially inspired by RemedyBG
bashdbSource-code debugger for bash; follows the GDB command syntax
SysprofProfile an application or entire system
crashLinux kernel crash analysis utility
NemiverStandalone graphical debugger for GNOME

Read our verdict in the software roundup.


Best Free and Open Source Software Explore our comprehensive directory of recommended free and open source software. Our carefully curated collection spans every major software category.

This directory is part of our ongoing series of informative articles for Linux enthusiasts. It features hundreds of detailed reviews, along with open source alternatives to proprietary solutions from major corporations such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

You’ll also find interesting projects to try, hardware coverage, free programming books and tutorials, and much more.

Discovered a useful open source Linux program that we haven’t covered yet? Let us know by completing this form.
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments