https://elinux.org/api.php?action=feedcontributions&user=Erh&feedformat=atomeLinux.org - User contributions [en]2024-03-28T13:14:37ZUser contributionsMediaWiki 1.31.0https://elinux.org/index.php?title=Memory_Debuggers&diff=62473Memory Debuggers2011-08-10T20:38:15Z<p>Erh: valgrind doesn't use source code</p>
<hr />
<div>Several tools exist for finding memory leaks or for reporting individual memory allocations<br />
of a program. These tools help analyze memory usage patterns, detect unbalanced allocations and frees, report buffer over- and under-runs, etc.<br />
<br />
=== mtrace ===<br />
mtrace is a builtin part of glibc which allows detection of memory leaks caused by unbalanced malloc/free calls. To use it, the program is modified to call mtrace() and muntrace() to start and stop tracing of allocations. A log file is created, which can then be scanned by the 'mtrace' Perl script. The 'mtrace' program lists only unbalanced allocations. If source is available it can<br />
show the source line where the problem occurred. mtrace can be used on both C and C++ programs.<br />
<br />
See the [http://wikipedia.org/wiki/Mtrace mtrace wikipedia article] for more information.<br />
<br />
=== memwatch ===<br />
memwatch is a program that not only detects malloc and free errors but also reads and writes beyond the allocated space (buffer over and under-runs). To use it, you modify the source to include<br />
the memwatch code, which provides replacements for malloc and free.<br />
<br />
Some things that memwatch does not catch are writing to an address that has been freed and reading data from outside the allocated memory.<br />
<br />
=== mpatrol ===<br />
mpatrol appears to be like memwatch.<br />
<br />
See http://mpatrol.sourceforge.net/<br />
<br />
=== dmalloc ===<br />
"The debug memory allocation or dmalloc library has been designed as a drop in replacement for the system's malloc, realloc, calloc, free and other memory management routines while providing powerful debugging facilities configurable at runtime. These facilities include such things as memory-leak tracking, fence-post write detection, file/line number reporting, and general logging of statistics."<br />
<br />
This library can be used without modifying the existing program, and uses environment variables<br />
to control it's operation and set of issues to log.<br />
<br />
It's home page is at: http://dmalloc.com/<br />
<br />
See Cal Erickson's article (link below, page 2) for information about using this system.<br />
<br />
=== dbgmem ===<br />
dbgmem looks like another dynamic library replacement tool, similar to dmalloc (but possibly having less features)<br />
<br />
See http://dbgmem.sourceforge.net/<br />
<br />
=== valgrind ===<br />
valgrind does dynamic binary instrumentation to analyze the program, and provides a number<br />
of memory problem detection tools and profiling tools. Unfortunately, as of July 2010 it is<br />
only available for x86 and ppc64 architecture platforms.<br />
<br />
See [[Valgrind]]<br />
<br />
=== Electric Fence ===<br />
See [[Electric Fence]]<br />
<br />
== Tutorials or Overviews ==<br />
* [http://www.linuxjournal.com/article/6059 Memory Leak Detection in Embedded Systems] by Cal Erickson, Linux Journal, September 2002<br />
** This article mentions mtrace, memwatch and dmalloc<br />
<br />
[[Category:Development Tools]]</div>Erh