Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full call stack from Valgrind?

Tags:

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?

like image 824
Michael Lukin Avatar asked Jun 28 '12 10:06

Michael Lukin


People also ask

What does valgrind return?

By default Valgrind's malloc, realloc, etc, return a block whose starting address is 8-byte aligned or 16-byte aligned (the value depends on the platform and matches the platform default).

How do you show lines in valgrind?

Look for function names and line numbersIf you compile your program with the -g flag, Valgrind will show you the function names and line numbers where errors occur.

How do I call valgrind?

Valgrind is installed on the department machines. To invoke it on an executable called a. out, you simply run the command valgrind ./a.

Is valgrind a dynamic library?

Valgrind uses dynamic binary instrumentation, so you don't need to modify, recompile or relink your applications. Just prefix your command line with valgrind and everything works.


1 Answers

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 valgrind 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, valgrind is very good at what it does, but there is a reason places like IBM can sell memory profiles for big money.

like image 198
roelofs Avatar answered Oct 22 '22 06:10

roelofs