memory-leaksvalgrindcallstack

How to get the full call stack from Valgrind?


I run Valgrind with the following parameters:

--leak-check=full --show-reachable=yes --leak-resolution=high --num-callers=100 --trace-children=yes

In memory leaks log, I see some error messages with full stack trace up to main, but some messages look like following:

==3956== 1,999,140 (68,796 direct, 1,930,344 indirect) bytes in 5,733 blocks are definitely lost in loss record 8,842 of 8,845
==3956==    at 0x4022AB8: malloc (vg_replace_malloc.c:207)
==3956== 

How can I get the full stack trace for these errors?


Solution

  • Getting the full stack trace will require debug symbols for all the libraries/executables that may be involved in a leak (and within the limits set by --num-callers).

    If you're building any of them yourself, you need to specify the -g flag in gcc (or the relevant flag in any other compiler).

    Note that is not foolproof, and may occasionally miss leaks or be unable to provide full stack traces (especially if you're using threads, or complicated class implementations).

    For libraries without debug information, the stack trace will stop at that library.

    For a free tool, is very good at what it does, but there is a reason places like IBM can sell memory profiles for big money.