gpt4 book ai didi

linux - 程序是否需要退出才能让 Valgrind 工作?

转载 作者:太空宇宙 更新时间:2023-11-04 13:01:17 27 4
gpt4 key购买 nike

注意:
1. 我尝试传递标志 --vgdb=yes,但在这种情况下,进程根本没有运行。
2. 我不赞成检测我的代码。

问题:
我正在尝试在永远运行的自定义操作系统(基于 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 上使用相同的参数运行 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
. . .

如何为我的程序获取类似的统计信息?我的进程永远不会退出。

最佳答案

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

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

另一方面,给出 --vgdb-error=0 意味着您的程序将等待来自 gdb/vgdb 的连接以继续。

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

vgdb leak_search full

关于linux - 程序是否需要退出才能让 Valgrind 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33835638/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com