简体   繁体   English

valgrind / callgrind可以在发布的可执行C ++程序上工作吗?

[英]Can valgrind/callgrind work on a release executable C++ program?

I understand that valgrind can call memcheck to perform memory leak check, and in this case the compiled C++ executable program must contain debug information. 我知道valgrind可以调用memcheck来执行内存泄漏检查,在这种情况下,已编译的C ++可执行程序必须包含调试信息。 Then, if I want to use valgrind/callgrind to perform profiling, must the executable contain debug information? 然后,如果我想使用valgrind / callgrind进行性能分析,该可执行文件是否必须包含调试信息? I have run a small test, and it seems that valgrind/callgrind can work on release executable programs without debug information. 我进行了一个小测试,看来valgrind / callgrind可以在没有调试信息的情况下运行发布的可执行程序。 Can anyone confirm it? 有人可以确认吗?

From Official Valgrind documentation link, following information can be found: 在官方Valgrind文档链接中,可以找到以下信息:

2.2. 2.2。 Getting started 入门

First off, consider whether it might be beneficial to recompile your application and supporting libraries with debugging info enabled (the -g option) . 首先,考虑启用调试信息(-g选项)重新编译应用程序和支持库是否有益

Without debugging info , the best Valgrind tools will be able to do is guess which function a particular piece of code belongs to, which makes both error messages and profiling output nearly useless . 没有调试信息 ,最好的Valgrind工具将能够做的就是猜测特定代码段属于哪个功能, 这将使错误消息和性能分析输出几乎无用 With -g, you'll get messages which point directly to the relevant source code lines. 使用-g,您将获得直接指向相关源代码行的消息。

Another option you might like to consider, if you are working with C++, is -fno-inline. 如果使用的是C ++,则可能要考虑的另一个选项是-fno-inline。 That makes it easier to see the function-call chain, which can help reduce confusion when navigating around large C++ apps. 这样可以更轻松地查看函数调用链,这有助于减少在大型C ++应用程序中导航时的困惑。 For example, debugging OpenOffice.org with Memcheck is a bit easier when using this option. 例如,使用此选项时,使用Memcheck调试OpenOffice.org会容易一些。 You don't have to do this, but doing so helps Valgrind produce more accurate and less confusing error reports. 您不必执行此操作,但是这样做可以帮助Valgrind生成更准确,更不易混淆的错误报告。 Chances are you're set up like this already, if you intended to debug your program with GNU GDB, or some other debug. 如果您打算使用GNU GDB调试程序或进行其他调试,则很有可能已经这样设置。

Hence the recommended step is to recompile your program with -g option to get maximum information from the Valgrind. 因此,建议的步骤是使用-g选项重新编译程序,以从Valgrind获得最大信息。

According to the valgrind manual: 根据valgrind手册:

http://valgrind.org/docs/manual/manual-core.html http://valgrind.org/docs/manual/manual-core.html

If you are planning to use Memcheck: On rare occasions, compiler optimisations (at -O2 and above, and sometimes -O1) have been observed to generate code which fools Memcheck into wrongly reporting uninitialised value errors, or missing uninitialised value errors. 如果您打算使用Memcheck:在极少数情况下,观察到编译器优化(在-O2及以上,有时是-O1)会生成代码,这些代码会使Memcheck误报未初始化的值错误,或者丢失了未初始化的值错误。 We have looked in detail into fixing this, and unfortunately the result is that doing so would give a further significant slowdown in what is already a slow tool. 我们已经详细研究了解决此问题的方法,不幸的是,这样做的结果是,原本已经很慢的工具将大大降低速度。 So the best solution is to turn off optimisation altogether. 因此,最好的解决方案是完全关闭优化。 Since this often makes things unmanageably slow, a reasonable compromise is to use -O. 由于这通常会使事情变得难以控制,因此使用-O是一个合理的折衷方案。 This gets you the majority of the benefits of higher optimisation levels whilst keeping relatively small the chances of false positives or false negatives from Memcheck. 这为您带来了较高优化级别的大部分好处,同时使Memcheck产生误报或误报的机会相对较小。 Also, you should compile your code with -Wall because it can identify some or all of the problems that Valgrind can miss at the higher optimisation levels. 另外,您应该使用-Wall编译代码,因为它可以识别Valgrind在较高的优化级别上可能会遗漏的部分或全部问题。 (Using -Wall is also a good idea in general.) All other tools (as far as we know) are unaffected by optimisation level, and for profiling tools like Cachegrind it is better to compile your program at its normal optimisation level. (通常,使用-Wall也是一个好主意。)所有其他工具(据我们所知)不受优化级别的影响,对于Cachegrind之类的性能分析工具,最好以其常规优化级别编译程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM