你如何让 Valgrind 显示行错误? [英] How do you get Valgrind to show line errors?

查看:32
本文介绍了你如何让 Valgrind 显示行错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何让 Valgrind 准确显示发生错误的位置?我编译了我的程序(在 Windows 机器上通过 PuTTy 通过 Linux 终端)添加了 -g 调试选项.

How do you get Valgrind to show exactly where an error occured? I compiled my program (on a Windows machine over a Linux terminal via PuTTy) adding the -g debug option.

当我运行 Valgrind 时,我得到了 Leak 和 Heap 摘要,而且我确实丢失了内存,但是我从来没有得到关于它发生在哪里的信息(文件名、行).分配内存后,Valgrind 不应该告诉我在哪一行,它稍后无法释放吗?

When I run Valgrind, I get the Leak and Heap summary, and I definitely have lost memory, but I never get information about where it happens (file name, line). Shouldn't Valgrind be telling me on what line after I allocate memory, it fails to deallocate later?

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

推荐答案

Try valgrind --leak-check=full

这通常会打印更多有用的信息.还要在编译时添加 -O0 标志,这样您的代码就不会得到优化.

This normally prints more useful information. Also add the -O0 flag when compiling so your code doesn't get optimized.

这篇关于你如何让 Valgrind 显示行错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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