该程序是否需要退出以使Valgrind工作?

时间:2015-11-20 20:36:16

标签: linux memory-leaks valgrind

注意:
 1.我尝试传递旗帜--vgdb=yes,但在这种情况下,该过程根本不会运行。
 我并不赞成使用我的代码。

问题:
我试图在一个永远运行的自定义操作系统(基于Linux)的用户空间进程上运行valgrind。在这种情况下,如何获得内存泄漏的Valgrind统计数据,即该过程将永久运行。 在当前状态下,我使用Valgrind开始了这个过程并查看了这些日志:

==6561== Memcheck, a memory error detector                                                                                                                                                                         
==6561== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==6561== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==6561== Command: xyz_server
==6561== Parent PID: 3056
. . . . 
==6561== 
==6561== Thread 12: 
==6561== Syscall param timer_create(evp) points to uninitialised byte(s)
==6561==    at 0x84949BD: timer_create (in /lib64/librt-2.12.so)
==6561==    by 0x56D518E: api_1 (in . . .) // removed proprietary lib name
==6561==    by 0x74DDDD2: api_2 (in . . .) // removed proprietary lib name
==6561==    by 0x827A9BB: start_thread (pthread_create.c:301)
==6561==  Address 0x1fb37a50 is on thread 12's stack
==6561==   

这里没有统计数据。例如,如果我在ls上使用相同的args运行valgrind:

$ valgrind --leak-check=full ls -l
==12584== Memcheck, a memory error detector
==12584== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==12584== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==12584== Command: ls -l
==12584==
. . .
==12584== HEAP SUMMARY:
==12584==     in use at exit: 18,424 bytes in 10 blocks
==12584==   total heap usage: 71 allocs, 61 frees, 63,312 bytes allocated
. . .
==12584== LEAK SUMMARY:
==12584==    definitely lost: 0 bytes in 0 blocks
==12584==    indirectly lost: 0 bytes in 0 blocks
==12584==      possibly lost: 18,424 bytes in 10 blocks
==12584==    still reachable: 0 bytes in 0 blocks
==12584==         suppressed: 0 bytes in 0 blocks
==12584==
==12584== For counts of detected and suppressed errors, rerun with: -v
==12584== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 2 from 2
. . .

如何为我的计划获得类似的统计数据?我的过程永远不会退出。

1 个答案:

答案 0 :(得分:0)

您可以在程序运行时从shell或gdb触发泄漏搜索。

为此,valgrind gdbserver必须处于活动状态。默认情况下激活gdbserver(如果给出--vgdb = no,则禁用它)。没有理由给出--vgdb = yes会使你的程序无法运行。

另一方面,给出--vgdb-error = 0表示你的程序将等待gdb / vgdb的连接继续。

要从shell触发泄漏搜索,您可以使用:

PAGER=cat git diff ...