valgrind 可以输出部分报告而不必退出分析的应用程序吗? [英] Can valgrind output partial reports without having to quit the profiled application?

查看:25
本文介绍了valgrind 可以输出部分报告而不必退出分析的应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 valgrind 检查一个长时间运行的进程是否存在内存泄漏.我怀疑我所追求的内存泄漏可能只有在执行几个小时后才会发生.我可以在 valgrind 下运行应用程序并获取 valgrind 日志,但这样做意味着我必须退出应用程序并重新启动它以进行新的 valgrind 会话,但我仍然需要等待几个小时.是否有可能保持 valgrind 和应用程序运行并在执行过程中的任何时候仍然获取 valgrind 的(部分)数据?

I want to check a long running process for memory leaks with valgrind. I suspect the memory leak I'm after might happen only after several hours of execution. I can run the app under valgrind and get the valgrind log just fine, but doing so means I have to quit the application and start it again anew for a new valgrind session for which I would still have to wait several hours. Is it possible to keep valgrind and the app running and still get valgrind's (partial) data at any point during execution?

推荐答案

您可以使用 Valgrind gdbserver 和 GDB.

简而言之,您像往常一样使用 valgrind 启动程序,但使用 --vgdb=yes 开关:

In short, you start your program with valgrind as usual, but with the --vgdb=yes switch:

$ valgrind --tool=memcheck --vgdb=yes ./a.out 

在另一个会话中,您在同一个可执行文件上启动 gdb,并连接到 valgrind.然后您可以发出 valgrind 命令:

In another session, you start gdb on the same executable, and connect to valgrind. You can then issue valgrind commands:

$ gdb ./a.out
...
(gdb) target remote | vgdb
....
(gdb) monitor leak_check full reachable any
==8677== 32 bytes in 1 blocks are definitely lost in loss record 1 of 2
==8677==    at 0x4C28E3D: malloc (vg_replace_malloc.c:263)
==8677==    by 0x400591: foo (in /home/me/tmp/a.out)
==8677==    by 0x4005A7: main (in /home/me/tmp/a.out)
==8677== 
==8677== 32 bytes in 1 blocks are definitely lost in loss record 2 of 2
==8677==    at 0x4C28E3D: malloc (vg_replace_malloc.c:263)
==8677==    by 0x400591: foo (in /home/me/tmp/a.out)
==8677==    by 0x4005AC: main (in /home/me/tmp/a.out)
==8677== 
==8677== LEAK SUMMARY:
==8677==    definitely lost: 64 bytes in 2 blocks
==8677==    indirectly lost: 0 bytes in 0 blocks
==8677==      possibly lost: 0 bytes in 0 blocks
==8677==    still reachable: 0 bytes in 0 blocks
==8677==         suppressed: 0 bytes in 0 blocks
==8677== 
(gdb) 

查看命令列表的手册,这里 用于内存检查.

See the manual for a list of commands, here for memcheck.

这篇关于valgrind 可以输出部分报告而不必退出分析的应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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