A programming tool or software development tool is a computer program or application software that software developers use to create, debug, maintain, or otherwise support other programs and applications.... for memory debugging
Memory debugger
A memory debugger is a programming tool for finding memory leaks and buffer overflows. These are due to Software bug related to the allocation and deallocation of dynamic memory.... , memory leak
Memory leak
In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release dynamic memory when no longer needed.... detection, and profiling
Performance analysis
In software engineering, performance analysis, more commonly today known as profiling, is the investigation of a program's behavior using information gathered as the program executes .... . The name Valgrind comes from the name of the main entrance to Valhalla
Valhalla
In Norse mythology, Valhalla is a majestic, enormous hall located in Asgard, ruled over by the god Odin. Chosen by Odin, half of those that die in combat travel to Valhalla upon death, led by valkyries, while the other half go to the goddess Freyja's field F?lkvangr.... in Norse mythology
Norse mythology
Norse, Viking or Scandinavian mythology comprises the beliefs, myths and legends of the Norse paganism of the North Germanic language people, including those who settled on Faroe Islands and Iceland, where most of the written sources for Norse mythology were assembled.... .
Valgrind was originally designed to be a free memory debugging tool for Linux
Linux
Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license... on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers. It is used by a number of Linux-based projects.
Julian Seward is a compiler writer and Free Software contributor who lives in Cambridge, UK. He is commonly known for creating the bzip2 compression tool, as well as the valgrind memory debugging toolset funded in 2000.... , who in 2006 won a second Google
Google
Google Inc. is an United States public company, earning revenue from AdWords related to its Google search, Gmail, Google Maps, Google Apps, Orkut, and YouTube services as well as selling advertising-free versions of the Google Search Appliance.... -O'Reilly
O'Reilly Media
O'Reilly Media is an American Mass media company established by Tim O'Reilly that publishes books and web sites and produces conferences on computer technology topics.... Open Source
Open source
Open source is an approach to design, development, and distribution offering practical accessibility to a product's source . Some consider open source as one of various possible design approaches, while others consider it a critical Strategy element of their business operations.... Award for his work on Valgrind.
Several others have also
made significant contributions, including Cerion Armour-Brown, Jeremy Fitzhardinge, Tom Hughes, Nicholas Nethercote, Paul Mackerras, Dirk Mueller,
Josef Weidendorfer and Robert Walsh.
The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft.... , Valgrind is free software
Free software
Free Software or software libre is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware... .
In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions... using just-in-time
Just-in-time compilation
In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program.... (JIT) (aka binary translation
Binary translation
In computing, binary translation is the emulation of one instruction set by another through translation of Machine language. Sequences of instruction s are translated from the source to the target instruction set.... ) compilation techniques.
A programming tool or software development tool is a computer program or application software that software developers use to create, debug, maintain, or otherwise support other programs and applications.... for memory debugging
Memory debugger
A memory debugger is a programming tool for finding memory leaks and buffer overflows. These are due to Software bug related to the allocation and deallocation of dynamic memory.... , memory leak
Memory leak
In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release dynamic memory when no longer needed.... detection, and profiling
Performance analysis
In software engineering, performance analysis, more commonly today known as profiling, is the investigation of a program's behavior using information gathered as the program executes .... . The name Valgrind comes from the name of the main entrance to Valhalla
Valhalla
In Norse mythology, Valhalla is a majestic, enormous hall located in Asgard, ruled over by the god Odin. Chosen by Odin, half of those that die in combat travel to Valhalla upon death, led by valkyries, while the other half go to the goddess Freyja's field F?lkvangr.... in Norse mythology
Norse mythology
Norse, Viking or Scandinavian mythology comprises the beliefs, myths and legends of the Norse paganism of the North Germanic language people, including those who settled on Faroe Islands and Iceland, where most of the written sources for Norse mythology were assembled.... .
Valgrind was originally designed to be a free memory debugging tool for Linux
Linux
Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license... on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers. It is used by a number of Linux-based projects.
Julian Seward is a compiler writer and Free Software contributor who lives in Cambridge, UK. He is commonly known for creating the bzip2 compression tool, as well as the valgrind memory debugging toolset funded in 2000.... , who in 2006 won a second Google
Google
Google Inc. is an United States public company, earning revenue from AdWords related to its Google search, Gmail, Google Maps, Google Apps, Orkut, and YouTube services as well as selling advertising-free versions of the Google Search Appliance.... -O'Reilly
O'Reilly Media
O'Reilly Media is an American Mass media company established by Tim O'Reilly that publishes books and web sites and produces conferences on computer technology topics.... Open Source
Open source
Open source is an approach to design, development, and distribution offering practical accessibility to a product's source . Some consider open source as one of various possible design approaches, while others consider it a critical Strategy element of their business operations.... Award for his work on Valgrind.
Several others have also
made significant contributions, including Cerion Armour-Brown, Jeremy Fitzhardinge, Tom Hughes, Nicholas Nethercote, Paul Mackerras, Dirk Mueller,
Josef Weidendorfer and Robert Walsh.
The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft.... , Valgrind is free software
Free software
Free Software or software libre is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware... .
In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions... using just-in-time
Just-in-time compilation
In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program.... (JIT) (aka binary translation
Binary translation
In computing, binary translation is the emulation of one instruction set by another through translation of Machine language. Sequences of instruction s are translated from the source to the target instruction set.... ) compilation techniques. Nothing from the original program ever gets run directly on the host processor. Instead, Valgrind first translates the program into a temporary, simpler form called Intermediate Representation (IR),
which is a processor-neutral,
SSA
Static single assignment form
In compiler design, static single assignment form is an intermediate representation in which every variable is assigned exactly once. Existing variables in the original IR are split into versions, new variables typically indicated by the original name with a subscript, so that every definition gets its own version.... -based form. After the conversion, a tool (see below) is free to do whatever transformations it would like on the IR, before Valgrind translates the IR back into machine code and lets the host processor run it. A considerable amount of performance is lost in these transformations (and usually, the code the tool inserts); usually, code run with Valgrind and the "none" tool (which does nothing to the IR) runs 4-5 times slower than normal. However, the IR form is much more suitable for instrumentation than the original, which makes it easier to write tools, and for most projects, a slowdown of this order is not a big problem during debugging.
Tools
There are multiple tools included with Valgrind (and several external ones). The default (and most used) tool is Memcheck. Memcheck inserts extra instrumentation
Instrumentation (computer programming)
In context of computer programming, instrumentation refers to an ability to monitor or measure the level of a product's performance, to diagnose errors and writing trace information.... code around almost all instructions, which keeps track of the validity (all unallocated memory starts as invalid or "undefined", until it is initialized into a deterministic state, possibly from other memory) and addressability (whether the memory address in question points to an allocated, non-freed memory block), stored in the so-called V bits and A bits, respectively. As data is moved around or manipulated, the instrumentation code keeps track of the A and V bits so they are always correct on a single-bit level.
In addition, Memcheck replaces the standard C memory allocator with its own implementation, which also includes memory guards around all allocated blocks (with the A bits set to "invalid"). This feature enables Memcheck to detect off-by-one error
Off-by-one error
An off-by-one error is a logical error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an control flow#Loops iterates one time too many or too few.... s where a program reads or writes outside an allocated block by a small amount. (Other approaches to this problem include implemented bounded pointer
Bounded pointer
In computer science a bounded pointer is a pointer that is augmented with additional information that enable the storage bounds within which it may point to be deduced.... s in the compiler that give lower chances of undetected errors, especially on memory that is allocated on the stack
Call stack
In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program.... and not the heap, but requires recompiling all instrumented binary code.) The problems Memcheck can detect and warn about include the following:
In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release dynamic memory when no longer needed.... s
The price of this is lost performance; programs running under Memcheck usually run from five to twenty times as slow as running outside Valgrind, and use a lot more memory (there is a considerable memory penalty per-allocation). Thus, few developers run their code under Memcheck (or any other Valgrind tool) all the time; the most common situations would be either to trace down some specific bug, or to verify there are no latent bugs (of the kind Memcheck can detect) in the code.
In addition to Memcheck, Valgrind has several other tools:
Addrcheck, a lightweight cousin of Memcheck, running much faster and requiring less memory, but catching fewer types of bugs. This tool has been removed as of version 3.2.0.
A race condition or race hazard is a flaw in a system or process whereby the output and/or result of the process is unexpectedly and critically dependent on the sequence or timing of other events.... s in multithreaded code.
In computer science, a cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch or to compute, compared to the cost of reading the cache.... profiler and its GUI
Gui
Gui or guee is a generic term to refer to grillinged dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients.... KCacheGrind
There are also several externally developed tools available.
Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license... on x86, x86-64
X86-64
x86-64 is a superset of the x86. x86-64 Central processing units can run existing 32-bit or 16-bit x86 programs at full speed, but also support new programs written with a 64-bit address space and other additional capabilities.... and PowerPC
PowerPC
PowerPC is a RISC instruction set architecture created by the 1991 Apple Inc.?IBM?Motorola alliance, known as AIM alliance. Originally intended for personal computers, PowerPC CPUs have since become popular embedded system and high-performance processors.... . There are, however, unofficial ports to other UNIX-like platforms (like FreeBSD
FreeBSD
FreeBSD is a Unix-like free software operating system descended from AT&T Unix via the Berkeley Software Distribution branch through the 386BSD and Berkeley Software Distribution#4.4BSD and descendants operating systems.... , NetBSD
NetBSD
NetBSD is a freely redistributable, open source version of the Unix-derivative Berkeley Software Distribution computer operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed.... , and Mac OS X
Mac OS X
Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems.... ). There is no port for Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces .... at the moment (nor are there any official short-term plans for one), but there is an experimental version capable of interfacing with Wine
Wine (software)
Wine is a free software software application that aims to allow Unix-like computer operating systems on the x86 architecture or x86-64 architecture to execute programs written for Microsoft Windows.... for debugging Windows software running on Linux. Increasing platform support is a long-term goal, but requires much work due to the nature of the project.
Limitations
In addition to the performance penalty an important limitation of Valgrind is its inability to detect bounds errors in the use of static or stack allocated data. The following code will pass the Memcheck tool in Valgrind without incident, despite the indicated errors:
In computer security and computer programming, a buffer overflow, or buffer overrun, is an Anomaly in software condition where a process attempts to store data beyond the boundaries of a fixed-length buffer .... make software
vulnerable
Vulnerability (computing)
In computer security, the term vulnerability is applied to a weakness in a system which allows an attacker to violate the integrity of that system.... to the classic
stack smashing exploit.