valgrind可以输出部分报告而无需退出配置文件应用程序吗?

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

你可以使用 Valgrind gdbserver and GDB来做到这一点.

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

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

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

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

有关命令列表,请参阅手册,有关memcheck的信息,请参见here.

你可能感兴趣的:(linux,debug调试)