你如何让Valgrind准确显示错误发生的位置?我编译了我的程序(通过PuTTy在Linux终端上的Windows机器上)添加-g调试选项.
当我运行Valgrind时,我得到了Leak和Heap摘要,我肯定已经丢失了内存,但我从未获得有关它发生的位置的信息(文件名,行).在我分配内存之后,Valgrind不应该在告诉我什么线路,它以后无法解除分配?
==15746==
==15746== HEAP SUMMARY:
==15746== in use at exit: 54 bytes in 6 blocks
==15746== total heap usage: 295 allocs, 289 frees, 11,029 bytes allocated
==15746==
==15746== LEAK SUMMARY:
==15746== definitely lost: 12 bytes in 3 blocks
==15746== indirectly lost: 42 bytes in 3 blocks
==15746== possibly lost: 0 bytes in 0 blocks
==15746== still reachable: 0 bytes in 0 blocks
==15746== suppressed: 0 bytes in 0 blocks
==15746== Rerun with --leak-check=full to see details of leaked memory
==15746==
==15746== For counts of detected and suppressed errors, rerun with: -v
==15746== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 8)
Run Code Online (Sandbox Code Playgroud)
Dan*_*ano 10
我一再得到这个,并且无法弄清楚为什么'--leak-check = full'对我不起作用,所以我想我会提高tune2fs评论.
最可能的问题是你(不是ShrimpCrackers,但是现在正在阅读这篇文章的人)在命令行的末尾放置了--leak-check = full.Valgrind希望您在输入实际命令行之前发布标志以运行程序.
即:
valgrind --leak-check=full ./myprogram
Run Code Online (Sandbox Code Playgroud)
不:
valgrind ./myprogram --leak-check=full
Run Code Online (Sandbox Code Playgroud)
ale*_*avi 10
这不是与 valgrind 相关的选项。相反,必须使用-g选项编译代码,以保留调试符号。
cc -g main.c
valgrind --trace-children=yes --track-fds=yes --track-origins=yes --leak-check=full --show-leak-kinds=all ./a.out
Run Code Online (Sandbox Code Playgroud)
尝试 valgrind --leak-check=full
这通常会打印更多有用的信息。还要-O0在编译时添加标志,这样您的代码就不会得到优化。
小智 6
让我对其他读者更具体一些(我遇到了同样的问题,但我的论点顺序正确):我发现 valgrind 需要可执行文件的路径,如果你不提供这个路径,那么它将运行但不会运行给你行号。就我而言,可执行文件位于不同的目录中,该目录位于我的 PATH 中,但要获取行信息,您必须运行
valgrind --leak-check=full path_to_myprogram/myprogram
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21616 次 |
| 最近记录: |