Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Valgrind
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Programming tool for profiling, memory debugging and memory leak detection}} {{about|software|the mythical gate|Valhalla}} {{Infobox software | logo = Valgrind logo.png | logo caption = Valgrind logo | logo_size = 200px | logo_alt = | screenshot = <!-- Image name is enough --> | caption = | screenshot_size = | screenshot_alt = | collapsible = | author = [[Julian Seward]], Nicholas Nethercote<ref>{{Cite web |title=AUTHORS |url=https://valgrind.org/docs/manual/dist.authors.html |access-date=2022-09-19 |website=valgrind.org}}</ref> | developer = Valgrind Development Team<ref>{{Cite web|url=https://valgrind.org/info/developers.html|title = Valgrind: The Developers}}</ref> | released = Jul 27, 2002<ref>{{Cite web |title=Twenty years of Valgrind |date=27 July 2022 |url=https://nnethercote.github.io/2022/07/27/twenty-years-of-valgrind.html |access-date=2023-08-04 }}</ref> | discontinued = | latest release version = | latest release date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | latest preview version = | latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | status = | programming language = [[C (programming language)|C]] | operating_system = [[Linux]]<br/>{{nowrap|[[FreeBSD]]}}<br/>{{nowrap|[[Solaris (operating system)|Solaris]]}}<br/>[[Android (operating system)|Android]]<ref name="relnotes">[https://valgrind.org/docs/manual/dist.news.html Valgrind release notes]</ref> | platform = | size = | genre = [[Profiler (computer science)|Profiler]], [[Memory debugger]] | license = [[GNU General Public License]] | website = {{URL|https://www.valgrind.org/}} }} '''Valgrind''' ({{IPAc-en|ˈ|v|æ|l|ɡ|r|ɪ|n|d}})<ref>{{Cite web |title=Valgrind |url=https://valgrind.org/docs/manual/faq.html#faq.pronounce |access-date=2023-05-04 |website=valgrind.org}}</ref> is a [[programming tool]] for [[memory debugger|memory debugging]], [[memory leak]] detection, and [[profiling (computer programming)|profiling]]. Valgrind was originally designed to be a [[Free software|freely licensed]] memory debugging tool for [[Linux]] on [[x86]], but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers. ==Overview== Valgrind is in essence a [[virtual machine]] using [[just-in-time compilation]] techniques, including [[dynamic recompilation]]. Nothing from the original program ever gets run directly on the host [[Central processing unit|processor]]. Instead, Valgrind first translates the program into a temporary, simpler form called [[intermediate representation]] (IR), which is a processor-neutral, [[static single assignment form]]-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. Valgrind recompiles [[binary code]] to run on host and target (or simulated) CPUs of the same architecture. It also includes a [[GDB]] stub to allow debugging of the target program as it runs in Valgrind, with "monitor commands" that allow querying the Valgrind tool for various information. 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 at 20% to 25% of the speed of the normal program.<ref>[https://valgrind.org/info/about.html Valgrind homepage]</ref><ref>[https://valgrind.org/docs/manual/valgrind_manual.pdf Valgrind Manual]</ref> ==Tools== {{See also|Memory debugger|Profiling (computer programming)}} ===Memcheck=== There are multiple tools included with Valgrind (and several external ones). The default (and most used) tool is ''Memcheck''. Memcheck inserts extra [[instrumentation (computer programming)|instrumentation]] 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 [https://en.cppreference.com/w/cpp/memory/new/operator_new C++ allocators] and [[C dynamic memory allocation|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]]s where a program reads or writes outside an allocated block by a small amount. The problems Memcheck can detect and warn about include the following: * Reading uninitialized memory * Reading/writing invalid memory which may be ** memory that has been <code>free</code>'d ** memory outside of <code>malloc</code>'d blocks ** memory below the stack pointer * Use of incorrect parameters for system calls * Unsafe overlapping memory copies with <code>mem*</code> and <code>str*</code> functions * [[Memory leak]]s * Mismatched allocations and deallocations which may be ** mixing C and C++ e.g., <code>malloc</code> and <code>delete</code> ** mixing scalar and array e.g., <code>new</code> and <code>delete[]</code> ** sized deallocation not the same size as allocation ** aligned deallocation not the same alignment as allocation * Use of incorrect alignment * Use of <code>realloc</code> with a size of zero The price of this is lost performance. Programs running under Memcheck usually run 20–30 times slower<ref>{{Cite web|url=https://valgrind.org/docs/manual/quick-start.html#quick-start.mcrun|title = Valgrind}}</ref> than running outside Valgrind and use more memory (there is a memory penalty per allocation). Thus, few developers run their code under Memcheck (or any other Valgrind tool) all the time. They most commonly use such tools either to trace down some specific bug, or to verify that there are no latent bugs (of the kind Memcheck can detect) in the code. ===Other tools=== In addition to Memcheck, Valgrind has several other tools:<ref>[https://valgrind.org/info/tools.html Valgrind main tool list]</ref> *''None'', runs the code in the virtual machine without performing any analysis and thus has the smallest possible CPU and memory overhead of all tools. Since Valgrind itself provides a trace back from a [[segmentation fault]], the ''none'' tool provides this traceback at minimal overhead. *''Addrcheck'', similar to Memcheck but with much smaller CPU and memory overhead, thus catching fewer types of bugs. Addrcheck has been removed as of version 3.2.0.<ref>{{Cite web|url=https://valgrind.org/docs/manual/dist.news.old.html|title = Valgrind}}</ref> *''Massif'', a [[Dynamic memory allocation|heap]] [[profiling (computer programming)|profiler]]. The separate [[Graphical user interface|GUI]] massif-visualizer visualizes output from Massif. *''Helgrind'' and ''DRD'', detect [[race condition]]s in [[thread (computing)|multithreaded code]] *''Cachegrind'', a [[CPU cache|cache]] profiler. The separate GUI KCacheGrind visualizes output from Cachegrind. *''Callgrind'', a [[call graph]] analyzer created by Josef Weidendorfer, added to Valgrind as of version 3.2.0. KCacheGrind can visualize output from Callgrind. *''DHAT'', dynamic heap analysis tool which analyzes how much memory is allocated and for how long, as well as patterns of memory usage. *''exp-bbv'', a performance simulator that extrapolates performance from a small sample set. ''exp-sgcheck'' (named ''exp-ptrcheck'' prior to version 3.7), was removed in version 3.16.0. It was an experimental tool to find stack and global array overrun errors, which Memcheck cannot find. There are also several externally developed tools available. One such tool is ThreadSanitizer, another detector of [[race condition]]s.<ref>{{Cite web|url=https://valgrind.org/downloads/variants.html|title = Valgrind: Variants / Patches}}</ref><ref>K Serebryany, T Iskhodzhanov, ''[http://data-race-test.googlecode.com/files/ThreadSanitizer.pdf ThreadSanitizer–data race detection in practice]'', Proceedings of the Workshop on Binary Instrumentation and Applications WBIA'09</ref> ==Platforms supported== As of version 3.4.0, Valgrind supports [[Linux]] on [[x86]], [[x86-64]] and [[PowerPC]]. Support for Linux on [[ARM architecture family|ARMv7]] (used for example in certain [[smartphone]]s) was added in version 3.6.0.<ref>[http://talk.maemo.org/showthread.php?t=65335 ARM/Linux port]</ref> Support for [[Solaris (operating system)|Solaris]] was added in version 3.11.0.<ref name="relnotes" /> Support for {{nowrap|[[macOS|OS X]]}} was added in version 3.5.0.<ref>[http://blog.mozilla.com/nnethercote/2009/05/28/mac-os-x-now-supported-on-the-valgrind-trunk/ OS X port]</ref> Support for [[FreeBSD]] x86 and amd64 was added in version 3.18.0. Support for FreeBSD aarch64 was added in version 3.23.0. There are unofficial ports to other [[Unix-like]] platforms (like [[OpenBSD]],<ref>[http://ports.su/devel/valgrind Valgrind OpenBSD port]</ref> [[NetBSD]]<ref>{{Cite web |url=http://vg4nbsd.berlios.de/ |title=Valgrind NetBSD port |access-date=2006-01-28 |archive-url=https://web.archive.org/web/20060209063503/http://vg4nbsd.berlios.de/ |archive-date=2006-02-09 |url-status=dead }}</ref> and QNX<ref>{{Cite web |title=foundry27 : View Release |url=https://community.qnx.com/sf/frs/do/viewRelease/projects.valgrind/frs.valgrind.valgrind_3_10;jsessionid=OEBZSSQUfLf5gV+W-ht7wdVW.tf |access-date=2024-05-24 |website=community.qnx.com}}</ref>). From version 3.7.0 the ARM/[[Android (operating system)|Android]] platform support was added.<ref name="relnotes" /> Since version 3.9.0 there is support for Linux on [[MIPS architecture#MIPS32/MIPS64|MIPS64]] little and big endian, for MIPS DSP ASE on [[MIPS32]], for [[s390x]] Decimal Floating Point instructions, for [[POWER8]] ([[Power ISA#Power ISA v.2.07|Power ISA 2.07]]) instructions, for Intel [[Advanced Vector Extensions|AVX2]] instructions, for Intel Transactional Synchronization Extensions, both RTM and HLE and initial support for Hardware Transactional Memory on POWER.<ref name="Valgrind News" /> == History and development == The name Valgrind refers to the main entrance to [[Valhalla]] in [[Norse mythology]].<ref>[http://www.valgrind.org/docs/manual/faq.html#faq.whence Valgrind FAQ]</ref><ref>{{cite web| url=https://www.voluspa.org/grimnismal21-25.htm| title=Grímnismál| website=Völuspá.org}}</ref> During development (before release) the project was named [[Heimdall]]; however, the name would have conflicted with a security package. The original author of Valgrind is [[Julian Seward]], who in 2006 won a [[Google-O'Reilly Open Source Award]] for his work on Valgrind.<ref>[https://valgrind.org/gallery/awards.html valgrind.org's list of awards]</ref><ref>[http://code.google.com/events/osa-hall-of-fame.html Google-O'Reilly Open Source Awards – Hall of Fame]</ref> Several others have also made significant contributions, including Nicholas Nethercote, Bart Van Assche, Florian Krohm, Tom Hughes, Philippe Waroquiers, Mark Wielaard, Paul Floyd, Petar Jovanovic, Carl Love, Cerion Armour-Brown and Ivo Raisr.<ref>[https://valgrind.org/info/developers.html The Valgrind Developers]</ref> It is used by a number of Linux-based projects.<ref>[https://valgrind.org/gallery/users.html valgrind.org's list of users]</ref> ==Limitations of Memcheck== In addition to the performance penalty, an important limitation of Memcheck is its inability to detect all cases of bounds errors in the use of static or stack-allocated data.<ref>[http://www.valgrind.org/docs/manual/faq.html#faq.overruns Valgrind FAQ]</ref> The following code will pass the ''Memcheck'' tool in Valgrind without incident, despite containing the errors described in the comments: <syntaxhighlight lang="c"> int Static[5]; int func(void) { int Stack[5]; Static[5] = 0; /* Error - Static[0] to Static[4] exist, Static[5] is out of bounds */ Stack [5] = 0; /* Error - Stack[0] to Stack[4] exist, Stack[5] is out of bounds */ return 0; } </syntaxhighlight> The inability to detect all errors involving the access of stack allocated data is especially noteworthy since [[Buffer overflow|certain types of stack errors]] make software [[Vulnerability (computing)|vulnerable]] to the classic [[Stack buffer overflow|stack smashing exploit]]. == See also == {{Portal|Free and open-source software}} * {{section link|Memory debugger|List_of_memory_debugging_tools}} * [[Dynamic program analysis]] * [[Pin (computer program)|Pin]] * [[DynamoRIO]] * [[VOGL]] * [[Libumem]] * [[AddressSanitizer]] ==Notes== {{Reflist|30em}} ==References== * {{cite journal | title = Valgrind: A framework for heavyweight dynamic binary instrumentation |first1=Nicholas|last1=Nethercote |first2=Julian|last2=Seward| journal = ACM SIGPLAN Notices |date=10 June 2007 |volume=42 |issue=6 |pages=89–100 | publisher = ACM |doi=10.1145/1273442.1250746 | url = http://portal.acm.org/citation.cfm?id=1250734.1250746&coll=GUIDE&dl=GUIDE&CFID=8869850&CFTOKEN=10168503 |url-access=subscription }} * {{cite journal | title = Using Valgrind to detect undefined value errors with bit-precision |first1=Julian|last1=Seward |first2=Nicholas|last2=Nethercote | journal = Proceedings of the USENIX Annual Technical Conference 2005 |date=10 April 2005|page=2| publisher = USENIX Association | url = http://portal.acm.org/citation.cfm?id=1247362&dl=GUIDE&coll=GUIDE&CFID=8869850&CFTOKEN=10168503 }} * {{cite book | first1 = J. | last1 = Seward | first2 = N. | last2 = Nethercote | first3 = J. | last3 = Weidendorfer | author4 = Valgrind Development Team | title = Valgrind 3.3 – Advanced Debugging and Profiling for GNU/Linux applications | publisher = Network Theory Ltd | date = March 2008 | pages = 164 pages | url = http://www.network-theory.co.uk/valgrind/manual/ | isbn = 978-0-9546120-5-4 }} ==External links== {{Wikibooks|Valgrind}} *{{official website|http://www.valgrind.org/}} {{Linux}} [[Category:Debuggers]] [[Category:Free memory debuggers]] [[Category:Free memory management software]] [[Category:Free software testing tools]] [[Category:Profilers]] [[Category:Software testing tools]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:About
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:IPAc-en
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Linux
(
edit
)
Template:Main other
(
edit
)
Template:Navbox
(
edit
)
Template:Nowrap
(
edit
)
Template:Official website
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:Section link
(
edit
)
Template:See also
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Wikibooks
(
edit
)