Can valgrind print partial reports without leaving a profiled application?

I want to check the long process of memory leak with valgrind. I suspect that the memory leak that I am after this can only happen after a few hours of execution. I can run the application under valgrind and get the valgrind log just fine, but that means I have to exit the application and restart it again for a new valgrind session, for which I still have to wait several hours. Is it possible to keep valgrind and the application running and still receive valgrind (partial) data at any time during runtime?

+5
source share
1 answer

You can do this using Valgrind gdbserver and GDB .

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

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

In another session, you run gdb in the same executable and connect to valgrind. Then you can 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.

+8
source

All Articles