LMDBG is an application that allows detecting memory leaksand double frees. However, unlike others, LMDBG generates *FULL* stacktracesand separates logging from analysis thusallowing to analyse an application on per-module basis.
- lmdbg-run is a main lmdbg utility. It runs an application and creates a log file (or fifo) where all called malloc/calloc/realloc/free/memalign/posix_memalign invocations are registered with their input (bytes count, pointer), output (pointer) and (!!!uniques feature!!!) FULL STACKTRACE (pointers).
Example:
$ cat tests/test2.c
#include
int main ()
{
void *p1 = NULL;
void *p2 = NULL;
p1 = malloc (555);
p2 = realloc (p2, 666);
p2 = realloc (p2, 777);
p2 = realloc (p2, 888);
return 0;
}
$ gcc -O0 -g -o _test2 tests/test2.c
$ lmdbg-run -o _log ./_test2
$ cat _log
malloc ( 555 ) --> 0xbb901400
0xbbbe58e8
0xbbbe5b03
0x8048738
0x8048584
0x80484e7
realloc ( NULL , 666 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804874e
0x8048584
0x80484e7
realloc ( 0xbb901800 , 777 ) --> 0xbb901c00
0xbbbe58e8
0xbbbe5a37
0x8048764
0x8048584
0x80484e7
realloc ( 0xbb901c00 , 888 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804877a
0x8048584
0x80484e7
$
NOTE: Full stacktrace allows you to analyse your application, i.e. you can detect what blocks/components require more memory than others and why. lmdbg-sym is a very important tool for this, see below.
- lmdbg-leaks analyses a log file generated by lmdbg-run and output all found memory leaks
Example:
$ lmdbg-leaks _log
realloc ( 0xbb901c00 , 888 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804877a
0x8048584
0x80484e7
malloc ( 555 ) --> 0xbb901400
0xbbbe58e8
0xbbbe5b03
0x8048738
0x8048584
0x80484e7
$
- lmdbg-sym converts addresses to source.c:999 if it is possible
Example (gdb(1) is in action):
$ lmdbg-sym ./_test2 _log
malloc ( 555 ) --> 0xbb901400
0xbbbe58e8
0xbbbe5b03
0x8048738 tests/test2.c:8 main
0x8048584
0x80484e7
realloc ( NULL , 666 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804874e tests/test2.c:9 main
0x8048584
0x80484e7
realloc ( 0xbb901800 , 777 ) --> 0xbb901c00
0xbbbe58e8
0xbbbe5a37
0x8048764 tests/test2.c:10 main
0x8048584
0x80484e7
realloc ( 0xbb901c00 , 888 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804877a tests/test2.c:11 main
0x8048584
0x80484e7
$
Example (addr2line(1) works here):
$ lmdbg-sym -a ./_test2 _log
malloc ( 555 ) --> 0xbb901400
0xbbbe58e8
0xbbbe5b03
0x8048738 tests/test2.c:8
0x8048584
0x80484e7
realloc ( NULL , 666 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804874e tests/test2.c:9
0x8048584
0x80484e7
realloc ( 0xbb901800 , 777 ) --> 0xbb901c00
0xbbbe58e8
0xbbbe5a37
0x8048764 tests/test2.c:10
0x8048584
0x80484e7
realloc ( 0xbb901c00 , 888 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804877a tests/test2.c:11
0x8048584
0x80484e7
$
- lmdbg-sysleaks - greps or skips system memory leaks found in libc, libdl, C++ stl etc. See tests/lmdbg*.conf files. The default config files are: ~/.lmdbg.conf and /etc/lmdbg.conf
- lmdbg = lmdbg-run + lmdbg-leaks + lmdbg-sym + lmdbg-sysleaks
That is lmdbg is all-in-one higher level tool.
Example:
$ lmdbg -v -o _log ./_test2
Memory leaks were detected and saved to file '_log'
$ cat _log
realloc ( 0xbb901c00 , 888 ) --> 0xbb901800
0xbbbe58e8
0xbbbe5a37
0x804877a tests/test2.c:11 main
0x8048584
0x80484e7
malloc ( 555 ) --> 0xbb901400
0xbbbe58e8
0xbbbe5b03
0x8048738 tests/test2.c:8 main
0x8048584
0x80484e7
$
What's New in This Release: [ read full changelog ]
· This version adds a lot of improvements and fixes in manual pages, new capabilities in lmdbg, lmdbg-run, and lmdbg-sym, and minor fixes to lmdbg-stat.
· lmdbg is now a meta tool which is able to do many more things, not just find memory leaks.