如何从Valgrind获取完整的调用堆栈? [英] How to get the full call stack from Valgrind?

查看:481
本文介绍了如何从Valgrind获取完整的调用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下参数运行 Valgrind :

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

在内存泄漏日志中,我看到一些错误消息,这些错误消息具有完整的堆栈跟踪信息,可追溯到main,但是某些消息如下所示:

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?

推荐答案

获取完整的堆栈跟踪将需要调试所有可能与泄漏有关的库/可执行文件的调试符号(并在--num-callers设置的范围内)

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).

如果您要自己构建它们中的任何一个,则需要在gcc中指定-g标志(或在任何其他编译器中指定相关标志).

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).

请注意,并非万无一失,并且可能偶尔会漏掉泄漏或无法提供完整的堆栈跟踪信息(尤其是在使用线程或复杂的class实现的情况下).

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.

对于免费工具而言,非常虽然擅长于此,但是有一个理由可以使IBM之类的公司能够以大笔钱出售内存配置文件.

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.

这篇关于如何从Valgrind获取完整的调用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆